Community discussions

MikroTik App
 
turmiola
just joined
Topic Author
Posts: 6
Joined: Wed Jun 08, 2022 10:10 am

IoT: How to read Modbus TCP on hEX (no serial port)

Wed Jun 08, 2022 10:25 am

I want read to Modbus TCP-info from Eastron SMART X96-5 energy meter, which can provide Modbus data over it's ethernet interface.

The end goal is to send that data as MQTT messages.

The Mikrotik platform is:
  • hEX running 7.3 version (stable)
On which I have installed the IoT-package from the extra packages.

When trying to activate the Modbus TCP, it requires also to have some serial-connected device on the Mikrotik.
How would I enable ONLY the Modbus TCP?? See attached screen capture.

Looking into next 7-beta version: iot-7.4beta2.npk has no help on this matter.
You do not have the required permissions to view the files attached to this post.
 
turmiola
just joined
Topic Author
Posts: 6
Joined: Wed Jun 08, 2022 10:10 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Wed Jun 08, 2022 6:20 pm

Oh-la-laa! By going into terminal and disabling (the only serial port on this system (which was a console?)),
by doing this:
(help from here: https://wiki.mikrotik.com/wiki/Serial_Port_Usage )
/system/console/disable 0
/port/set serial0 baud-rate=9600
The Modbus -extension can now be enabled!
You do not have the required permissions to view the files attached to this post.
 
turmiola
just joined
Topic Author
Posts: 6
Joined: Wed Jun 08, 2022 10:10 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Wed Jun 08, 2022 6:32 pm

hmm... then what? I was sort of hoping that on the Modbus component, I could now define a Modbus device from which to read some registers....

I guess some scripting is needed?
Some hint are given here (at the end):
https://help.mikrotik.com/docs/pages/vi ... ngRouterOS

Something like this:
/iot/modbus/read-holding-registers ip=192.168.100.30 port=502 reg-addr=0x0 as-value once
 
tdw
Forum Guru
Forum Guru
Posts: 1841
Joined: Sat May 05, 2018 11:55 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Wed Jun 08, 2022 7:08 pm

I guess some scripting is needed?
No. From the top of the help article "The feature allows KNOT to act as a TCP bridge and read data from Modbus-supported devices connected to a 2-pin terminal block on the board. Modbus clients (slaves) can access the data from the Modbus server (master - KNOT) using the 502/TCP port." It does not say the KNOT implements Modbus client, you can use scripting to to read holding register data from devices attached to the local serial Modbus and publish it with MQTT.
 
turmiola
just joined
Topic Author
Posts: 6
Joined: Wed Jun 08, 2022 10:10 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Wed Jun 08, 2022 7:34 pm

Thanks,

So my smart energy meter already does same thing as this KNOT device.
-> Makes Modbus info available on TCP.

And all I need to do is create some polling script that reads the required value(s) and publishes them through the MQTT?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Wed Jun 08, 2022 8:00 pm

I would have liked to help in the scripting and on the hexadecimal, but unfortunately I don't have the hardware to do the tests... :(
 
tdw
Forum Guru
Forum Guru
Posts: 1841
Joined: Sat May 05, 2018 11:55 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Wed Jun 08, 2022 11:58 pm

There are two separate functions:
A Modbus TCP server to serial port gateway: /iot modbus set which takes parameters disabled, hardware-port, tcp-port, timeout.
A Modbus client: /iot modbus read-holding-registers which takes parameters ip, port, num-regs, reg-addr, slave-id, timeout (plus the usual actions append, as-value, do, duration, file, interval, once, without-paging). The documentation is really poor and incomplete, the final paragraph only mentions num-regs, reg-addr, slave-id parameters for the client.

I suspect that the client defaults to ip=127.0.0.1 port=502 so by default the client uses the internal server as a gateway to issue the requests though a serial port. If this is indeed the case you do not have to set up the server at all, just specify the IP address of your meter. The main issue is that currently only read-holding-registers (function code 3) is implemented, you need read-inpt-registers (function code 4).
 
turmiola
just joined
Topic Author
Posts: 6
Joined: Wed Jun 08, 2022 10:10 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Thu Jun 09, 2022 11:05 am

Yep,

I can't easily find docs for the Eastron Smart X96-5H (that I have), but for X96-1 there is a protocol doc
https://www.eastroneurope.com/images/up ... l_v1.0.pdf

And indeed the interesting data seems to be in: Input Registers,Function Code 04
> 30049 'Sum of line currents'

So, using the
iot/modbus/read-holding-registers
is not good enough...

One would need to create some raw TCP connect from the Mikrotik and somehow interpret the response?

Any idea if Mikrotik will start supporting reading the input registers as well?
 
tdw
Forum Guru
Forum Guru
Posts: 1841
Joined: Sat May 05, 2018 11:55 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Thu Jun 09, 2022 1:28 pm

There is no mechanism to open a TCP connection and send arbitrary data on Mikrotiks.

Implementing only read-holding-registers is an odd choice as these are typically device outputs or settings, if only a single Modbus command was going to be implemented read-input-registers would have been a better choice as these are typically device inputs or accumulated measurements.

Other than submitting a feature request there isn't much you can do.
 
turmiola
just joined
Topic Author
Posts: 6
Joined: Wed Jun 08, 2022 10:10 am

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Thu Jun 09, 2022 3:10 pm

What is the official way to create feature requests?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: IoT: How to read Modbus TCP on hEX (no serial port)

Thu Jun 09, 2022 3:11 pm

Who is online

Users browsing this forum: No registered users and 11 guests