LOGIN
Subramanya Chakravarthy
Engineer (Project Leader)
 · HyderabadIndia
Edit
Delete
Share
Report
TASK
Open
  ·  Close Task

Control a Led through MQTT protocol

1 like 
Like
Share
Swapnil Kalhapure
Entrepreneur, roboticist and avid blogger
 · PuneIndia
Edit
Delete
Share
Report
0 like 
Subramanya Chakravarthy
Engineer (Project Leader)
 · HyderabadIndia
Edit
Delete
Share
Report

I will check now

1 like 
Aman Kashyap
Embedded Real Time System Engineer
 · BengaluruIndia
Edit
Delete
Share
Report

I am currently working on MQTT so if you need anything regarding MQTT and how the connection is made or explanation for the OPEN SOURCE libraries that you are thinking of using then let me know. I am making the MQTT protocol stack from scratch so I am pretty sure I will be able to help if you are stuck in this. Also if you want to control the LED/Anything through MQTT and need it to be stand alone then GSM is the best option in every ASPECTS be it cost, responsiveness, reliability etc. Keep me posted!

1 like 
Aman Kashyap
Embedded Real Time System Engineer
 · BengaluruIndia
Edit
Delete
Share
Report

Okay let me help you a little bit to get started with this awesome protocol!
Think as if you want to send some data on TCP link to a server but you dont know in what format you want to send. You have a number of different values and you want to send them-
Example:-
1.) Motor rotation speed
2.) temperature of 5-6 sensors
3.) Smoke detector sensor data
4.) pressure sensor readings
5.) air humidity data
6.) GPS data/coordinates
7.) bla bla bla
8.) bla bla bla data
9.) bla bla bla reading
10.) bla bla bla
So now you want to send this data over TCP to the server. You cant send the data just in a raw format right? you need to arrange all of the readings in some format and then send it to the servers so that the server should be able to understand the data and act accordingly with all the nodes connected to it, yeah?
So what you do is arrange them in a specific format. Let us again take an example -
1.) Motor rotation speed = mr: <data>
2.) temperature of 5-6 sensors = ts: <data>
3.) Smoke detector sensor data = sd: <data>
4.) pressure sensor readings = ps: <data>
5.) air humidity data = ahd: <data>
6.) GPS data/coordinates = gps: <data>
7.) bla bla bla 1 = bbb: <data>
8.) bla bla bla data = bbbd: <data>
9.) bla bla bla reading = bbbr : <data>
10.) bla bla bla 2 = bbb2: <data>

Now this is all the short forms and data following them. everything will be arranged and delimited by a comma ‘,’ which will make it easier for YOU, SERVER AND THIRD PERSON to read and understand it.
Now you think that “how will I send the data over TCP?” AND THIS IS WHERE all the Connection request and acknowledgement we read about in college comes in handy
So you think …OKAY …I will send a first connect request to the server and if the connection is accepted then I will Send the data to the server. BUT THEN YOU AGAIN THINK - How will the server know that I want to connect to it? To crush this problem you make a code for Connect request and Data send.
So the flow chart will be -
CLIENT ------Con REQ------> SERVER
CLIENT <------Con ACK------ SERVER
CLIENT --------YAY! LETS SEND THE DATA!!!
CLIENT --------Data with checksum-----> SERVER
CLIENT <-------ACK with verified checksum------SERVER
CLIENT <-------YAY!!------> SERVER

MQTT is nothing but a clever way of forming a packet and sending it over TCP LINK to the server.
There are terms that are used when working with MQTT.
Broker - Its nothing but a server that will just handle the exchange of data between nodes.
Publisher - Tricky! But lets try to understand it.
As you would have read about MQTT that its a publisher subscriber model of communication.
Take an example of email. Now you subscribe to a newsletter of Collaborizm and you want to stay updated. Whatever happens in Collaborizm will be sent to you on email. Collaborizm is one node that will send the data to the server (PUBLISHER) and you are getting the emails (SUBSCRIBER) of all the things going on Collaborizm.
Same goes with this MQTT. There are nodes for example- temp sensor, pressure and a microcontroller having a TCP LINK (just imagine) to the BROKER (Server). Temp and pressure sensor publish (Send data) to the broker TOPIC WISE. FOR TEMP SENSOR TOPIC WILL BE TEMP_SENS_TOPIC AND FOR PRESSURE SENSOR WILL BE PRE_SENSOR_TOPIC and you are SUBSCRIBED to both of them. What all the broker does is that it directs the message to the SUBSCRIBER which is THE MICROCONTROLLER in this case. You receive the data and accordingly act on it.

Read more and you will BE ABLE TO UNDERSTAND IT. If not download the software and install it. PLAY with it for some time using the public broker. READ THE PACKET FORMAT AND ALL THE THINGS IN DETAILS. OPEN WIRESHARK and analyze the packet. Refer the MQTT.ORG MQTT 3.1.1 Official doc. Compare the wireshark packet to the packet format descrived in the doc. You will surely get it.

2 likes 
Aman Kashyap
Embedded Real Time System Engineer
 · BengaluruIndia
Edit
Delete
Share
Report

I have left the things that you will get by yourself. This was for your kickstart. Looking forward to see your project working real time! Cheerios

0 like 
Subramanya Chakravarthy
Engineer (Project Leader)
 · HyderabadIndia
Edit
Delete
Share
Report

Aman Kashyap thanks for the detailed explanation.

0 like 
Leave a reply...
DISCOVER
CHAT
ALERTS
-2
DISCUSSIONS
-1
FEED