The best way of learning a new technology is by working with it.
I am continually creating scripts for testing and demo purposes,and doing small projects to gain a better understanding of MQTT and associated technologies.
In this section I will take you though some existing scripts that I have created as well as new ones.
I will endeavour to create a video (s) for each project so as to make it easier to understand .
You will be able to download the code, use and modify it to help with your own projects.
You should note that any Scripts are for educational purposes,but you are free to use them in your own projects without restriction.
Controlling Devices Using MQTT and Python
Online tutorial and downloadable Project workbook where we use MQTT to control a python script. The script is a simple sensor but I have used the same technique to control many other python scripts.
What it covers:
- Basic topic design
- Basic MQTT API creation
Prerequisites
You should be familiar with the Paho MQTT client
See Controlling Devices Using MQTT and Python
Python MQTT Bridge
Many networks will have a local MQTT broker (edge broker) which also connects to a cloud broker.
The broker could be configured as an MQTT bridge and relay messages to the cloud broker.
However some brokers don’t support this functionality (Aedes) and also you many want to only bridge changed messages,topic aggregation, or topic remapping that isn’t supported by the broker.
In addition you may not be the broker administrator and so doing it on the broker is impossible.
In this project we look at using an MQTT client (python client) to do the bridging
This is an ongoing project with a simple bridge and an aggregating bridge available.
See Python MQTT Bridge –
Simple MQTT Data Logger using SQL – This script Logs sensor data to a a SQLLite database .
Simple MQTT Data Logger – This script Logs data to a files as simple text or JSON encoded data .
How to Send a File Using MQTT– Reads a file from disk and sends it using MQTT. It uses a file hash to check that the file is received ok.
Encrypting MQTT Payloads with Python – Example Code. -Payload encryption is easier to implement than SSL link encryption. This is an example Python script that implements MQTT payload encryption.
Republishing HTTP Data Over MQTT
HTTP is the protocol that powers the Web,and is the most common protocol on the Internet.
Because of this it has been used in many scenarios were it is not ideally suited.
Any type of public information system e.g flight or bus arrivals and departures is more suited for MQTT than http.
In this project we take an example of a flight arrival system taken from a real airport and republish this data over MQTT.
What is particularly interesting is how easily and seamlessly this could be done.
See flight arrivals – Republish HTML Data Over MQTT
Simple Device Simulators
Very often when helping clients with their projects I find that I don’t have the specific hardware that they are using.
To overcome this I create a simulator that allows me to simulate the features that I need.
I create them either Python or Node-red Depending on the project and what is required.
If you would like a simulator for your project then use the Ask Steve page to contact me
Sensor Simulators
Simple Controllable MQTT Sensor Simulator in Python -A very simple two state sensor using python , that can be controlled externally using MQTT.
Suggestions
Do You have a suggestion for a project or workbook then please let me know using the comment form.
Hi steve,
I had a doubt on mqtt qos1 and 2. If we are implementing mqtt client in hardware(esp), are we able to see the acknowlegements in device console ?. It is ppossible to view the ack on client side.
If posible mention the method to implemen the client.
The python client will show the PUback message the qos 2 exchange is not shown just the end result. I did modify the client to show these messages for demo purposes so you can do it but not with the standard client.
Does that help?
Rgds
Steve
Hi Steve,
Is it possible to communicate via mqtt which is having different networks, other than local Networks??