Trying to make a simple MQTT broker connection (mqtt_as) #13232
Replies: 2 comments 11 replies
-
I usually connect to hivemq like in example below ("My example:") based on example/tutorial fromot-reading-sensor-data-raspberry-pi-pico and then run node-red to visualising data. also wy await in see some other example ( not asnychio) with mosquito as broker on local machine (your laptop) (it help (at least in my case) to faster design and test code and then easy way to switch to hivemq micropython-mqtt-esp32-esp8266 My example: def connectMQTT():
client = MQTTClient(
client_id=b"l<client_name>",
server=<server_adres> #b"da375fb.........92bf6d.eu.hivemq.cloud",
port=8883, # port No defined in hivemq.cloud (ussualu 8883)
user=<user name> , #
password=<password do server(cluster)>,
keepalive=120,
ssl=True,
ssl_params={'server_hostname':'da233fb2......2bf6c.s2.eu.hivemq.cloud'}
)
client.connect()
return client
client = connectMQTT()
async def publish(topic, value): # ensure than you have connection with client
while True:
print(topic)
print(value)
client.publish(topic, value)
print("publish Done")
await asyncio.sleep(1)
# do any async work in main app ...... |
Beta Was this translation helpful? Give feedback.
-
The code looks OK to me. When you say it doesn't work, what happens? Please provide the traceback. The advice from @2dof to test manually is good. I use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everybody.
I'm using the @peterhinch libraries and his example to make a simple connection with my "Hive MQ" broker cluster (adding Hive MQ particularities) and it doesn't work:
Somebody could help me?
Thanks. Merry christmas to everyone.
Beta Was this translation helpful? Give feedback.
All reactions