MQTT protocol overview

The MQTT protocol is based on the publish-subscribe architecture. It's a very lightweight protocol, where message exchange happens asynchronously. The main usage of the MQTT protocol is in places of low bandwidth and low processing power. A small code footprint is required for establishing an MQTT connection. Every communication in the MQTT protocol happens through a medium called a broker. The broker is either subscribed or published. If you want the data to flow from Edison to a server, then you publish the data via the broker. A dashboard or an application subscribes to the broker with the channel credentials and provides the data. Similarly, when we control the device from any application, Edison will act as a subscriber and our application will act as a publisher. That's how the entire system works out. The following screenshot explains the concept:

Overflow where Edison acts as a publisher

In the preceding screenshot, we see Edison acting as a publisher. This is one type of use case, where we need to send data from Edison, as with a similar example shown in Chapter 2, Weather Station (IoT). The application will get the data and act as a publisher. The following screenshot depicts the use case that will be used in this chapter: the use of Edison as a subscriber:

Overflow where Edison acts as a subscriber

In the preceding case, we have some controls on the application. These controls send signals to Edison via the MQTT broker. Now, in this case, the application will act as a publisher and Edison acts as a subscriber.

It is to be noted that in a single system, you can make the endpoint (device or application) act both as a publisher as well as a subscriber. This occurs when we want to get some data from the IoT device, such as the Intel Edison, and also control the device in emergency cases. The same may also occur when we need to control the home's electrical appliances, as well as monitor them remotely. Although most systems are deployed based on a closed loop feedback control, there is always room to monitor them remotely, and at the same time have control based on feedback received from the sensors.

To implement the MQTT protocol, we are not going to set our own server but use an existing one. https://iot.eclipse.org/ has provided a sandbox server which will be used for the upcoming projects. We're just going to set up our broker and then publish and subscribe to the broker. For the Intel Edison side, we are going for Node.js and its related libraries. For the application end, we are going to use an already available application named MyMqtt for Android. If anyone wants to develop his or her own application, then you need to import the paho library to set up MQTT. We are also developing a PC application, where we will again use MQTT to communicate.

For details on the eclipse IoT project on MQTT and other standards, please refer to the following link:

https://iot.eclipse.org/standards/

In the following section, we'll set up and configure Edison for our project and also set up the development environment for the WPF application.

The paho project can be accessed through this link:

https://eclipse.org/paho/

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.12.140