Suchen Sie etwas anderes?
Table of Contents
Scenario Details
Titan routers have all the funcionalities a 2G/3G/4G router has, plus a variety of additional features that make it into one of the most functional router in the marketplace.
One of those additional features is the ability of automatically questioning Modbus RTU or TCP devices, and then sending the data to a web, FTP or MQTT server.
As usual, we will illustrate that ability with an easy example.
Creation of IoT Hub in Azure
This example shows how to configure a Titan router to read, collect and send modbus registries from 2 PLCs through HTTP. Those readings will happen every 10 minutes.
The modbus registries to be read fromPLC1 are:
1;10;11;12;55;56;69;70;72;73;74;75;76;77;78;79;80;100;101;102;103;104;105;106;107;108;109; 120;121;122;123;124;130;131;132;133;152;153;154;160;161;162;163;164;165;166;170
The modbus registries to be read from PLC2 are:
10;11;12;13;14
That is, from PLC1 we are getting a diverse registry map, non-consecutive registries sometimes. PLC2 is more simple and we only need 5 consecutive registries.
The PLCs are RS485 devices, so we will use Modbus RTU, but the scenario also applies to Modbus TCP equipment (with Ethernet) or to both kinds of equipment used simultaneously (Modbus TCP and Modbus RTU).
Configuration of the Port where Modbus Devices Connect
Let’s say the PLCs, with a RS485 port, have the serial port configuration: 9600,8,N,1. Then, our first task is to configure the Titan router serial port COM1, since this port can be configured as an RS232 or RS485 port. The next picture shows how to configure the port COM1.
Let’s not forget that in order to activate the BUS RS485 of the MTX-Router-Titan-3G-mini, we need to activate the microswitches indicated in the user guide (turn on n. 3 and 4 for RS485).
Configuring Titan for the Reading of Modbus Devices
We click on the link: “External Devices > Modbus Devices” and configure the screen as shown below:
To read registries 10,11,12,13,14 from PLC2, we specify registry “10” in field “Start” and the number “5” in the “Number Words,” since we want to read 5 registries, from 10 to 14. In PLC1 we will separate the registry blocks with a semicolon (;). That is, if we want to read the following registries:
1;10;11;12;55;56;69;70;72;73;74;75;76;77;78;79;80;100;101;102;103;104;105;106;107;108;109;
120;121;122;123;124;130;131;132;133;152;153;154;160;161;162;163;164;165;166;170
… we will enter the initial registry of each block in the field “Start” like this:
1;10;55;69;72;100;120;130;152;160;170
And the number of registries to be read in each block in the field “Number Words” like this:
1;3;2;2;9;10;5;4;3;7;1
The next step is configuring the Logger, that is, the Titan router system that collects and sends the data. This example explains how to configure the router to send the data to a HTTP server (we could also use HTTP or FTP ones).
Our HTTP server will be the URL https://www.mydomain.com/set.asp?data= where we will receive the data in JSON format of every reading made (timestamp, equipment ID, …) in the variable “data.”
As shown in the next picture, we will access through the menú “External Devices > Logger Configuration” to configure that section like this:
Final Remarks
After configuring the Titan router we need to restart it so it functions with the new configuration and it can start reading and sending data.
Every time the Titan router sends a measurement to an HTTP server, it does it through the following JSON object:
Example JSON PLC2
{TYPE:MODB,ID:2,TS:17/06/2017 17:01:05,IMEI:357044060009633,P:12345678,A:2,ST:10,N:5,V:[10,11,12,0,0]}
Example JSON PLC1
{TYPE:MODB,ID:1,TS:17/06/2017 17:01:04,IMEI:357044060009633,P:12345678,A:1,STX:[1,10,55,69,72,100,120,130,152,160,170],NX:[1,3,2,2,9,10,5,4,3,7,1], PX:[0,1,4,6,8,17,27,32,36,39,46],V:[1,10,11,12,55,56,69,70,72,73,74,75,76,77,78,79,80,100,101,102,103,104,105,106,107,108,109,120,121,122,123,124,130,131,132,133,152,153,154,160,161,162,163,164,165,166,170]}
Where:
TYPE: indicates the kind of data (MODB = Modbus reading)
TS: indicates the Timestamp (that is, the time of the measurement reading)
IMEI: indicates a unique identifier for the modem
P,: in the case of HTTP it indicates the configured ID field
ST: indicates the address of the first registry read
STX: array that indicates the address of the first modbus registries in case a group of registries is read
N: indicates the number of words read
NX: array that indicates the number of words read in case a group of registries is read
PX: array that indicates the position of the initial registry of each block inside V
V: array with the read data
Note there is a significant difference between the data sent by PLC1 and PLC2. PLC1 has groups, thus fields “ST” and “N” are substituted in JSON by “STX” and “NX,” arrays that store the initial registries and registry numbers of each block. Also, the “PX” registry indicates the initial position of the group inside array “V”. In fact, PX is not necessary since it can be calculated, but it is included to facilitate the decoding operation in the server.