Tunnel – Access the RS232/RS485 serial port of a device via MQTT (for serial RAW data management). Transparent catwalk “RS232/485 – MQTT”

¿Buscas alguna otra cosa?

Scenario details:

  • There is a vending machine with an RS232 serial port. We want to connect the RS232 serial port of the vending machine directly to an MQTT platform, where the communications protocol will be implemented. When the reading protocol of the vending machine is implemented in the MQTT platform, the modem must behave as a “transparent RS232-MQTT gateway,” providing the MQTT platform access to the machine’s data bus in RAW format
  • The modem must be able to be managed from the platform, being able to change its configuration remotely at any time via MQTT. The modem must also inform periodically about its status (coverage, technology used, …)
  • The modem must immediately inform the MQTT platform when it detects a change in one of its digital inputs, which will be connected to the open door sensor of the machine

Solution: MTX-Tunnel firmware + MTX-Java-IoT/MTX-Java-T/MTX-Java-T2 EXAMPLE of configuration (config.txt file) for the indicated scenario. Solution for quick communication via Socket TCP:

Configuration Observations

COMM_baudrate: 9600
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-IOT-STD-N
MTX_ping: 35
MTX_pingIP: 8.8.8.8
MTX_invertedCom: off
MTX_msToSend: 100
MTX_ATLimited: off
MTX_TPProtocol: ntp
MTX_TPServer: ntp.roa.es
MTX_TPServer2: es.pool.ntp.org
SMS_allPhones: off
SMS_sendIP: off
SMS_ATEnabled: on
SMS_ATResponse: on
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: [IMEI]/rx
MQTT_commtxtopic: [IMEI]/tx
DNS_enabled: on
DNS_mode: mqtt
DNS_mqttTopic: [IMEI]/dns
DNS_extended: off
DNS_period: 300
LOGGER_enabled: on
LOGGER_registerSize: 300
LOGGER_numRegistersFlash: 1500
LOGGER_mode: mqtt
LOGGER_mqttTopic: [IMEI]/logger LOGGER_ioEvent: on

Serial port baud rate
8 bit data
No flow control
No flow control
1 stop bit
No parity
APN GPRS provided by the GSM operator
GPRS Login
GPRS Password
Permanent 3G session
The SIM card PIN (if there is any)
MQTT serial gateways will be used
MTX modem model being used
One ping every 35 min. without communications
Ping address
Gateway port RS485
No fragmented networks
No limitations to AT commands
Time synch protocol
Time server
Backup time server
Send SMS with commands from any phone
Modem won’t respond IP to a missed call/SMS
Commands can be sent to the MTX by SMS
MTX responds with an SMS to a command SMS
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
Status data sending activated
Sending mode MQTT
Topic where status data will be sent
Extended data not sent (E/S, ADCs…)
Every 300 secs. (5 mins.) there’s a sending
Logger activated
Size of the record
Number of records in flash storage
Sending mode MQTT
Sending topic to MQTT broker of the data
Changes in digital inputs automatically sent

Details:

  • A transparent RS232-MQTT gateway allows to exchange raw data between the MQTT broker (or another application connected to the MQTT broker) and the machine connected to the RS232 port of the modem. All data the modem receives through its RS232 serial port will be forwarded via MQTT to the broker’s topic specified in the “MQTT_commtxtopic” parameter, and viceversa
  • If, instead of specifying an RS232-MQTT gateway, we need an RS485-MQTT gateway (and the MTX modem has an RS485 port), we only need to set the “MTX_invertedCom: on” parameter in the configuration file
  • 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
  • In addition, the modem will send its status periodically (every 300 sec) to the MQTT broker (in a JSON object) to the topic configured in the “DNS_mqtttopic” parameter. Similarly, each time there is a change in one of the digital inputs, the modem will send a JSON with the changes to the topic configured in the “LOGGER_mqtttopic” parameter