Hello developers. Surilli is back with another tutorial for IOT starters. We will be communicating with MQTT broker (HiveMQ) and publish our data on to a specific topic. For now we will be publishing “Hello World” to topic “TestSurilliGSM”.
What is MQTT?MQTT stands for Message Query Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design principles are to minimize network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium. You can learn more about MQTT at “mqtt.org”
STEP 1: Insert the SIM card.Insert the SIM card into your Surilli as shown in the picture below. Make sure your sim is active and inserted properly.
Note: Make sure your SIM has an active data plan. MQTT uses GPRS on Surilli.
After you have connected both the battery and your antenna to Surilli as shown in the picture below, wait for the blue light to get stable (mostly gets stable after 8-12 fast blinks).
Stable blue light means you are successfully connected to the GSM network/network provider.
Open a new sketch and write the code or download the sketch and library from attachments.
About The Code:
mqtts Mqtts("Client ID", "Broker URL", "Port");
- Client ID -> Assign yourself a unique Client ID. A good standard to follow is “clientId_xxxxxxxxxx”.
- Broker URL -> Paste in the MQTT broker’s URL you are using for test. We will be using HiveMQ to subscribe to our topic. HiveMQ URL = “broker.mqttdashboard.com”.
- Port -> The port through which you want to communicate from. Normally is 1883 for MQTT.
Mqtts.Publish("Topic", "Message/Data");
- Topic -> Topic at which we want to publish our messages/data to.
- Messages/Data -> What we want to publish to our topic. Could be a message or some Integer variable.
Note: Arguments must only be passed as char array. If you have an Integer, String etc. as the variable, convert it to char array first.
STEP 4: Subscribe To A Topic On HiveMQGo to www.HiveMQ.com and click on “Try out” in the “HIVEMQ” tab, as shown in the picture below. Keep following the screenshots as follows:
- Download the library for MqttPubSub given below. Unzip it and paste in into This PC > Documents > Arduino > libraries.
- Now you have completed setting up your hardware. Copy and paste the code given below into your Arduino IDE sketch and hit upload.
- After it is uploaded, Open serial monitor to visualize weather your AT commands are working fine. “OK” refers to a successful execution of that specific AT command.
It will take approximately 30-45 seconds to publish your first message. Check your HiveMQ dashboard and messages should start appearing in it as follows:
#include <MqttPubSub.h>
//mqtts Mqtts("Client ID", "Broker URL", "Port");
mqtts Mqtts("clientId-abcdefghij", "broker.mqttdashboard.com", "1883");
void setup()
{
Mqtts.Connect();
}
void loop()
{
//Mqtts.Publish("Topic", "Message");
Mqtts.Publish("TestSurilli", "Hello from Surilli");
}
You have now successfully published the messages from your Surilli. Wait until the next tutorial and we will send real-time data from a sensor to our web application. See you until then :)
Comments
Please log in or sign up to comment.