ARM platform and broker MQTT, as a modern basis for IoT solutions

The MQTT protocol, for the time being, has gained its popularity and has become the de facto standard in projects aimed at creating solutions for the Internet of Things (IoT). Of course, the Internet of things is a definite abstraction or, more correctly, the concept of building distributed networks of devices or machines. At the same time, private tasks of interaction between Machine-to-Machine (M2M) machines are already effectively solved today, including the level of connection of these systems to the Internet, both for creating industrial automation systems and, for example, for building smart home systems. Obviously, critical systems require a local arbitrator or broker and devices to work out a solution to the situation, regardless of the quality of the Internet connection, as well as in the event of a complete disconnection.



At the same time, as a hardware platform for launching such a broker MQTT, energy-efficient, but no less productive, microprocessors based on the ARM architecture proved to be excellent. This interconnection of the hardware platform, messaging protocols and their software implementation became the starting point in the rapid progress of the development of modern automation systems. Next, we will take a closer look at hardware solutions and software components for implementing one of the most successful messaging protocols in technical systems.





ClusterHAT review: Raspberry Pi cluster computer kit. Photo: MagPi magazine



ARM microprocessor architecture (Advanced RISC Machine) has firmly entered our lives. Almost every smartphone is already working on the basis of this architecture. It is worth noting that the concept of a RISC machine today is quite vague, because its opposite, the modern x86-64 platform, borrowed a lot from the world of RISC systems. But it's not about that, but about the fact that today it has become a synonym or a distinctive feature of a productive and, at the same time, energy-efficient mobile platform, as well as the basis for various inexpensive DIY or “do-it-yourself” devices. In this context, of course, it is impossible not to mention the various options for the Raspberry Pi, up to the solution of the cluster based on the ClusterHAT board, etc. As the main operating system for this platform, Linux has proven itself well. But even here, how not to recall, for example, a system like Microsoft Windows 10 IoT Core?



Well, when there is a choice, but not everything is as simple as we would like. Microsoft Windows 10 IoT Core is a great operating system, but it is primarily intended for developing and running programs, for example, written in C # in Microsoft Visual Studio. This approach can not be called universal. Therefore, while the classic choice for most tasks remains ARM and Linux, as well as Android, as without it. Note that for rapid prototyping, in addition to Raspberry Pi boards, there are also cheaper Orange Pi by Xunlong Software or, on the contrary, more expensive Hardkernel ODROIDs, but at the same time fully justifying their price. It all depends on the problem being solved. And such, for the current project, was the launch of the server / broker MQTT. At the same time, one should not focus on the fact that the project is dedicated to “smart home” or solutions for robotics. This is not critical, since the MQTT protocol itself is a very versatile solution.





CPU-351-13. Low Power, Rugged i.MX6 SBC. Photo: Eurotech



Speaking about ARM, it’s worth thinking not only about modern smartphones, a variety of applications as home routers or prototyping tools. Processors with such an architecture can work in quite difficult conditions of industrial automation systems. For example, single-board computer CPU-351-13 of the company Eurotech. The board of this industrial computer is based on the iMX.6 ARM processor (1.2GHz) and is an efficient system with reduced power consumption (about 4 W per four cores), which is used in IoT / M2M applications, withstanding operation in the temperature range: -40 ° to + 85 ° C. The board contains a video output, battery charger, cellular modem (cellular), WiFi, Bluetooth LE and supports ZigBee technology. The board is also ideally suited for solving problems in transport, since it supports the CAN bus, it has an integrated accelerometer sensor and a GPS signal receiving system.



In addition to industrial solutions, ARM architecture penetrates the server solutions market. The experience of Scaleway, which deploys and rents not ordinary virtual machines, but physical servers based on ARMv8, is interesting here. This solution is interesting for its energy efficiency, from the point of view of the provider, and the lack of a hypervisor or virtualization environment, as such, for the user of the service. Thus, a great environment for launching Docker containers is becoming a reality. This is reminiscent of something like ClusterHAT on an industrial scale, and in terms of performance, it is an excellent choice for container virtualization in the cloud. In general, one cannot but agree that this is a bold, innovative business solution in the direction of hosting services, which has been on the market for quite a long time. It turns out that if you do not buy your Raspberry Pi or equivalent, you can always experiment with an ARM-based server by renting it.





