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

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.
Mobdus-TCP_20220608.jpg

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!
Mobdus-TCP_enabled_20220608.jpg

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/viewpage.action?pageId=61046813#heading-ReadingMODBUSdatausingRouterOS

Something like this:

/iot/modbus/read-holding-registers ip=192.168.100.30 port=502 reg-addr=0x0 as-value once

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.

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?

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… :frowning:

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).

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/uploads/products/protocol/SMART_X96-1A_MODBUS_Protocol_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?

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.

What is the official way to create feature requests?

Write to support@mikrotik.com

Any updates on this front?

I got the same goal with OP here although thankfully Schneider usually use FC03 rather than FC04

Also yeah it’s shame Eastron gotta lock their modbus to FC04, weird

I got Eastron SDM72CT-M that I usually use for testing besides Schneider, was planning to use this, sad

Same advise ...