Example 1. Modbus datalogger to send data to WebServer

 

Details of the example scenario:

  • We have a PLC Modbus RTU which has a series of variables/records (for example, temperature/meters) in its internal memory which must be read and sent periodically to a Web server.
  • Because of this, the MTX-Tunnel must request from the PLC, via a serial port, that these records be read every 15 minutes. These records are: for the temperature record number 20, and the meters are in the records 21, 22 and 23 respectively.
  • The MTX-Tunnel must send the value of the records to a Web server via HTTP GET using a JSON object after each reading; however, it must be able to store up to 1500 readings in flash memory in case of a GPRS communication failure, and these will be sent when communications are restored.
  • The MTX-Tunnel must be accessible at all times to be able to read the records of the PLC in real time, as well as to write in them and modify the configuration of the PLC.

Proposed solution using MTX-65i and MTX-Tunnel.

Datalogger modbus gprs

Configuration files for the MTX-Tunnel for the proposed solution:

This configuration is what must be inputted in the configuration file of the modem to be able to carry out the implementation described in the scenario.

 

 COMM2_baudrate: 9600 Speed of the serial communication port with the PLC
 COMM2_bitsperchar: 8 Number of data bits
 COMM2_autorts: off No flow control
 COMM2_autocts: off No flow control
 COMM2_stopbits: 1 Configure 1 stop bit
 COMM2_parity: none No parity bit
 
 GPRS_apn: movistar.es APN GPRS provided by the GSM operator
 GPRS_login: MOVISTAR Login GPRS provided by the GSM operator
 GPRS_password: MOVISTAR GPRS password provided by the GSM operator
 GPRS_timeout: 0 The modem will be permanently connected
 
 MTX_PIN: 0000 The SIM card’s PIN number
 MTX_mode: none Serial GPRS Gateway mode. Set to “none” as they are not used
 MTX_model: MTX65i MTX65i model where MTXTunnel is installed
 MTX_portAux: modbusmaster Aux port to be used as Modbus master
 MTX_TPServer: time-a.timefreq.bldrdoc.gov Time server (MTX must synchronize the time)
 MTX_TPServer2: ptbtime1.ptb.de Backup server time
 MTX_ping: 35 Ping will be sent every 35 minutes when there is no connection
 MTX_pingIP: 8.8.8.8 Address where the ping is sent
 MTX_radioBand: europe Not necessary. “Europe” indicated if MTX is installed in Europe
 MTX_rssiLevel: 10 LED to show network coverage of MTX-65i is activated
 
 SMS_allPhones: on SMS can be sent using commands from any mobile phone
 SMS_sendIP: on The modem will respond with its IP via a missed call or SMS
 SMS_ATEnabled: on Commands can be sent to MTX via SMS
 SMS_ATResponse: on MTX will respond with an SMS to commands sent via SMS
 
 FIREWALL_enabled: off Connections to the modem (via Telnet) can be made from any IP
 
 TELNET_enabled: on Set up Telnet on the modem
 TELNET_login: user Login for Telnet
 TELNET_password: 1234 Password for Telnet
 TELNET_firewall: off Connections via Telnet to MTX can be made from any IP
 
 LOGGER_enabled: on Activation of Logger of MTX to store readings
 LOGGER_password: ID00001 Field that will allow us to identify where the connections come from
 LOGGER_server: www.miservidorWeb.com/json.asp?data= URL where the JSON with data will be sent
 LOGGER_registerSize: 300 Size of the internal register of MTX
  LOGGER_numRegistersFlash: 1500 The maximum number of records inside MTX
 
 MODBUS_address: 1 Modbus address of the device to be read
 MODBUS_start: 20 Address of the first Modbus record to be read
 MODBUS_numwords: 4 Number of records to be read after the first
 MODBUS_period: 900 MODBUS_period: 900

 

Details:

  • In this example a MTX-65i with RS232 communication is used for MODBUS communication against a PLC, although it could easily be an RS485 without problem. In this case, a MTX-65i-RS485 model could be used (with incorporated RS485 communications).
  • A summary of this example is as follows: the modem periodically (every 15 minutes) reads a series of ModBus records from the PLC and sends them via a JSON object to a Web server (at the URL specified in the LOGGER_server parameter). If the record cannot be sent (due to there being no GPRS coverage or because of a down server), the data is stored in memory to be sent later. Through Telnet it is possible to connect directly to the device and consult/change the PLC’s records in real time (for this, search for the commands AT^MTXTunnel=getmodbus and AT^MTXTUNNEL=setmodbus in this manual).
  • The JSON object sent to the URL specified in LOGGER_server is encrypted in the following way: {“IMEI”:353234028103206,“P”:“ID00001”,“A”:1,“TS”:“20/08/12 08:31:44”,“V1”:23,“V2”:275,“V3”:274,“V4”:32765}

This means that the Web server receives a JSON object with the IMEI of the modem, a password field (P) that can also be used to identify the device (if you do not want to use the IMEI), the device’s Modbus address (A),the timestamp (TS) of when the Modbus data was read, and V1, V2, etc.