Tunnel – Serial Cable replacer RS232-4G-RS232 via MQTT

¿Buscas alguna otra cosa?

Scenario details:

  • There are 2 RS232 devices (115200,8, N, 1) connected by a serial cable through which data is sent. We want to replace the serial cable with a transparent link RS232-4G-RS232
  • None of the devices is a PC. They are computers with hardly any intelligence and their internal control programs can’t be modified. That is, they can be seen as “black boxes” with an RS232 serial port with no possibility of modifying anything, so it will be necessary to use one MTXTunnel on each side of the communication
  • Both modems will use affordable SIM cards that don’t have a public or fixed IP. Therefore, an MQTT broker will be used as an intermediary for communications

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

Config.txt configuration file MTX-Tunnel 1:

Configuration Observations
COMM_baudrate: 115200
COMM_bitsperchar: 8
COMM_autorts: off
COMM_autocts: off
COMM_stopbits: 1
COMM_parity: none
GPRS_apn: movistar.es
GPRS_login: MOVISTAR
GPRS_password: MOVISTAR
GPRS_timeout: 0
MTX_PIN: 0000
MTX_mode: mqtt
MTX_model: MTX-4G-JAVA-T
MTX_ping: 35
MTX_pingIP: 8.8.8.8
MTX_invertedCom: off
MTX_msToSend: 250
SMS_allPhones: on
SMS_sendIP: on
SMS_ATEnabled: on
SMS_ATResponse: on
FIREWALL_enabled: off
MQTT_enabled: on
MQTT_server: tcp://test.mosquitto.org:1883
MQTT_id: [IMEI]
MQTT_attopic1: [IMEI]/AT
MQTT_atrtopic: [IMEI]/ATR
MQTT_keepalive: 300
MQTT_commrxtopic: mtx2
MQTT_commtxtopic: mtx1
Serial port baud rate
8 bit data
RTS hardware control disabled
CTS hardware control disabled
1 stop bit
No parity
GPRS APN from your network operator
GPRS Login
GPRS Password
Value 0 means MTX-Tunnel is always connected
If SIM card has no PIN security, use 0000 value
MQTT serial gateways will be used
MTX terminal modem model used
One ping every 35 min. without communications
Ping address
Gateway port RS485
No fragmented networks
Send SMS with commands from any phone
Modem responds with its IP to a missed call/SMS
Commands can be sent to the MTX by SMS
MTX responds with an SMS to a command SMS
Any incoming connection form any IP is allowed
MQTT service enabled
Broker IP/DNS specified, including identifying port
Identifier
MQTT topic to send AT commands
Topic to send replies to commands to
Connection keep alive (300 seconds)
Data received will be retransmitted via serial
Data received v/serial, retransmitted to this topic

Config.txt configuration file MTX-Tunnel 2:

Configuration Observations
COMM_baudrate: 115200
COMM_bitsperchar: 8
COMM_autorts: off
COMM_autocts: off
COMM_stopbits: 1
COMM_parity: none
GPRS_apn: movistar.es
GPRS_login: MOVISTAR
GPRS_password: MOVISTAR
GPRS_timeout: 0
MTX_PIN: 0000
MTX_mode: mqtt
MTX_model: MTX-4G-JAVA-T
MTX_ping: 35
MTX_pingIP: 8.8.8.8
MTX_invertedCom: off
MTX_msToSend: 250
SMS_allPhones: on
SMS_sendIP: on
SMS_ATEnabled: on
SMS_ATResponse: on
FIREWALL_enabled: off
MQTT_enabled: on
MQTT_server: tcp://test.mosquitto.org:1883
MQTT_id: [IMEI]
MQTT_attopic1: [IMEI]/AT
MQTT_atrtopic: [IMEI]/ATR
MQTT_keepalive: 300
MQTT_commrxtopic: mtx1
MQTT_commtxtopic: mtx2
Serial port baud rate
8 bit data
RTS hardware control disabled
CTS hardware control disabled
1 stop bit
No parity
GPRS APN from your network operator
GPRS Login
GPRS Password
Value 0 means MTX-Tunnel is always connected
If SIM card has no PIN security, use 0000 value
MQTT serial gateways will be used
MTX terminal modem model used
One ping every 35 min. without communications
Ping address
Gateway port RS485
No fragmented networks
Send SMS with commands from any phone
Modem responds with its IP to a missed call/SMS
Commands can be sent to the MTX by SMS
MTX responds with an SMS to a command SMS
Any incoming connection form any IP is allowed
MQTT service enabled
Broker IP/DNS specified, including identifying port
Identifier
MQTT topic to send AT commands
Topic to send replies to commands to
Connection keep alive (300 seconds)
Data received will be retransmitted via serial
Data received v/serial, retransmitted to this topic

Details:

  • The MTX-Tunnel 1 modem forwards the entire data stream it receives on its RS232 serial port to the MQTT broker to the “mtx1” topic. The MTX-Tunnel 2 modem, since it’s subscribed to the “mtx1” topic of the MQTT broker, automatically receives the data stream that it also forwards to its RS232 serial port. And viceversa
  • If instead of using the RS232 port we need to perform an RS485 bridge, we only have to change the parameter MTX_invertedCom to “on”
  • If we need to use secure communications (SSL) between both devices, we can use port 8883, specifying in the broker MQTT_server: ssl: //test.mosquitto.org: 8883. At the end of this manual we will find how to install SSL certificates on computers
  • Keep in mind that communications latencies may be somewhat greater than direct communication latencies since there is an intermediary (the mqtt broker) and the speed of communications will depend on the power of the latter. Set the timeout if necessary