Difference: MQTTAndCayenne (1 vs. 9)

Revision 92019-05-22 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up an IoT

Line: 202 to 202
  cayenneEmptyDashboard.png
Added:
>
>

Send dummy measurement

cayenneDummyTemp.png

Dummy temperature in Cayenne

dummyTemp.png

Dummy temperature parameters

dummyTempPars.png

Fix widget to dashboard

dummyTempFixed.png

Dummy temperature history

Cayenne keeps measurement values which can be plotted as a history plot

or downloaded for further evaluation

dummyTempHistory.png

A custom widget

cayenneCustonWidget.png

A gauge widget

cayenneTempGauge.png

Dummy temperature gauge on the dashboard

cayenneWarm.png

Gauge value ranges

cayenneGaugeRanges.png

It's hot!

cayenneHot.png

Several dummy measurements

Now 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 code

cayenneTempHum.png

Dashboard with temperature and humidity

cayenneDashboardTempHum.png

Other measurements

We have seen that we can send temperature with

  • client.celsiusWrite(channel,temp)
And relative humidity with

  • Client.humidityWrite(channel,hum)
Which other types of measurements can we send?

Measurements implemented in the Cayenne Client

cayenneMQTTCalls.png

How to control a device?

Cayenne supplies only 2 control widgets:

  • a push button
  • A slider

Cayenne Slider

cayenneDummySlider.png

We can define the range for the slider in the above case: 0..255

Slider on the dashboard

cayenneDashSlider.png

A Cayenne Button

cayenneDummyButtton.png

Dashboard with button

cayenneDashButton.png

How to receive commands

We must define a callback function, which is called

whenever the user of the Cayenne dashboard

changes a setting on the push button or slider

The callback takes a message parameter which is a tuple of

  • Cayenne topic
  • Cayenne payload

Cayenne command message

cayenneCmdMsg.png

Please 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

Line: 237 to 375
 
META FILEATTACHMENT attachment="cayenneConnectCode.png" attr="" comment="" date="1558543962" name="cayenneConnectCode.png" path="cayenneConnectCode.png" size="58160" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneConnect.png" attr="" comment="" date="1558543971" name="cayenneConnect.png" path="cayenneConnect.png" size="141182" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneEmptyDashboard.png" attr="" comment="" date="1558543976" name="cayenneEmptyDashboard.png" path="cayenneEmptyDashboard.png" size="153778" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="cayenneDummyTemp.png" attr="" comment="" date="1558549946" name="cayenneDummyTemp.png" path="cayenneDummyTemp.png" size="72819" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneHot.png" attr="" comment="" date="1558549948" name="cayenneHot.png" path="cayenneHot.png" size="150698" user="UliRaich" version="1"
META FILEATTACHMENT attachment="dummyTempFixed.png" attr="" comment="" date="1558549949" name="dummyTempFixed.png" path="dummyTempFixed.png" size="129302" user="UliRaich" version="1"
META FILEATTACHMENT attachment="dummyTempHistory.png" attr="" comment="" date="1558549949" name="dummyTempHistory.png" path="dummyTempHistory.png" size="30202" user="UliRaich" version="1"
META FILEATTACHMENT attachment="dummyTemp.png" attr="" comment="" date="1558549950" name="dummyTemp.png" path="dummyTemp.png" size="112872" user="UliRaich" version="1"
META FILEATTACHMENT attachment="dummyTempPars.png" attr="" comment="" date="1558550238" name="dummyTempPars.png" path="dummyTempPars.png" size="141124" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneTempGauge.png" attr="" comment="" date="1558550476" name="cayenneTempGauge.png" path="cayenneTempGauge.png" size="210070" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneWarm.png" attr="" comment="" date="1558550689" name="cayenneWarm.png" path="cayenneWarm.png" size="153237" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneGaugeRanges.png" attr="" comment="" date="1558550915" name="cayenneGaugeRanges.png" path="cayenneGaugeRanges.png" size="158951" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneTempHum.png" attr="" comment="" date="1558551138" name="cayenneTempHum.png" path="cayenneTempHum.png" size="84686" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneMQTTCalls.png" attr="" comment="" date="1558551398" name="cayenneMQTTCalls.png" path="cayenneMQTTCalls.png" size="68591" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneDashboardTempHum.png" attr="" comment="" date="1558551400" name="cayenneDashboardTempHum.png" path="cayenneDashboardTempHum.png" size="122373" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneDashButton.png" attr="" comment="" date="1558551804" name="cayenneDashButton.png" path="cayenneDashButton.png" size="160259" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneDashSlider.png" attr="" comment="" date="1558551805" name="cayenneDashSlider.png" path="cayenneDashSlider.png" size="142904" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneDummySlider.png" attr="" comment="" date="1558551855" name="cayenneDummySlider.png" path="cayenneDummySlider.png" size="182816" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneDummyButtton.png" attr="" comment="" date="1558551858" name="cayenneDummyButtton.png" path="cayenneDummyButtton.png" size="216089" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneCmdMsg2.png" attr="" comment="" date="1558552532" name="cayenneCmdMsg2.png" path="cayenneCmdMsg2.png" size="70285" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneCmdMsg.png" attr="" comment="" date="1558552534" name="cayenneCmdMsg.png" path="cayenneCmdMsg.png" size="194050" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ourCredentials.png" attr="" comment="" date="1558552534" name="ourCredentials.png" path="ourCredentials.png" size="18282" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneCustonWidget.png" attr="" comment="" date="1558553190" name="cayenneCustonWidget.png" path="cayenneCustonWidget.png" size="189279" user="UliRaich" version="1"

