Line: 1 to 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Slide 1: Setting up an IoTSession 3: MQTT and CayenneUli Raich
Slide 2: The Network LayersThe WeMos D1 mini has a built-in WiFi interfaceIn order to communicate with other IoT nodes we must therefore connect to the WiFi network first On top of WiFi we will run a TCP session On top of TCP we will run the MQTT protocol On top of MQTT we have dedicated topics and payloads imposed by Cayenne Slide 3: Accessing the WiFi networkSlide 4: Accessing the WiFi network from MicropythonSlide 5: MQTTMQTT (Message Queuing Telemetry Transport: a publish-subscribe basedmessage protocol running of top of TCP. A processor can subscribe to messages of a certain “topic” and/or it can push its results on a certain topic Slide 6: MQTT DemoSlide 7: The Micropython librarySlide 8: A MQTT example using umqtt.simpleSlide 9: Sending dummy temperature dataSlide 10: Receiving commandsReceiving commands is a bit more tricky! We must:
Slide 11: Subscribe a callbackSlide 12: Callback resultSlide 13: Controlling a LEDIn order to control a LED through MQTT we now simply interpret the payload:
Slide 14: Changed CallbackSlide 15: Missing functions in IoT
Slide 16: Cayenne functionality
Slide 17: Signing up for CayenneSign up athttps://mydevices.com/cayenne/signup Slide 18: Cayenne StartSlide 19: Cayenne DocYou find the documentation at https://mydevices.com/cayenne/docs/intro Contains short introductory video clips, information of Cayenne on Raspberry Pi and Arduino but also how to use Cayenne on any device. Pointers to the Cayenne MQTT Libraries and their APISlide 20: Installing Cayenne on the Raspberry PISlide 21: Installing Cayenne on the Raspberry Pi manuallySlide 22: Register your Controller Single Board ComputersSlide 23: Run Cayenne on the ArduinoSlide 24: Basic Arduino Sketch for the ArduinoSlide 25: Cayenne CredentialsSlide 26: Cayenne network layersThe Cayenne credentials are integrated into the MQTT topic stringValue and units are integrated into the payload string Slide 27: Cayenne and PythonThis falls under “bring your own thing” !Having a look at the Arduino sketch you can see that it uses the Arduino Cayenne C++ library. Cayenne MQTT libraries are available in
Slide 28: Cayenne and MicropythonThe Python Cayenne Client library depends on the Eclipse Paho MQTT libraryMicropython uses its own, stripped down “umqtt” (micro mqtt) library such that the standard Cayenne Client does not work on Micropython but … The Python Cayenne Client is Open Source and can be adapted to umqtt, which is what I did for you. The adapted Client library uses the same API as the original one, which means that the example programs work unchanged. Slide 29: The Cayenne ClientWhen creating a Cayenne Client Class it
Slide 30: The code to connect to CayenneSlide 31: Connecting to CayenneSlide 32: The empty Cayenne dashboard | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > | Send dummy measurementDummy temperature in CayenneDummy temperature parametersFix widget to dashboardDummy temperature historyCayenne keeps measurement values which can be plotted as a history plot or downloaded for further evaluationA custom widgetA gauge widgetDummy temperature gauge on the dashboardGauge value rangesIt's hot!Several dummy measurementsNow we want to send a dummy temperature and a dummy humidity value.How do we distinguish? They use different communication channels! Sending temperature and humidity: the codeDashboard with temperature and humidityOther measurementsWe have seen that we can send temperature with
Measurements implemented in the Cayenne ClientHow to control a device?Cayenne supplies only 2 control widgets:
Cayenne SliderWe can define the range for the slider in the above case: 0..255Slider on the dashboardA Cayenne ButtonDashboard with buttonHow to receive commandsWe must define a callback function, which is called whenever the user of the Cayenne dashboard changes a setting on the push button or sliderThe callback takes a message parameter which is a tuple of
Cayenne command messagePlease compare the command message with our credentials and try to find out to which channel this command has been addressed. Can you find the values as well? Remember: we defined the push button on channel 3 and the slider in channel 2!Exercises!More on how to interpret this message in the next session | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
%SLIDESHOWEND%
-- Uli Raich - 2019-05-14
Comments
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
|