semunimed2022
You can execute the code either in your computer or online:
paho-mqtt
library:The documentation of the MQTT Paho API is here: https://www.eclipse.org/paho/clients/python/docs/
The code of this section is here
File: sisub.py
cointains the code of a simple python subscriber. This code connects to a public broker and subscribes to topic $SYS/#
.
Let's see:
File: sipub.py
cointains the code of a simple python producer. This code connects to a public broker and periodically publishes random values to topic "PMtest/rndvalue"
Let's see:
To check whether this is working we can use the previous code sisub.py
… with a slight modification… which one?
The Things Network uses MQTT to publish device activations and messages, but also allows you to publish a message for a specific device in response.
You will now read the values of two LoRaWAN sensors that are periodically sending their data to the TTN Network Server from the GRC lab.
The basic data we need is the following:
As a first example we will modify the code of sisub.py
to get the raw information from TTN, see file sisubttn1.py
in the repository.
Let's see:
The structure of the raw message is:
Now we can sligtly modify the code to get a specific piece of information, see file sisubttn2.py
in the repository.
To get sometthing like this:
OK, so now, what if we want to "containerize" this app so that simply running as: docker run -t mysubttn
we get the result above?
Which is the content of the Dockerfile?