Revision 82019-05-22 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up an IoT

Line: 74 to 74
 
  • Message “LED on”
  • Message “LED off”
Added:
>
>

Changed Callback

changedCallback.png

Missing functions in IoT

  • MQTT broker should be globally reachable
  • GUI to easily visualize sensor measurements
  • GUI elements to easily control actuators
  • GUI should be accessible through a WEB interface
  • GUI should be accessible through smart phone app
This is what Cayenne supplies

Cayenne functionality

  • MQTT broker is accessible at mqtt.mydevices.com

  • Supplies GUI
cayenneFunctionality.png

Signing up for Cayenne

Sign up at
https://mydevices.com/cayenne/signup

cayenneSignup.png

Cayenne Start

cayenneStart.png

Cayenne Doc

You 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 API

cayenneDoc.png

Installing Cayenne on the Raspberry PI

cayenneRPI.png

Installing Cayenne on the Raspberry Pi manually

cayenne_RPI_ManualInstallation.png

Register your Controller Single Board Computers

cayenneRegisterRPI.png

Run Cayenne on the Arduino

cayenneArduinoInstall.png

Basic Arduino Sketch for the Arduino

cayenneArduinoSketch.png

Cayenne Credentials

cayenneCredentials.png

Cayenne network layers

cayenneNetLayers.png

The Cayenne credentials are integrated into the MQTT topic string

Value and units are integrated into the payload string

Cayenne and Python

This 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

  • C, C++
  • Python
  • Java
and probably a few other languages

Cayenne and Micropython

The Python Cayenne Client library depends on the Eclipse Paho MQTT library

Micropython 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.

The Cayenne Client

When creating a Cayenne Client Class it

  • Initializes its internal variables
  • Checks if the OLED display is connected and if yes, initializes it
  • The Cayenne Client has has a begin method which
  • Connects to WiFi
  • Connects to the Cayenne MQTT broker at mqtt.mydevices.com
  • Subscribes to commands send by Cayenne
  • Displays its internal state on the OLED display

The code to connect to Cayenne

cayenneConnectCode.png

Connecting to Cayenne

cayenneConnect.png

The empty Cayenne dashboard

cayenneEmptyDashboard.png

 %SLIDESHOWEND%

-- Uli Raich - 2019-05-14

Line: 94 to 222
 
