Template:Networking rut2 9 modbus custom register block

From Teltonika Networks Wiki
Revision as of 14:29, 10 September 2020 by Tomas (talk | contribs)

Configuration examples modbus logo.png

Introduction

The goal of this manual is to help configuring Teltonika Networking Devices to get additional custom Modbus registers for device monitoring via Modbus if default registers are not enough. Default Modbus registers can be found on our Wiki page: Monitoring via Modbus

Configuring Teltonika Networking Device

For this example we will be using script to store data into regfile from which then you can read data via Modbus. To achieve follow this steps:

  1. Enable router to be as Modbus TCP slave (Network -> Modbus -> Modbus TCP Slave);
  2. Enable Custom Register Block in the webUI (Network -> Modbus -> Modbus TCP Slave);
    • Register file path: tmp/regfile (this is where new register will be stored);
    • First register number: 1025 (by default it is 1025 and recommend to keep it, if necessary it could be changed accordantly);
    • Register count: 32 (how much "space" there is given for additional Modbus registers, the more register you want to bigger count should be used).

Creating Custom Modbus Registers

In order to create custom Modbus register which would allow you to read certain routers information via Modbus, you will need to create a script or any other method for putting certain information into regfile.

Script which would log certain data into Modbus register. To add new script, connect to the device via SSH and use:

$ vi /bin/extramodbus (where extramodbus here could be any name)

Then press the letter [i] on the keyboard and insert following script (this script is for this manual purpose, yours might be different) example:

#!/bin/ash
while true
do
date > /tmp/regfile  #where data will be stored
gsmctl -X >> /tmp/regfile
gsmctl -E >> /tmp/regfile
sleep 5
done

Now we can try and create a simple script. With following script we will be getting routers date and couple of mobile related data.


After saving change execution rights with this command:

$ chmod +x /bin/<scriptname> #example: chmod +x /bin/extramodbus

Then you need to run your script to start loggin data to regfile, to start script simple write <script name> & example:

$ extramodbus &

And script will run in the background.

With this script we will be able to get routers local time and couple 3G signal values each 5 seconds. Data stored in regfile (cat /tmp/regfile) looks like this:

Wed Jun 17 15:11:29 EEST 2020
-69
27

In HEX #command to view data via SSH: hexdump -v /tmp/regfile

0000000 5765 6420 4a75 6e20 3137 2031 353a 3132	
0000010 3a32 3020 4545 5354 2032 3032 300a 2d36
0000020 380a 3137 0a00
0000025

Reading Created Custom Modbus Registers

To read data via Modbus you can use:

  • ComTestPro program;
  • Modbus TCP Master;

For example purpose we will be using ComTestPro program, which allows us to get Modbus data from device in Hex. So in order to get date from the router by reading custom Modbus registers we need to use following configuration:

  • Protocol: Modbus TCP;
  • IP Address: 192.168.3.1 (routers LAN or WAN IP);
  • Port: 502 (port number on which Modbus TCP Slave is listening);
  • Device: 1
  • Register: 1024 (the register number from which custom Modbus registers are started, keep in mind you need to -1 from the register which you configured in the webUI, for example we used 1025 but here we need to use 1024);
  • Registers: 14 (registers lenght).

With this configuration you should get routers date in hex. Below is the example of configuration and what answer do we get from the router:

Configuration examples modbus comtest pro.png

And as you can see we received answer in hex which is:

5468 7520 4A75 6C20 3330 2031 313A 3539 3A30 3820 5554 4320 3230 3230 

And by using certain websites, like this one: online hex converter and there we can analyze the data, and by entering the received hex we can see the routers date which in ASCII is:

Thu Jul 30 11:59:08 UTC 2020

Configuration examples modbus hex to ascii.png

[[Category:{{{name}}} Configuration Examples]]