Community discussions

MikroTik App
 
kp3928
just joined
Topic Author
Posts: 20
Joined: Tue Jul 06, 2021 3:47 pm

KNOT modbus sniffer to mqtt

Mon May 08, 2023 1:16 am

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/u ... -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
 
denissMT
MikroTik Support
MikroTik Support
Posts: 49
Joined: Wed May 26, 2021 12:00 pm

Re: KNOT modbus sniffer to mqtt

Mon May 15, 2023 1:07 pm

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.
 
scampbell
Trainer
Trainer
Posts: 487
Joined: Thu Jun 22, 2006 5:20 am
Location: Wellington, NZ
Contact:

Re: KNOT modbus sniffer to mqtt

Sat Dec 16, 2023 9:26 pm

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/vi ... aModbusRTU 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"
 
marekm
Member
Member
Posts: 391
Joined: Tue Feb 01, 2011 11:27 pm

Re: KNOT modbus sniffer to mqtt

Sun Dec 17, 2023 3:06 am

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.

Who is online

Users browsing this forum: No registered users and 30 guests