META FILEATTACHMENT attachment="mqttDummySensorDemo.png" attr="" comment="" date="1558377647" name="mqttDummySensorDemo.png" path="mqttDummySensorDemo.png" size="76145" user="UliRaich" version="1"
META FILEATTACHMENT attachment="subscribeDemo.png" attr="" comment="" date="1558377918" name="subscribeDemo.png" path="subscribeDemo.png" size="80206" user="UliRaich" version="1"
META FILEATTACHMENT attachment="callbackResult.png" attr="" comment="" date="1558528264" name="callbackResult.png" path="callbackResult.png" size="146144" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="changedCallback.png" attr="" comment="" date="1558541165" name="changedCallback.png" path="changedCallback.png" size="15715" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneFunctionality.png" attr="" comment="" date="1558541341" name="cayenneFunctionality.png" path="cayenneFunctionality.png" size="138918" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneStart.png" attr="" comment="" date="1558541708" name="cayenneStart.png" path="cayenneStart.png" size="149818" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneSignup.png" attr="" comment="" date="1558541709" name="cayenneSignup.png" path="cayenneSignup.png" size="125087" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneDoc.png" attr="" comment="" date="1558542080" name="cayenneDoc.png" path="cayenneDoc.png" size="162100" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneRegisterRPI.png" attr="" comment="" date="1558542243" name="cayenneRegisterRPI.png" path="cayenneRegisterRPI.png" size="151833" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneRPI.png" attr="" comment="" date="1558542245" name="cayenneRPI.png" path="cayenneRPI.png" size="154438" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenne_RPI_ManualInstallation.png" attr="" comment="" date="1558542615" name="cayenne_RPI_ManualInstallation.png" path="cayenne_RPI_ManualInstallation.png" size="194412" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneArduinoInstall.png" attr="" comment="" date="1558542775" name="cayenneArduinoInstall.png" path="cayenneArduinoInstall.png" size="131451" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneCredentials.png" attr="" comment="" date="1558542983" name="cayenneCredentials.png" path="cayenneCredentials.png" size="112327" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneArduinoSketch.png" attr="" comment="" date="1558542958" name="cayenneArduinoSketch.png" path="cayenneArduinoSketch.png" size="195823" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneNetLayers.png" attr="" comment="" date="1558543535" name="cayenneNetLayers.png" path="cayenneNetLayers.png" size="35297" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneConnectCode.png" attr="" comment="" date="1558543962" name="cayenneConnectCode.png" path="cayenneConnectCode.png" size="58160" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneConnect.png" attr="" comment="" date="1558543971" name="cayenneConnect.png" path="cayenneConnect.png" size="141182" user="UliRaich" version="1"
META FILEATTACHMENT attachment="cayenneEmptyDashboard.png" attr="" comment="" date="1558543976" name="cayenneEmptyDashboard.png" path="cayenneEmptyDashboard.png" size="153778" user="UliRaich" version="1"

Revision 72019-05-22 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up an IoT

Line: 65 to 65
 

Callback result

Added:
>
>
callbackResult.png

Controlling a LED

In order to control a LED through MQTT we now simply interpret the payload:

  • Message “LED on”
  • Message “LED off”
 %SLIDESHOWEND%

-- Uli Raich - 2019-05-14

Line: 84 to 93
 
META FILEATTACHMENT attachment="afnog19-ws-session3.odp" attr="" comment="" date="1557947594" name="afnog19-ws-session3.odp" path="afnog19-ws-session3.odp" size="5370872" user="UliRaich" version="1"
META FILEATTACHMENT attachment="mqttDummySensorDemo.png" attr="" comment="" date="1558377647" name="mqttDummySensorDemo.png" path="mqttDummySensorDemo.png" size="76145" user="UliRaich" version="1"
META FILEATTACHMENT attachment="subscribeDemo.png" attr="" comment="" date="1558377918" name="subscribeDemo.png" path="subscribeDemo.png" size="80206" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="callbackResult.png" attr="" comment="" date="1558528264" name="callbackResult.png" path="callbackResult.png" size="146144" user="UliRaich" version="1"

Revision 62019-05-21 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up an IoT

Line: 62 to 62
  subscribeDemo.png
Added:
>
>

Callback result

 %SLIDESHOWEND%

-- Uli Raich - 2019-05-14

Revision 52019-05-20 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up an IoT

Line: 7 to 7
 

The Network Layers

Changed:
<
<
The WeMos D1 mini has a built-in WiFi interface

In 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
>
>
The WeMos D1 mini has a built-in WiFi interface

In 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

 

Accessing the WiFi network

Line: 41 to 43
 umqttDemo.png

Added:
>
>

Sending dummy temperature data

mqttDummySensorDemo.png

 

Added:
>
>

Receiving commands

Receiving commands is a bit more tricky! We must:

  • Write a callback function and register it with the MQTT client
  • This function takes 2 arguments:
  • The topic
  • The payload
  • Subscribe to the topic
  • Wait forever. The callback function will be executed when a message with the
    topic we subscribed to, will arrive

Subscribe a callback

subscribeDemo.png

  %SLIDESHOWEND%
Line: 61 to 79
 
META FILEATTACHMENT attachment="mqttExample.png" attr="" comment="" date="1557936755" name="mqttExample.png" path="mqttExample.png" size="74994" user="UliRaich" version="2"
META FILEATTACHMENT attachment="realData.png" attr="" comment="" date="1557940336" name="realData.png" path="realData.png" size="28318" user="UliRaich" version="1"
META FILEATTACHMENT attachment="afnog19-ws-session3.odp" attr="" comment="" date="1557947594" name="afnog19-ws-session3.odp" path="afnog19-ws-session3.odp" size="5370872" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="mqttDummySensorDemo.png" attr="" comment="" date="1558377647" name="mqttDummySensorDemo.png" path="mqttDummySensorDemo.png" size="76145" user="UliRaich" version="1"
META FILEATTACHMENT attachment="subscribeDemo.png" attr="" comment="" date="1558377918" name="subscribeDemo.png" path="subscribeDemo.png" size="80206" user="UliRaich" version="1"

