Tunnel – Writing to Modbus RTU devices based on the digital and analog inputs of the modem.

¿Buscas alguna otra cosa?

Scenario details:

  • 2 sensors need to be monitored. An analog 0-10V sensor and a digital dry contact sensor
  • The modem has 2 PLCs with Modbus RTU support connected to its RS485 port. One has the Modbus RTU @ 1 address and the other has the Modbus RTU @ 2 address.
  • When changing the state of the dry contact sensor, which is connected to a digital input of the modem, the modem must write a value “1” in register 10 of the PLC @ 1 and PLC @ 2 in case the input and a “0” in case input is disabled
  • When the analog sensor has a value> = 5000mV, the modem will write to register 20 of PLC @ 1 and PLC @ 2 a value of “2”. In case the analog input is <= 1000mV it will write a “0” in both registers and otherwise (between 1000mV and 5000mV) it will write a “1” in the Modbus registers of both PLCs
  • In each digital event, the value of the digital and analog input must be sent to the MQTT broker

Solution: MTX-Tunnel firmware + MTX-IoT-S [4-N]

Configuration example (config.txt file) for the indicated scenario:

Configuration Observations
GPRS_apn: movistar.es
GPRS_login: MOVISTAR
GPRS_password: MOVISTAR
GPRS_timeout: 0
MTX_pin: 0000
MTX_model: 199802407
MTX_ping: 30
MTX_pingIP: 8.8.8.8
MTX_numGSMErrors: 180
MTX_TPProtocol: ntp
MTX_TPServer: ntp.roa.es
MTX_TPServer2: es.pool.ntp.org
MTX_TPFormat: unix
SMS_allPhones: on
SMS_sendIP: on
SMS_ATEnabled: on
SMS_allPhones: on
MQTT_enabled: on
MQTT_server: tcp://broker.mqttdashboard.com:1883
MQTT_id: [IMEI]
MQTT_login:
MQTT_password:
MQTT_attopic1: [IMEI]/AT
MQTT_atrtopic: [IMEI]/ATR
MQTT_qos: 1
MQTT_keepalive: 60
GPIO_mode0: input
GPIO_config0: at;AT^MTXTUNNEL=EXECUTE,digitalon.txt;AT^MTXTUNNEL=EXECUTE, digitaloff.txt
ADC_mode0: voltage
ADC_config0: at;1000;5000;100;AT^ MTXTUNNEL=EXECUTE,analoglow.txt; AT^MTXTUNNEL=EXECUTE,analoghigh.txt;AT^MTXTUNNEL=EXECUTE, analognormal.txt 
GPRS APN provided by GSM operator
GPRS Login
GPRS Password
Modem is permanently connected to GPRS
PIN if it has one
Device model
Every 30 minutes PING check
Google IP (f.e.) to ping
Reset if no registry on GSM network in 1800 secs.
Time synch protocol
Time server
Time server backup
Unix time format
IP by SMS authorized
IP by SMS authorized
AT by SMS allowed
SMS AT responses activated
MQTT service
MQTT broker, format protocol://url:port
Device ID in broker
Username
Password
MTX topic to recieve AT commands
Topic where MTX sends responses to AT commands
QoS established
Keepalive
GPIO0 configured as an input
GPIO0 AT configuration
ADC0 as voltage input

Details

  • The configuration of the digital GPIO0 (where it is connected to the dry meter sensor) as “at; AT ^ MTXTUNNEL = EXECUTE, digitalon.txt; AT ^ MTXTUNNEL = EXECUTE, digitaloff.txt” indicates the following. Remember that all parameters are separated by semicolons ;
    “At”> The input is configured to execute an AT command every time it changes state
    “AT ^ MTXTUNNEL = EXECUTE, digitalon.txt”> The second parameter indicates the AT command that will be executed when the digital input is activated. In this case, the AT command script file is located in /atscripts/digitalon.txt
    “AT ^ MTXTUNNEL = EXECUTE, digitaloff.txt”> The third parameter indicates the AT command to be executed when the digital input is deactivated. In this case, the AT command script file is located in /atscripts/digitaloff.txt
    The file “digitalon.txt” will have the following content

    The file “digitaloff.txt” will have the following content
    The first two lines of this file write in register 10 of the PLCs with address @ 1 and address @ 2 a value of “1” in the first case (when the input is activated) and a “0” in the second case (when input is disabled).
    The third line in both files executes an AT command that allows an MQTT message to be sent to the broker. NOTE that MTX-Tunnel substitutes the tags [GPIOx], [ADCx] and [COUNTERx] for ANY COMMAND AT with their corresponding values. In this case a JSON with the value of GPIO0 and current ADC0 is sent to the MQTT broker.
  • The configuration of the analog ADC0 (where it is connected to the 0-10V analog sensor) as “at; 1000; 5000; 100; AT ^ MTXTUNNEL = EXECUTE, analoglow.txt; AT ^ MTXTUNNEL = EXECUTE, analoghigh.txt; AT ^ MTXTUNNEL = EXECUTE, analognormal.txt ”indicates the following. Remember that all parameters are separated by semicolons;
    “At”> The input is configured to execute an AT command when a certain condition occurs
    “1000”> Minimum value from which the AT command of minimum value reached will be executed. In this case 1000mV
    “5000”> Maximum value from which the AT command of maximum value reached will be executed. In this case 5000mV
    “100”> Hysteresis. 100mV
    “AT ^ MTXTUNNEL = EXECUTE, analoglow.txt”> AT command to be executed when the analog input is less than or equal to 1000mV. In this case, the AT command script file is run in /atscripts/analoglow.txt
    “AT ^ MTXTUNNEL = EXECUTE, analoghigh.txt”> AT command to be executed when the analog input is greater than or equal to 5000mV. In this case, the AT command script file is located in /atscripts/analoghigh.txt
    “AT ^ MTXTUNNEL = EXECUTE, analognormal.txt”> AT command to be executed when the analog input returns to a normal state between 1000V and 5000mV. In this case, the AT command script file is located in /atscripts/analognormal.txt
    The file “analoglow.txt” will have the following content
    The file “analoghigh.txt” will have the following content

    El fichero “analognormal.txt” tendrá el siguiente contenido
    These files write in register 20 of the PLCs with address @ 1 and address @ 2 a value of “2”, “0” or “1” according to the statement in this example
  • Note that MTX-Tunnel substitutes the tags [GPIOx], [ADCx] and [COUNTERx] for ANY COMMAND AT with their corresponding values. For example, the current value of the sensor connected to the ADC0 could be written to the PLCs @ 1 and @ 2. To do this, simply replace the value to write with the tag [ADC0], as shown in the following file: