Suchen Sie etwas anderes?
Scenario details:
- We have a PLC Modbus RTU, in its internal memory a series of variables/registries (for instance una temperature, 3 meter boxes, etc.) which must be read and sent periodically to a webserver
- To do that the MTX modem must ask periodically, every minute, for a serial port to the PLC to read those registries. Registries to be read are, for temperature the registry number 20, and the meter boxes are in the registries 21, 22 and 23 respectively
- Also, the MTX modem must connect to an MQTT platform and send the modbus registries read
- The MTX modem can also send information about its status every 15 minutes (information about its IP, coverage, technology used (2G/3G/4G), etc.) to the MQTT platform
- We need to be able to send AT commands to the modem via MQTT in order to change the configuration, remote reset, etc. We also want to be able to send AT commands from a cell phone via MQTT
Solution: MTX-Tunnel firmware + MTX-Java-IoT/MTX-Java-T/MTX-Java-T2
EXAMPLE of configuration (config.txt file):
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: 199801436 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 MTX_rssiLevel: 10 SMS_allPhones: on SMS_sendIP: on SMS_ATEnabled: on SMS_ATResponse: on FIREWALL_enabled: off LOGGER_enabled: on LOGGER_registerSize: 300 LOGGER_numRegistersFlash: 1500 LOGGER_mode: mqtt LOGGER_mqttTopic: [IMEI]/logger MQTT_enabled: on MQTT_server: tcp://test.mosquitto.org:1883 MQTT_id: [IMEI] MQTT_login: MQTT_password: MQTT_attopic1: [IMEI]/AT MQTT_atrtopic: [IMEI]/ATR MQTT_qos: 1 MQTT_keepalive: 60 MQTT_persistent: off MODBUS_address: 1 MODBUS_start: 20 MODBUS_numwords: 4 MODBUS_readCommand: 3 MODBUS_period: 60 DNS_enabled: on DNS_mode: mqtt DNS_mqttTopic: [IMEI]/dns DNS_extended: on DNS_period: 30 |
Data rate of communication of serial port Number of bits CTS Hardware flow control deactivated RTS Hardware flow control deactivated 1 stop bit No parity APN GPRS provided by the GSM operator GPRS Login GPRS Password Modem is always GPRS connected SIM Card PIN No gateways Modem is configured as TCP server AUXILIAR COM port used as master modbus Time synch. protocol Time server (the MTX must sync the time) Backup time server Ping time to oversee connection Google IP (f.e.) to ping AWe activate the MTX-65i coverage led IP by SMS authorized SMS AT responses activated IP by SMS authorized AT by SMS allowed Firewall disabled Logger enabled Max. size of MTX internal registries Max. number of MTX internal registries MQTT sending mode Sending topic of internal datalogger data MQTT enabled Broker MQTT to be used Identification of the equipment in the broker No username No password MTX topic to receive AT commands Topic where MTX sends answers to commands QoS established 60 seconds keepalive No persistence Modbus address of the equipment to be read Address of the initial modbus registry to be read Number of registries to be read from the initial Reading command A reading is made every 60 seconds Status data sending activated MQTT sending mode Topic where status data will be sent to Sending extended data (I/O, ADCs, etc.) Every 30 seconds a sending will be made |
Details:
- The modem reads every 15 minutes the modbus registries of the PLC and sends them via JSON to an MQTT broker (for this test we use a free one: test.mosquitto.org). MTX sends datalogger (where modbus registries read are internally stored) data to MQTT broker, especifically to the topic [IMEI]/logger (MTX substitues the tag [IMEI] for the real IMEI). In case of being unable to send the registrie (no coverage or broker down) it stores the data in its memory to send them later
- It is also possible to send AT commands to the modem via MQTT from a cell phone. To do that, the MTX modem subscribes to the topic indicated in the parameter MQTT_attopic1. All the AT commands sent from a cell phone or any other device to said topic will be received and executed by the modem
- Remember you can specify 3 topics to receive AT commands: MQTT_attopic1, MQTT_attopic2, MQTT_attopic3. For example, we can configure MQTT_attopic1 to receive AT commands exclusively in that modem, MQTT_attopic2 for a several modems, and MQTT_attopic3 for all the modems
- The JSON object sent to the topic LOGGER_mqttTopic is coded like in the following example:
{“IMEI”:353234028103206,”P”:””,”TYPE”:”MODB”,”A”:1,”TS”:”20/08/12 08:31:44”,”ST”:20,”V1”:23,”V2”:275,”V3”:274,”V4”:32765}
That is, the web server receives a JSON object with the modem IMEI, the modbus address of the equipment (A), the time stamp (TS) when modbus data has been read, the initial address read (ST) and V1, V2… with each of the variables read. - To test this example we use the application MyMQTT you can find in Google Play for Android:
https://play.google.com/store/apps/details?id=at.tripwire.mqtt.client
Once installed on our phone, we click on “Settings.”
In the section “Settings” we enter the MQTT broker address, in this case test.mosquitto.org in the port 1883. There is no need to specify user or password, since test.mosquitto.org doesn’t allow it. We do it as shown below and press “Save.”
Next we will subscribe to 3 topcs. We want to see the modbus data send by the MTX modem and it is configured to send it to the topic [IMEI]/logger. In the cell phone app we will subscribe to that topic, specifying the IMEI numerically. You can find the MTX modem IMEI in the sticker on the bottom of the box.
Same for status data, that the modem sends to the topic [IMEI]/dns. The modem also sends answers to AT commands to the topic [IMEI]/ATR, and since we want to see them, we will enter that topic. We have 3 topics, as seen below:
Once these steps are done, if we turn on the MTX modem we will start receiving modbus and DNS data sent by the modem. DNS every 30 seconds, modbus every 2 minutes, as it is configured:
Finally, we will send an AT command to the modem via MQTT from the cell phone to know the GSM coverage (we could send any AT command, for instance to reset, to read the configuration, to change it, to activate a relay, etc.). To do that we go to the menu “Publish” and enter the command as shown below:
Once we press “Publish” the command will be executed on the modem. Since we are subscribed to the answers too, we can see those as well: