I am trying to subscribe to a mutt channel using Python Cayenne-mqtt library.
A Raspberry PI is publishing the data on channel 1 (i.e temp) and another Raspberry PI should receive the data by subscribing to it. The publishing part is working find, but I cannot find how to subscribe using the python cayenne library. Can you help me ?
I tried to used paho-mqtt library (client.subscribe) but connection to the device is stopped and restarted at every request… Strange !
I thought that this code works and send all messages, we don’t subscribe to a specific channel.
client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
logging.info('MQTT Message received ') logging.info(' Channel: %s', str(message.channel)) logging.info(' Value : %s', str(message.value)) logging.info(' Topic : %s', str(message.topic)) #logging.info(' Client : %s', str(message.client_id)) #logging.info(' Msg_ID : %s', str(message.msg_id))
Any idea how to do it ?
I also tried to run tinter graphical interface to show values. It required to start a myWindow.loop() which avoid running any other loop, like the mqtt client.loop() or loop_forever() in the same code.
What’s the best practices to run these two event code based ? Multi-Threading ?