Connecting to Cayenne
A Micropython class connecting to WiFi and subscribing to the myDevices MQTT broker
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:
- your WiFi SSID
- your "WiFi password
- the Cayenne credentials:
- client name
- user name
- password
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.
https://afnog.iotworkshop.africa/pub/AFNOG/Cayenne/cayennePublic.py.txt
Please rename this file to
cayenne.py after download
https://afnog.iotworkshop.africa/pub/AFNOG/Cayenne/cayenneDS18B20.py.txt
Please rename this file to
cayenneDS18B20.py after download
--
Uli Raich - 2019-03-28
Comments