KNOT modbus sniffer to mqtt

I am trying to log the traffic between a modbus master ( in this case a Wallbox Pulsar EV charger) that polls a power meter over modbus
(n1-ct , modbus client, https://ineprometering.com/wp-content/uploads/2022/01/N1-CT-Short-user-manual-V1.03.pdf )

I am not that much interested in the master traffic, but I would like to fetch the responses from the client and push these responses to mqtt.

Is there any way to fetch the raw responses of the power measuring device with KNOT acting as a passive listener / man in the middle ?

cc @denissMT

What’s new in 7.10beta5 (2023-May-09 13:38):
*) iot - added option to send Modbus function code commands directly from RouterOS (CLI only);

This means that you can now communicate with the Modbus connected device dirrectly from within RouterOS.
You can script the KNOT to send specific function code commands and store replies (from the Modbus device) as variables. Then, you can send Modbus device’s replies via MQTT further. KNOT can be Modbus “client” now. The guide with examples is on the way (the original Modbus guide will be updated).

This is the only solution/function that is availible as of this moment.

I’m testing a connected Relay Board from Bestep connected via Knot Modbus running on RoS 7.13

I can control the board OK via TCP from Windows QModMaster and have confirmed the Boards ID is 255.

I’m monitoring the Modbus via Oscilloscope to confirm output from the Knot is occuring.

Commands from Qmodbus are sent and relays trigerred as expected.

Following the information on https://help.mikrotik.com/docs/pages/viewpage.action?pageId=61046813#RB924i2nDBT5&BG77Modbusconfiguration-SendingfunctioncodecommandsviaModbusRTU I cannot get the board to respond.

The oscilloscope confirms data is being sent via the Modbus Interface.

Commands sent via RoS CLI on the Knot are transmitted but ignored - all return a “failure:Timeout”


/iot modbus transceive address=255 function=5 data=FF000001
/iot modbus transceive address=255 function=5 value=0xff,0x05,0x00,0x00
/iot modbus transceive address=0xff function=5 value=0xff,0x05,0x00,0x00
/iot modbus transceive address=1 function=5 value=0xff,0x05,0x00,0x00 <-tried a different device ID for fun


and

{:local output [/iot modbus read-holding-registers slave-id=0xff num-regs=0x1 reg-addr=0x0 as-value once];:put [($output->“values”)]}
returns “interrupted; Poll Timout”

Based on QModMaster working via the Knot I conclude communications are working to the device but the Knot is not encoding or decoding the data as expected ?.

Is their a way to log Modbus Output and Input to see what is actually being sent and received ?

I have also tried disabling Modbus interface to see if that might be an issue but then I get a message “Connection Refused”

Could you try to set the board to a different ID instead of 255? MODBUS spec calls for the ID in the range 1-247, perhaps KNOT enforces it and the Windows software doesn’t. And, double check serial port settings are the same on both sides - 2 stop bits, no parity. Also, expect random failures when the last byte of the response frame (2nd byte of CRC) is zero - known bug, already reported and MT working on a fix. Modbus works for me otherwise.