Useful information, particularly about MQTT X. But every example I can find of Python MQTT code does either publish or subscribe but not both. In any practical code, you are likely to want to subscribe to some topics and publish to other topics in the same script. If you just scrunch the two examples together, it does not work because client.loop_forever() blocks everything except for responses to incoming MQTT messages. It would be much more helpful to show a single example which could be adapted to either role: comment out the subscribe call(s) and it just does publish, comment out the publish call(s) and it just does subscribe. This way we'd have a template which can be used for one, the other or both.
Many thanks Hans, I look forward to learning from you.
Great, thanks Hans
Great tutorial Hans. This is really helpful
Useful information, particularly about MQTT X. But every example I can find of Python MQTT code does either publish or subscribe but not both. In any practical code, you are likely to want to subscribe to some topics and publish to other topics in the same script. If you just scrunch the two examples together, it does not work because client.loop_forever() blocks everything except for responses to incoming MQTT messages. It would be much more helpful to show a single example which could be adapted to either role: comment out the subscribe call(s) and it just does publish, comment out the publish call(s) and it just does subscribe. This way we'd have a template which can be used for one, the other or both.
Can we publish a topic from a device and subscribe it from another device using python?