MQTT is an easy to use protocol that enables IoT devices to pass messages. In this project, I used the integrated WiFi capability of the RTL8195 Ameba-1 development board together with a DHT temperature and humidity sensor to send and receive MQTT messages containing the sensor readings.
In this project I am using the Ameba-1 development board from Realtek, based on the RTL8195/RTL8710 soc, part of its AmebaIoT ecosystem. This board can be programmed using the Arduino IDE and is pin compatible with many sensors and expansion boards. It also has WiFi, NFC, and USB Host functionality as well, making it suitable for many IoT applications. Any other development boards capable of a WiFi connection can also be used, but the code will need to be changed.
To begin with, ensure that you have the Arduino IDE installed and configured for programming the Ameba-1 board. Instructions to do this can be found at https://www.amebaiot.com/en/ameba-arduino-getting-started/.
Next, connect the DHT11 sensor module to the board by following the wiring diagram in the youtube video here.
Once the wiring is done, connect the board to the computer. Download the code provided at this GitHub link and open it in the Arduino IDE. Before you upload the code to the board, there are a few changes that need to be made to the code. Please make the following changes:
- Line 16 - enter the name of the WiFi network the board will connect to
- Line 17 - enter the corresponding password of the WiFi network
- Line 20 - enter the URL or IP address of the MQTT server to use. If you do not have your own server to use, you can choose to use the free server at test.mosquitto.org
Upload the code to the board once these changes are made.
On your Android/iOS mobile device, download and install a MQTT client from the app store if you do not have one already. Configure the app to use the same MQTT server, and subscribe to the topic "ameba_xxx" shown on line 12 of the code. The Ameba-1 board will send a MQTT message with the updated sensor readings every 10 seconds. Blow on the sensor or heat it up, and you can see the published sensor readings change on your phone.