CloudMQTT is a perfect solution for "Internet of Things" messaging



Finishing the choice of the hardware platform and the praise of the ARM architecture, you can put an end to this, but you should not forget that you can always find an alternative solution, and this only pushes enthusiasts, geeks, and ethical hackers to new research and experiments with open hardware platforms. So, we have a task based on Linux to install the broker MQTT and experiment a bit with it.



It was possible not to consider the hardware platform at all, but go straight to work in the cloud service CloudMQTT. But the task is being considered on the basis of the three-level structure of the Internet of things, where intelligent sensors and control systems are located on the lower level. The middle is the seat of the MQTT broker, and it must be located locally so that problems with access to the Internet can be partially solved with internal equipment. And the top level is a cloud with a Node-Red or AWS IoT interface, Azure IoT Hub, etc. In such a concept, it is difficult to imagine the best candidate for the place of an energy-efficient and very low-cost micro-server, something different from ARM.



But this is the way the world works; one cannot say that everything is fine or, on the contrary, everything is bad. Everywhere has its own nuances. The fact is that the three-tier system under consideration is not exactly the Internet of Things; rather, it is a kind of intermediate version of the path to such a concept. Just IoT without an Internet connection should not exist, i.e. not for nothing, we expect the emergence of fifth-generation wireless networks, the improvement of existing communications, etc. In the concept of the Internet of Things there is no place for the level of the intermediate layer, sensors and executive systems should go directly to the cloud, where their interaction will take place.





A Brief, A Practical Introduction to the MQTT Protocol and an Application to IoT. Picture: Zoetrope labs



The MQTT (Message Queuing Telemetry Transport) protocol is an asynchronous telemetry transfer protocol based on the publisher / subscriber principle using a broker. This protocol was developed by IBM and transferred to the category of open projects of the Eclipse Foundation. A feature of the protocol is its compactness, since the size of the data packet header is only a few bytes. It works on top of the standard TCP protocol and, for security, involves the use of authentication mechanisms at the “username / password” level and the use of TLS / SSL transport protocol encryption. At the current time, the MQTT protocol has become the de facto standard for building Internet of Things solutions.



Since MQTT is designed for use in an Internet connection environment, which by definition is not considered reliable, the protocol provides for three levels of quality assurance for the delivery service. QoS 0: At most once - “no more than one”. The publisher publishes a message on the broker, then the broker publishes it to the subscriber. At this level, no guaranteed data transfer to the subscriber is guaranteed. QoS 1: At least once - "at least one." The subscriber must receive this message at least once. However, messages can be duplicated and this should be provided in the logic of their work by the subscriber. QoS 2: Exactly one - "guaranteed one." Provides the highest delivery guarantee and no duplication of messages.



To scale your solutions, you can use a bridge-type configuration between brokers, and thereby reduce the load on each broker separately. Also, the MQTT protocol allows subscribers to receive data across multiple channels at once. To do this, use wildcard-characters "+" and "#" to mark either all the records in a particular subscription, or just a block of messages. For example, a subscription to several different temperature sensors: “sensors / + / temperature / +” or a subscription to all channels at once: “#”. You can discuss the features of the protocol for a long time, but it's easier to try on a real example. As a broker, you can choose a variety of solutions, but one of the most popular and lightweight brokers is Mosquitto .



