Since every sensor node needs to first connect to WiFi and later subscribe to the MQTT broker at mqtt.mydevices.com. Unfortunately the
Cayenne-MQTT-Python library depends on the Eclipse Paho MQTT Python client library, which is not available in Micropython.
I therefore ported the code to the umqtt.simple MQTT client available in Micropython. The API is the same as in the standard Cayenne MQTT client, which means that the example programs provided in this library will work without modification.
In order to connect to myDevices Cayenne you need:
If the OLED display is connected, the state of network connection will be shown.
The CayenneMQTTClient provides the following methods to publish measurement results:
For temperature:
The callback function gets a message, a tuple consisting of the topic and the payload, as parameter. This message must be parsed to extract the channel number and the value. The CayenneMessage class helps with this. Create a CayenneMessage object cayenneMsg with topic and payload (message[0] and message[1]) as corresponding parameters.
cayenneMsg.channel will then contain the channel number on which the command must be executed, cayenneMsg.value contains the value.
You can also get hold of
The code of the CayenneMQTTClient class can be found here:
https://github.com/uraich/MicropythonCayenneMQTTClient/tree/master/cayenne
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
![]() |
cayenneDS18B20.py.txt | r1 | manage | 1.0 K | 2019-03-28 - 12:42 | UliRaich | |
![]() |
cayennePublic.py.txt | r1 | manage | 2.7 K | 2019-03-28 - 12:42 | UliRaich |