MQTT’s simplicity is welcoming hundreds of tech-savvy enthusiasts to utilize the protocol in their projects and get quick results. Today we’ll be talking about one of such projects created by one of flespi MQTT broker users, an Austrian industrial engineer Reinhard Dämon. You can contact Reinhard (email@example.com) at any time in case of questions or suggestions.
The project is a perfect illustration of an engineering approach to life — if you can’t find what you need, invent it yourself.
The project represents a firmware for a cheap and simple ESP8266 ESP-01 hardware that allows the user to control it over its serial port.
A typical application situation would be as follows:
Connect to your Wi-Fi (SSID and password) and to Flespi MQTT broker (token):
Wait and check whether already connected:
(if connected, ESP8266 responds "r:con:+<CR><LF>", if not: "r:con:-<CR><LF>")
When connected, publish a message, e.g.:
(this will publish the payload "abc" to topic "top/1" with QoS1 and no retaining)
Subscribe to a topic:
(to subscribe to topic "top/1" with QoS1)
Get the number of topic/payload pairs in the FIFO buffer:
If there is data available in the FIFO buffer, read it:
Then you can determine any logic based on the received data (see use case below).
Any kind of data can be transmitted from anywhere in the world to anywhere else, provided that Wi-Fi and the Internet connection are available.
You can easily observe the communication process. Go to MQTT Board. Enter your Flespi token as a username and connect.
You can enter # into the topic field of the subscription section and subscribe in order to
watch all traffic or just enter the topic/subtopic you are interested in.
One of the key advantages of the proposed solution is that it can work with a variety of hardware. It can apply to any uC, processor, personal computer, terminal, etc. that has a serial port (or can provide a virtual COM port from a physical USB port). Only GND, 3.3V, RX, and TX pins are used.
The areas of application for the given solution are not limited to any particular domain since MQTT is simply a communication protocol that can ensure reliable data exchange between any two or more parties.
Any kind of remote control or telemetry can be done. The user is free to publish anything to any desired topic and subscribe to any topic, as well.
One of the key advantages of the proposed solution is that it’s very cheap and all-purpose making it suitable for hobbyists, amateurs, and professionals alike.
Just flash the provided firmware to the ESP8266 ESP-01 module, connect it to your uC, processor, personal computer, terminal, etc., and communicate to the module via plain-text commands.
The solution is easily scalable to serve businesses — it’s a matter of uploading the same firmware on all ESP8266 ESP-01 modules used in the project. Companies will use bulk programming systems, while hobbyists may stick to Arduino IDE.
Simple use case
Here’s an example of a real-life project that relies on the discussed solution.
An appliance which senses the AC level of some electrical machine (e.g. washing machine, clothes dryer, etc.) that runs a program (washing, drying, etc.) for some time and stops thereafter.
While running a lot of current is consumed (publishing "running" via flespi) and when finished nearly no current is consumed (publishing "done" via flespi).
An appliance listening to a particular topic and receiving either "running" or "done". These values are then interpreted as corresponding LED lights: red light = “running”, green light = “done”.
As already mentioned, the PUB/SUB principle behind the MQTT protocol provides fast, lightweight, and secure M2M communication independent on the hardware type. Therefore, any applications requiring device-to-device interaction can benefit from the solution.