To deploy the Mosquitto broker, we will select a simple version of a single board computer, for example, one of the first versions of the Raspberry Pi Model B 512MB RAM. This choice is dictated literally by what was at hand. Of course, for a real project, it is necessary to study separately the question of the reliability and performance of the board and, besides the choice of optimal hardware solutions, the issues of reliability of the case, quality of the power supply, security of the system as a whole, etc. The Raspberry Pi board was also interesting to take to completely dispel the myth of the difficulties of starting a project based on open hardware solutions and the Linux operating system. Of course, basic knowledge is required from the developer, but modern platforms have become exceptionally user-friendly from the point of view of the software interface and are well documented.





Photo: Raspberry Pi Model B 512MB RAM



As an operating system, you can make a choice in the direction of the official firmware Raspbian Stretch with desktop or Raspbian Stretch Lite. These are two identical operating systems based on the well-known distribution kit Debian Stretch, which was modified to work with Raspberry Pi. Differences, only in the presence of a graphical desktop, which is quite justified for the beginning of the acquaintance, but for the server, of course, the graphical shell has nothing. To install, we will choose a version with a graphic desktop and install all this on an inexpensive 8GB SD card. In fact, it remains to download the image of the operating system and transfer the image to the physical drive using the very convenient Etcher cross-platform utility.





Screenshot: Etcher in Windows 10



It now remains to place the flashed flash drive into the Raspberry Pi board and apply power. There is an ode feature if you need to get remote access to the Raspbian Stretch command line using the ssh protocol, and there is no keyboard physically connected to the board, you can write an empty file with the name ssh to the boot partition of the flash drive, which will enable the appropriate access. After switching on and Raspberry Pi, access to the operating system is allowed to the user “pi” with the password “raspberry”. The default user “pi” can become root by running the sudo command. Since everything in Raspbian is prepared for comfortable work of an unprepared user, the first command in the new system can be to call the system configuration menu:



$ sudo raspi-config









Screenshot: Remote connection to Raspberry Pi by SSH and run raspi-config



The raspi-config utility allows you to set a new password for the user and, for example, in the “Interfacing Options” menu, you can configure the behavior of the system interfaces, enable the remote desktop using the VNC protocol, etc. Also in the menu: “Boot Options” you can set default parameters for booting the system, for example, select only the command line mode, and in the sub-menu “Resolution” from the Advanced Options menu, set the desired resolution of the graphical screen, for example, by selecting the required size “DMT” - for a digital monitor interface or “CEA” - an analog input, etc.



Now you can upgrade the system packages:

$ sudo apt-get update

$ sudo apt-get upgrade








And install the Mosquitto broker and the MQTT client, for example, to test the system:

$ sudo apt-get install mosquitto

$ sudo apt-get sudo mosquitto-clients








Now you can check the operation of the broker MQTT locally by subscribing, for example, to an event:

$ mosquitto_sub -h localhost -t "sensor/temperature"







And publish some values ​​for the corresponding channel:

$ mosquitto_pub -h localhost -t "sensor/temperature" -m 21.0









Screenshot: Raspberry Pi terminal sessions



You can view subscriptions and publish using the MQTT protocol, as well as test the broker’s load capacity, in the Chrome browser and operating systems: Linux, Mac, Windows thanks to the cross-platform application MQTTBox .



Indeed, the MQTT protocol has now become so common that it is simply impossible to not find a convenient solution for your tasks. Also within the framework of the Eclipse Paho project, the development of open software solutions and libraries is being actively developed in almost all programming languages ​​to implement the MQTT messaging protocol and, thereby, improve solutions for the Internet of things.



Building solutions based on the MQTT broker is becoming a trivial task. One has only to deploy the system, connect to the cloud, for example, using Node-RED or a specialized solution, and the matter remains “small” - to connect intelligent sensors and actuators. For consideration of the lower level of IoT systems, a separate article should be written, but for this example, it is quite possible to get by examining the example based on the actual standard for the Internet of things - the NodeMCU board based on the Espressif SoC ESP8266.





Screenshot: MQTTBox in Windows 10



Fee NodeMCU initially focused on the development of the language eLua . To build the firmware, you can use the cloud service , and the project board itself exists as an open hardware solution NodeMCU DEVKIT V1.0 , for which many analogues have already been released. It should be noted good project documentation. However, it is very subjective, but when developing an intelligent sensor with MQTT protocol based on firmware with eLua for NodeMCU DEVKIT, you still have to face a number of difficulties with the implementation of the MQTT protocol. At the same time, the entire infrastructure of the project looks somehow insufficiently prepared for use as an environment for the rapid and high-quality development of microprocessor systems. Some little things and nuances always come up, but once again it is worth repeating - this is a very subjective assessment. Interestingly, do blog readers have successful experiences with eLua and MQTT?



A completely different thing is choosing the Arduino IDE development environment for working with NodeMCU DEVKIT, however, as with other ESP8266 based motherboards. Everything is done almost instantly on the basis of ready-made libraries and code samples. To begin development follows from the official site of the Arduino project to download the open cross-platform Arduino IDE development environment. Then, in the “File” - “Preferences” - “Addition Boards Manager URLs:”, specify the link to the Arduino core project for ESP8266 WiFi chip: arduino.esp8266.com/stable/package_esp8266com_index.json Then in “Tools” - “Boards Manager It remains to download and install support for the ESP8266 Community boards. By the way, we should not forget that to work with the NodeMCU board, you need to install the driver for the interface converter CP210x or, it is also called the UART to USB bridge.





Photo: Working with the NodeMCU board



To work with the MQTT protocol, you can install the PubNub Arduino Library. To do this, in the “Sketch” menu - “Include Library” - “Manage Libraries”, select the appropriate library and install it. You can familiarize yourself with the capabilities of the software platform on the basis of an example code, for example, Basic ESP8266 MQTT example, where the broker publishes the “outTopic” channel, and also subscribes to “inTopic”, and when it reaches “inTopic”, “1”, then The board turns on the built-in LED. Everything is simple, fast and works fine out of the box.





Screenshot: Arduino IDE with ESP8266 support



In conclusion, I would like to note that this publication does not call for the use of the ARM processor architecture exclusively for building IoT systems and it only touched upon the features of the implementation of the MQTT broker as a link for automation solutions. But at the same time, the reader may form an opinion that today solutions for IoT are a lot of geeks, experimenters and fans, for example, Raspberry Pi boards. This is true, and this is where progress is made, but the future is already with us.



An example is obvious: the commercial solution of the Wzzard wireless sensor platform for IoT and Specter Network Gateway from Advantech B + B SmartWorx. Here, as in many of today's implementations in production cycles, an architecture of environmentally protected industrial sensors has been proposed, which are combined by a wireless network based on the 6LoWPAN and IEEE 802.15.4e standards. For data processing at the cloud level, a gateway with support for the MQTT protocol and data transmission over a wireless 3G network or wired 10/100 Ethernet is proposed.








Resources and related links:



ARM processors: architecture features, differences and perspectives - ITC.ua

Orange Pi PC - high-grade mini-pc for 15 dollars on Linux - Geek magazine

ODROID-C1 - review and comparison with RPi - Habrahabr

First look at Scaleway - Habrahabr

IBM moves the MQTT protocol to the category of open projects - OpenNET

Protocol MQTT - iot.ru

MQTT protocol. Features, applications, basic procedures - Technology and communications

Raspberry Pi documentation. Remote access - Raspberry Pi Foundation

Initial Raspberry Pi Setup - Domoticz

Getting started with MQTT Mosquitto Broker on Raspberry Pi, Windows, MacOS and Linux - DIY Projects

The Seven Best MQTT Client Tools - HiveMQ

Temperature upload over MQTT using NodeMCU and DHT11 sensor - The ThingsBoard Authors

MQTT Tutorial for Raspberry Pi, Arduino, and ESP8266 - Baldengineer Blog

ESP8266 firmware, programming in Arduino IDE - Geek magazine

Wireless Sensor Network Platform - Connect2 Systems



All Articles