IoT — temperature and humidity sensor example using MXDevKit and Custom MQTT Broker
In the previous article, I described how to configure a custom MQTT broker on AWS EC2 instance and test out the different types of communication. This post will provide a Step-By-Step guide to create an IoT example using a custom MQTT broker, a microcontroller and an Android phone.
1 Before you start
You need to have following parts to start:
- MXChip IoT DevKit AZ3166 (http://mxchip.com/az3166)
- MQTT Broker (e.g. iot.eclipse.org or DIY one)
- Android Smartphone with installed MQTT Dash app
2 Configuration and Preperation
In order to prepare the development environment, use the instructions https://microsoft.github.io/azure-iot-developer-kit/docs/get-started/ to (1) configure your MXDevKit and (2) install the development tools on your machine.
3 Scenario
In this scenario we are using a MQTT communication to get temperature and humidity from the MXDevKit everytime we publishing a new message to the topic “mxtest” using the MQTT Dash app on the Android device.
4 Microcontroller program
For this scenario the Microsoft MQTT example Sketch was used as base and adapted according to the above defined scenario. You can find this sketch here.
5 Installation on MXDevKit
- If you have an AntiVirus Software like McAffee, you have to deactivate it before.
- Download the sketch
- Open VS Code with Administrative Privileges
- Open the sketch
- Connect the MXDevKit
- Configure mqttServer variable in MQTTClient.ino
7. Upload the sketch to the MXDevKit
(1)Use CTRL+P and then (2) enter task device-upload
6 Configure MQTT Dash
- Open MQTT Dash on your Android device
- Create a new connection to the configured MQTT Broker and port (e.g. iot.eclipse.org Port:1883)
- Create a new TEXT subscription and subscribe to the topic “mxtest” (Note: In case you have changed the topic in the Arduino Sketch use this one)
7 Result
After successfully done the above steps, you will see following result.