How a GPS tracker became a logger or an easy and cheap way to organize monitoring of physical parameters of remote objects


    As often happens, tasks do not fit into the standard features of the available tools. So it happened this time. Next, I will outline the problem.

    There are several remote objects in the vast country (Ukraine) electrified, but not having simple technical capabilities for connecting to the Internet. Objects are usually located so there is no need to stutter about 3G or WiMax. Only GPRS is available. It is necessary to be able to monitor the temperature in several rooms of these objects. Moreover, it is desirable if not in real time, then with a minimum delay. It is complicated by the fact that the objects, although real estate, but there may be situations that will be moving. Therefore, capital methods of installation of equipment disappear.

    That is, it would be nice to have such a complex that can be easily transferred to a new place, plug into a power outlet and hang sensors to forget about it. I am well aware that this hour the market is full of suitable solutions, but as always there is a fly in the ointment - this is the price in this case. Plus, often these solutions come with their own software. And if, God forbid, you need to change something in it, then I won’t tell you, many probably communicated on similar topics with support services.


    It so happened that in connection with another project, I had a GPS tracker on my desk, something like this - Their peculiarity is that they are implemented using modules of the Italian company Telit. This company produces both GPS-GSM and just GSM modules. The peculiarity of these modules is that they have inside Python. That is, they can execute scripts. And naturally, all devices and module resources are accessible from Python. Do you understand what it is all about?)

    Many trackers have the ability to directly connect sensors, but in the first you can’t install the sensors at a considerable distance, and in the second their number is limited to two or four. On this I went the other way. Fortunately, the tracker also has a COM port. But with its help it is already possible to interrogate almost any equipment for stationary SCADA systems.

    It is worth noting that since Telit modules almost all have Python on board and scripts written for one module with minimal changes will work on another. It’s just that if the module doesn’t have, for example, GPS, then you need to show remarkable ingenuity and not try to use it in a script.

    I wrote and tested the script on the tracker, and then the modem was already purchasedon the Telit GL868-Dual module and it worked literally right away!

    Also nearby was an analog input module of OVEN firm MVA-8 .

    This is a simple module for inputting analog signals to 8 sensors. Supports Modbus (ASCII, RTU), DCON, ARIES protocols. That's just a tracker and Python does not know about such protocols. Have to train.

    Communication between devices is via RS485 and therefore they can be mutually spaced from each other at a considerable distance. In addition, the sensors themselves can be located quite far from the MBA-8.


    Using Telit modules is quite simple. The written script is loaded into the module and marked for execution. Docs on AT commands and Python functions can be found here GL865-DUAL - the module is in SMT format and the module platform is similar to GE865-QUAD. It’s just a little dopped for our countries.

    It can be seen that it can be soldered without problems at home. The strapping is minimal.

    I want to note that when you download the documentation, be sure to check that it is suitable for the specific firmware version of your module. This is a serious rake. You can search for a bug for a long time and tedious, but it turns out that just the function is not supported. Supported firmware versions can be found from the very beginning of the instructions.

    I will not retell everything that is written on the docks. Everything is available there. In short, we have at our disposal several devices on board somehow: MDM, MDM2, SER, SER2, MOD, GPS (if any). I think by name you guessed what is what. And in the end, it all comes down to the fact that through SER we interrogate MBA8 and try to send it via MDM (modem) to our server, and if it doesn’t work, then we put the data in the history file until better times.

    MDM and MDM2 are not two modems and just two interfaces of the same modem. For what? You will find out if you want to implement something similar.

    Now in order. How to organize work with the modem can be viewed above the link where I gave an example of a tracker. There is a survey of MBA8. We will do it.

    I was not lucky I had the old MBA8 and it supported only its own ARIES protocol. This protocol made me very surprised. Why is it so tricky for me it remains unclear, but I managed to implement the survey on it. You do not have to go headlong into the protocol. Here are the ready-made polling and checksum functions. Please do not kick, this is the first thing I wrote in Python. By the way, Python there, although 1.5.2, is very stripped down. For example, it does not contain floating point numbers as a phenomenon. Therefore, be sure to read the docks.

    Function for calculating the checksum:

    def Crc16Owen(buffer):
        CRC = 0x0000    
        for j in range(0,len(buffer)):
            byte = ord(buffer[j])       
            for i in range(0,8):       
                if ((byte^(CRC>>8))&0x80):
                    CRC = (CRC & 0x7FFF) << 1
                    CRC = CRC ^ 0x8F57
                else :
                    CRC= (CRC & 0x7FFF) << 1
                byte = (byte&0x7F) << 1
        return CRC

    Function for translating ARIES strings to normal view:

    def OwenToHex(S):
        for i in range(1,len(S)-1,2):
            a = ((ord(S[i])+0x09) << 4) & 0xF0
            b =  (ord(S[i+1])+0x09)&0x0F
            Sr = Sr + chr(a+b)
        return Sr

    The polling function of MBA8 with address No. 8:

    ToMva8Request = ['#GOHGONOKHTVU\r',
    def GetMva8Data():
        Mva8Data = ''
        SER.receive(5) #Выгребаем мусор из буфера чтения
        for i in range(0,len(ToMva8Request)):
            ValCurSensor = FFFFFFh + chr(0xf1) #Сообщение что получен фарш
            SRcv = SER.receive(10)
            if len(SRcv)==0:
                ValCurSensor = FFFFFFh + chr(0xf3) #Нет ответа от MVA8
                if len(SRcv) > 13:
                    SRcv = OwenToHex(SRcv) 
                    if (ord(SRcv[-2])*0x100+ord(SRcv[-1])) == Crc16Owen(SRcv[:-2]):
                        if (len(SRcv)==7):
                            ValCurSensor = FFFFFFh + SRcv[4]
                        if (len(SRcv)==12):
                            ValCurSensor = SRcv[4:8]
                        ValCurSensor = FFFFFFh + chr(0xf2) #Ошибка CRC пакета OWEN
            Mva8Data = Mva8Data + ValCurSensor
        Mva8Data = ShortImei + Mva8Data
        Mva8Data = Ascii2Bin("%08x"%MOD.secCounter()) + Mva8Data
        Mva8Data = Mva8Data + Ascii2Bin("%04x"%Crc16Owen(Mva8Data))
        return Mva8Data

    I want to remind once again that before yelling at me with a good obscene language, it’s worth understanding the intricacies of the built-in python, there are a lot of problems.

    There are several limitations. For example, places for scripts and other files are only 2 Mb. But enough for the story file. Also, working with files is very slow and the cold start of such a logger lasts about 1.5 minutes. Of course, you can organize a survey more than once every 30 seconds, but you will have to do it. Since I am satisfied with the survey every 5 minutes, this problem did not concern me. And do not forget that we use memory that has a limited number of overwrites. If your logger is constantly hitting data in the same cell, then you will have enough memory for two months, after which there will be failures. But it’s possible to implement the history file in such a way that the record is kept all the time in different cells, which was implemented. The estimated time of using memory in this mode was about 500 years., If you rely on data from memory manufacturers.

    The modem has one minus - it resets the clock when the power is turned off, I had to organize the receipt of time from the server.

    And by the way, I know that there are the same smart Siemens modems, but I like Telit more. And there are other reasons, but they won’t be here.

    Well, now about the main thing - the price.

    Modem - 2 950 rub.
    MBA8 - 4,189.00 rubles.
    Add sensors + wires yourself.

    In my opinion it turned out pretty cheaply. And do not forget that all this can be easily transferred and installed in another place.

    PS The main idea is that the modem performs not only the functions of the modem, but also the functions of a wizard who interrogates the equipment and functions of the storage. And you do not need to use a separate, even minimal, buffer server.

    Also popular now: