Tunnel – Reading and periodic sending of records of 5 Electric meters with ModBus RTU protocol and memory map for different records to a webserver

¿Buscas alguna otra cosa?

Scenario details:

  • We have 5 electric meters with modbus RTU protocol. These meters have, in their internal memory, a series of variables/records (for example, accumulated and average consumption) that must be periodically read and sent to a web server
  • To do so, the MTX-Tunnel must periodically question, every 15 minutes, via a serial port, the 5 meters in order to read the records. The records to read are different for each meter
    • Meter 1: records 20 to 21 and records 100 to 105
    • Meter 2 and 3: records 30 to 35
    • Meter 4 and 5: records 40 to 60
    • Meters 1, 2 and 3 will use the modbus read command 0x03 (the most usual), meters 4 and 5 will use the modbus read command 0x04
  • After each reading the MTX-Tunnel must send the value of the records to a web server via HTTP GET using a JSON object, but must be able, in case of 3G communication failure, to store up to 1500 records using flash memory that will be sent when communications are restored. For each meter it will send a JSON frame, where an identifier will specify (the modbus address) which meter has been read

Solution: MTX-Tunnel firmware + MTX-Java-IoT/MTX-Java-T/MTX-Java-T2

EXAMPLE of settings (file config.txt) for such scenario:

Configuration Observations
COMM2_baudrate: 9600
COMM2_bitsperchar: 8
COMM2_autorts: off
COMM2_autocts: off
COMM2_stopbits: 1
COMM2_parity: none
GPRS_apn: movistar.es
GPRS_login: MOVISTAR
GPRS_password: MOVISTAR
GPRS_timeout: 0
MTX_PIN: 0000
MTX_mode: none
MTX_model: MTX-4G-JAVA-IOT-STD-N
MTX_portAux: modbusmaster
MTX_TPProtocol: ntp
MTX_TPServer: ntp.roa.es
MTX_TPServer2: es.pool.ntp.org
MTX_ping: 35
MTX_pingIP: 8.8.8.8
SMS_allPhones: on
SMS_sendIP: on
SMS_sendIP: on
SMS_ATEnabled: on
SMS_ATResponse: on
FIREWALL_enabled: off
TELNET_enabled: on
TELNET_login: user
TELNET_password: 1234
TELNET_port: 20023
LOGGER_enabled: on
LOGGER_password: ID00001
LOGGER_server: www.miservidorWeb.com/json.asp?data=
LOGGER_registerSize: 300
LOGGER_numRegistersFlash: 1500
LOGGER_httpMode: jsonget
MODBUS_address: 1;1;2;3;4;5
MODBUS_start: 20;100;30;30;40;40
MODBUS_numwords: 2;6;6;6;21;21
MODBUS_period: 900
MODBUS_readCommand: 3;3;3;3;4;4
Serial port baud rate
Number of bits
No flow control
No flow control
1 stop bit
No parity
APN GPRS from your network operator
GPRS Login
GPRS Password
Modem is always GPRS connected
SIM Card PIN
MTX-Tunnel mode
MTX modem model
AUXILIAR COM port used as master modbus
Time synch. protocol
Time server
Backup time server
Ping every 35 minutes without comms
IP address to ping
All phone numbers are authorized
IP sent to phone which called or “on” SM
IP sent to phone which called or “on” SM
Remote AT commands by SMS enabled
Modem response to AT command with SMS
Any IP will be able to connect to the modem
Telnet is activated
Telnet login
Telnet password
Telnet port 20023
We enable the MTX Logger, to store the records
Password field can be used as ID device
Server URL, will receive JSON data
Register size
Maximum number of records in MTX
HTTP GET (JSON) mode
ModBus equipment address
ModBus register address to be read
Number of registers read
Timing -seconds- read is repeated
Reading command

Details:

  • The summary of this example is: the modem reads the Modbus records of every meter periodically, every 15 minutes, and sends them through a JSON object to a web server (to the URL specified in LOGGER_server). In cases where it is not possible to send the records (because there is no GPRS coverage at that moment or because the server is down) it stores the data in the memory to send them later. It is possible to connect to the device directly via Telnet and check/ change the PLC records in real time (to do so please check the AT^MTXTunnel=getmodbus y AT^MTXTUNNEL=setmodbus commands set out in this manual)
  • From version MTX-Tunnel v7.18 it is possible to read a different memory map for each device, as follows:
    • MODBUS_address: 1;1;2;3;4;5
    • Here the address of each meter is specified separately, using ‘;’ (semicolon). Notice that meter 1 is duplicated. The reason is that it is treated as if it were 2 different devices (two readings must be made) because 2 ranges of different records must be read, from 20-21 and 100-105.
    • MODBUS_start: 20;100;30;30;40;40
    • The first record to be read is indicated for each meter. Notice that, as in the previous case, meter 1 is treated as two different meters, and the initial record of the initial registration of each range is as indicated (20 and 100)
    • MODBUS_numwords: 2;6;6;6;21;21
    • The number of records to be read for each meter is specified. It shows, for meter 1, the number of records to be read (2 records) for the first range, and for the second (6 records).
  • The JSON object sent to the URL specified in LOGGER_server is codified as in this example:
{“IMEI”:353234028103206,”P”:”ID00001”,”TYPE”:”MODB”,”A”:1,”TS”:”20/04/13 08:31:44”,”ST”:20, “V1”:23,”V2”:275}

That is, the web server receives a JSON object with the modem’s IMEI, a password field (P) that can also be used to identify the device (if you don’t want to use the IMEI), the modbus address of the meter (A) which will be used to identify which meter the reading belongs to, the time stamp (TS) of when the modbus data of each meter has been read, and V1,V2 with the records read.

Notice that from version MTX-Tunnel 7.18, the field ST (start), where the number of the first record to be read is specified, appears in the JSON object. Thanks to this, you will be able to tell which records they are when making 2 readings of the same device (for example if there are different ranges of records to read).

You can quickly know the number of the record that has been read. If you want to know which record belongs to where, use Vx, NumReg= ST+x-1. For example V2, the case of the previous JSON: numReg=20+2-1 = 21