Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Connecting to CayenneA Micropython class connecting to WiFi and subscribing to the myDevices MQTT broker | ||||||||
Changed: | ||||||||
< < | Since every sensor node needs to first connect to WiFi and later subscribe to the MQTT broker at mqtt.mydevices.com I wrote a small micro Python class accomplishing these tasks. You will have to modify the code inserting: | |||||||
> > | 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 ![]() | |||||||
| ||||||||
Changed: | ||||||||
< < | After that you import cayenne and create a Cayenne class. This will set up your Wifi connection. After that you call cayenne.myttConnect() to connect to the myDevices MQTT broker. Once the connection is established you can call cayenne.publish(channel,dataString) to send your measurement data. The source code for the Cayenne class and an example showing how this is used with a DS18B20 temperature sensor is attached to this page. | |||||||
> > | The CayenneMQTTClient class has a begin method taking Cayenne username, password and client id as parameters. The ssid and wifiPassword have default values but can be specified as well. The begin method will first connect to WiFi and then connect to the MQTT broker at mqtt.mydevices.com. It then subscribes to the command topic such that cmd messages from Cayenne can be passed on to a callback routine registered by the user of the CayenneMQTTClient class. In case of a cmd message the required response message is sent automatically.
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:
Parsing of command messages | |||||||
Changed: | ||||||||
< < | https://iotworkshop.africa/pub/AFNOG/Cayenne/cayennePublic.py.txt | |||||||
> > | 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 parameters. | |||||||
Changed: | ||||||||
< < | Please rename this file to cayenne.py after download | |||||||
> > | cayenneMsg.channel will then contain the channel number on which the command must be executed, cayenneMsg.value contains the value. | |||||||
Changed: | ||||||||
< < | https://iotworkshop.africa/pub/AFNOG/Cayenne/cayenneDS18B20.py.txt | |||||||
> > | You can also get hold of
| |||||||
Changed: | ||||||||
< < | Please rename this file to cayenneDS18B20.py after download | |||||||
> > | The code of the CayenneMQTTClient class can be found here: | |||||||
Changed: | ||||||||
< < | -- ![]() | |||||||
> > | https://github.com/uraich/MicropythonCayenneMQTTClient/tree/master/cayenne![]() | |||||||
Comments |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
Connecting to CayenneA Micropython class connecting to WiFi and subscribing to the myDevices MQTT brokerSince every sensor node needs to first connect to WiFi and later subscribe to the MQTT broker at mqtt.mydevices.com I wrote a small micro Python class accomplishing these tasks. You will have to modify the code inserting:
![]() Comments
|