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