Revision 42019-05-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up an IoT

Line: 60 to 60
 
META FILEATTACHMENT attachment="wifiDemoCode.png" attr="" comment="" date="1557936842" name="wifiDemoCode.png" path="wifiDemoCode.png" size="44819" user="UliRaich" version="1"
META FILEATTACHMENT attachment="mqttExample.png" attr="" comment="" date="1557936755" name="mqttExample.png" path="mqttExample.png" size="74994" user="UliRaich" version="2"
META FILEATTACHMENT attachment="realData.png" attr="" comment="" date="1557940336" name="realData.png" path="realData.png" size="28318" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="afnog19-ws-session3.odp" attr="" comment="" date="1557947594" name="afnog19-ws-session3.odp" path="afnog19-ws-session3.odp" size="5370872" user="UliRaich" version="1"

Revision 32019-05-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up an IoT

Line: 10 to 10
 The WeMos D1 mini has a built-in WiFi interface

In 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

Added:
>
>

Accessing the WiFi network

wifiDemoCode.png

 

Accessing the WiFi network from Micropython

wifiConnect.png

Line: 36 to 40
  umqttDemo.png
Added:
>
>

 

Line: 52 to 57
 
META FILEATTACHMENT attachment="mqttDemo.png" attr="" comment="" date="1557854608" name="mqttDemo.png" path="mqttDemo.png" size="195883" user="UliRaich" version="1"
META FILEATTACHMENT attachment="micropython-lib.png" attr="" comment="" date="1557855078" name="micropython-lib.png" path="micropython-lib.png" size="77052" user="UliRaich" version="1"
META FILEATTACHMENT attachment="umqttDemo.png" attr="" comment="" date="1557855530" name="umqttDemo.png" path="umqttDemo.png" size="73955" user="UliRaich" version="2"
Added:
>
>
META FILEATTACHMENT attachment="wifiDemoCode.png" attr="" comment="" date="1557936842" name="wifiDemoCode.png" path="wifiDemoCode.png" size="44819" user="UliRaich" version="1"
META FILEATTACHMENT attachment="mqttExample.png" attr="" comment="" date="1557936755" name="mqttExample.png" path="mqttExample.png" size="74994" user="UliRaich" version="2"
META FILEATTACHMENT attachment="realData.png" attr="" comment="" date="1557940336" name="realData.png" path="realData.png" size="28318" user="UliRaich" version="1"

Revision 22019-05-14 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Changed:
<
<

Title

>
>

Setting up an IoT

Session3: MQTT and Cayenne

Uli Raich

Formally CERN, Geneva, Switzerland

The Network Layers

The WeMos D1 mini has a built-in WiFi interface

In 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

Accessing the WiFi network from Micropython

wifiConnect.png

MQTT

MQTT (Message Queuing Telemetry Transport: a publish-subscribe based

message 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

mqttPostOfffice.png

MQTT Demo

mqttDemo.png

The Micropython library

micropython-lib.png

A MQTT example using umqtt.simple

umqttDemo.png

  %SLIDESHOWEND%
Line: 10 to 46
 

Comments

<--/commentPlugin-->
\ No newline at end of file
Added:
>
>
META FILEATTACHMENT attachment="wifiConnect.png" attr="" comment="" date="1557854311" name="wifiConnect.png" path="wifiConnect.png" size="131494" user="UliRaich" version="1"
META FILEATTACHMENT attachment="mqttPostOfffice.png" attr="" comment="" date="1557854314" name="mqttPostOfffice.png" path="mqttPostOfffice.png" size="51402" user="UliRaich" version="1"
META FILEATTACHMENT attachment="mqttDemo.png" attr="" comment="" date="1557854608" name="mqttDemo.png" path="mqttDemo.png" size="195883" user="UliRaich" version="1"
META FILEATTACHMENT attachment="micropython-lib.png" attr="" comment="" date="1557855078" name="micropython-lib.png" path="micropython-lib.png" size="77052" user="UliRaich" version="1"
META FILEATTACHMENT attachment="umqttDemo.png" attr="" comment="" date="1557855530" name="umqttDemo.png" path="umqttDemo.png" size="73955" user="UliRaich" version="2"

Revision 12019-05-14 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Title

-- Uli Raich - 2019-05-14

Comments

<--/commentPlugin-->
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback