About the benefits of standardization

Hi Habr! I am engaged in the development of electronics (good skills cover most of this interesting hobby). And they somehow ordered me to develop a GSM logger for housing and communal services.

In addition to the presence of the required inputs / outputs (including 4-20 mA) and a 5-30 V power supply for sensors, the main condition was to minimize consumption in order to be able to be powered by batteries. protocol. I wanted something simple and standard.

MQTT. But MQTT is TCP with all the advantages and disadvantages. And I have a battery and a life of 3 months. For tests, a primitive protocol was written on top of UDP. But since I do not consider myself a pioneer, I am firmly convinced that now something digestible will be written in 2 days - I continued searching for something generally accepted.

I don’t remember how - I got a mention of MQTT-SN. A protocol that inherits MQTT semantics, but is adapted for UDP and battery-powered clients. It turned out that there is one developed in the bowels of IBM and subsequently open to the community. After reading the description, it became clear that here it is, happiness, nearby.

But you need a broker (as the server is called in MQTT), the familiar Mosquitto (according to Jan Krags from 2013) will someday be able to use MQTT-SN, but not now. But there is RSMB, and even in the source code on the Git hub.

Sources are good, you need to collect. The assembly is done by CygWin in Visual Studio (which I last saw about 5 years ago). We put the free version, we create the project and - in any way. 5-10 times (in general, chance and stubbornness play an important role in my life) the project was prescribed correctly - and oh, miracle, I got the broker. I note that under Linux this action went much easier.

Solemnly launched. It's a shame but does not work. Maybe after all, your protocol is the way out? Having imagined the amount of work on writing and debugging the server and clients, I decided not, my choice is MQTT-SN. Everything turned out to be simple - it was necessary to register the configuration and indicate to the broker.
The minimum looks like this:

trace_output off                # Диагностика, можно и включить
listener 1883 INADDR_ANY        # Порт для обычного MQTT
listener 1883 INADDR_ANY mqtts  # Порт для MQTT-SN протокола

And after that, the broker earned. In short, the differences between the MQTT-SN and the classic MQTT.

  1. The MQTT-SN protocol runs on top of UDP, not TCP as normal. This shifts responsibility for controlling message delivery to the programmer. But it allows the device to spend less energy (which is important for me) to maintain a communication channel via GSM.

  2. A new level of QoS (Quality of Service) -1 has been introduced. Meaning lack of delivery control. The device wakes up, does the necessary work, sends the results and then falls asleep without waiting for confirmation.

  3. There are gateways that allow you to aggregate data from multiple devices and send them to the broker.

The git eclipsa contains the source code for the MQTT-SN client with examples. Actually, you need to prescribe the functions of working with the transport_xx channel to your needs. Otherwise, there are no big problems (I found a couple of errors, I need to test).

Unfortunately, support for sleeping clients has not been implemented. There are stubs. Who can throw a stone at the authors of the protocol - source codes are available, help is welcome.

What I wanted to say in the end. Having spent some (small time), I got a ready-made infrastructure for the further development of the project. The protocol allows the use of STM32 at 4 MHz. I can use many clients on different platforms (which would be unrealistic to do alone when writing my protocol). Moreover, having the opportunity to build a broker for Linux, I placed it on an Amazon instance and my customer got a solution without the need to keep and maintain a server. Standard solutions (not always, but in the vast majority of cases) speed up the task.

Links:
MQTTSN client - Eclipse
RSMB - github

Also popular now: