Hello back developers. We are here again with yet another tutorial, this time expanding the potential domain of Surilli. Yes, Android is stepping in. Today we will be using our Surilli GSM to publish messages to an MQTT broker and receiving / subscribing it on to an Android application. Bam! We will be sending values of temperature and humidity around our Surilli and observe them on our smart-phones.
Note: If you haven’t gone through our previous two tutorials, MQTT-GSM & DHT11 integration with Surilli, it is highly recommended you read and perform those first and then come back here.
- First client: Surilli-GSM.
- Broker: HiveMQ.
- Second client: Android application.
Plug in the Surilli to your PC and connect:
- Lipo Battery
- GSM Antenna
- DHT11
Connect the pins of DHT11 and Surilli as follows. DHT11 -> Surilli
- GND -> GND
- VCC -> 3.3V
- DATA -> PIN10
Copy and paste the code given below in the Arduino IDE sketch and save it on to your PC.
NOTE: Necessary Libraries are given below. Download them and paste the folders (after unzipping) in: This PC > Documents > Arduino > libraries.
STEP 3: Get “MQTT Dashboard” from PlaystoreDownload the app and install it into your android phone. You can use any other MQTT client dashboard app available on Playstore but this is highly recommended. After the app is installed, follow the steps in the video below: (Assign yourself any other unique Client ID e.g. “clientId-YOURNAME12345”) Everything else remains the same.
When you are done, and app says connected to broker… on the top of the screen, as shown in the picture below, move on to the next step.
Open your Arduino IDE and hit upload button under the “Edit” tab. Wait for MQTT to setup. Keep checking your mobile app. The humidity and temperature values will start to show up after 15-20 seconds. As shown in the GIF below:
#include <dht.h>
#include <MqttPubSub.h>
//mqtts Mqtts("Client ID", "Broker URL", "Port");
mqtts Mqtts("clientId-WpdRzvpxEE", "broker.mqttdashboard.com", "1883");
#define dht_apin 10 // Analog Pin sensor is connected to
dht DHT;
void setup(){
Serial.begin(9600);
delay(1500);//Delay to let system boot
Mqtts.Connect();
}
//end "setup()"
void loop(){
//Start of Program
DHT.read11(dht_apin);
char H = (char(DHT.humidity));
char T = (char(DHT.temperature));
Mqtts.Publish("TestSurilliTH", (H, DEC));
Mqtts.Publish("TestSurilliTH", (T, DEC));
delay(5000);//Wait 5 seconds before accessing sensor again.
//Fastest should be once every two seconds.
}// end loop(
That’s it. See you next time.
Comments