Friday 19 October 2018

A MQTT demo using ESP-01 (ESP8266)

I created a very simple demo based on ESP-01 module and MQTT protocol.

A video of the demo is also available here:



MQTT is a popular protocol for IoT, the client implementation is small in footprint and there are all kinds of example codes available on the internet, from C to Java or Java Script.

This demo is based on C code, which is provided as an example in the esp-open-rtos SDK. The circuit is very simple, it has 2 LEDs connected to the ESP-01 and a mobile phone is used to control these LEDs.

There are several open MQTT servers providing free access to public on the internet, such as test.mosquitto.org, and a private server is also very easy to setup, if you use Ubuntu, you can simply use command
sudo apt-get install mosquitto
to install the open source MQTT server on your computer. I'm using a VPS as the server, to verify that this concept will actually work in the cloud.

The red and blue LEDs are belonging to different topics, and are subscribed to the topic. The mobile phone App has two buttons, one for each LED, when you press the button, the App will publish a new message to the corresponding topic. The published message will toggle between '0' and '1' every time the button is pressed. Then the message will be delivered to the subscribed client (ESP8266), the microcontroller will decide whether to turn the LED on or off according to the message content.

No comments:

Post a Comment