Configuring RUT241 via subscribed mqtt topic

I succesfully managed to connect my RUT241 over the mobile connection to my home mqtt broker. The RUT241 responds to router/get commands i publish on my broker, and ‘data to server’ works to send the mobile data usage from RUT241 to my mqtt broker.
But i was wondering, can i set topics in my mqtt broker to which the RUT241 is subsribed, and let the RUT241 perform actions based on those subscribed topics? i.e. i set a router/output topic to ‘high’, and a script on the RUT241 sets the output to high upon receiving the updated mqtt topic?

@pwhooftman Hello,

I recommend checking out this Modbus MQTT example:
https://wiki.teltonika-networks.com/view/Modbus_TCP_Master_MQTT_Gateway

In this setup, you configure the RUT241 as a Modbus TCP server and then enable the Modbus MQTT Gateway feature. This allows you to send MQTT messages to a specific topic that the RUT is subscribed to. Depending on your commands, the RUT will read from or write to its internal Modbus registers.

For example, if you send an MQTT message to write ‘1’ to register 326, the RUT will receive the command from the subscribed topic, write ‘1’ to register 326, and activate the digital output (DO).

image

A full list of available Modbus registers for RUT241 can be found here:
https://wiki.teltonika-networks.com/view/RUT241_Modbus#Modbus_Registers

Kind Regards,

Thanks AndzejJ , it took me a while to understand that “MODBUS TCP server” is the process that talks directly to the registers of the device, and “MQTT Modbus Gateway” is just a client which connects to a broker and can read/write messages from the broker topics from/to the modbus registers of the device. via the Modbus server.

I have one question left: why is register ‘72’ with a ‘Register count’ 3 used in the examples while the register for the device name is 16 numbers?. If i enter a request
0 65432 0 192.168.1.1 502 5 1 3 72 3
in the topic ‘request’ of my mqtt broker, i expect the name “RUT241” back in ‘response’, just like when i test the Modbus TCP Client, but i get back
65432 OK 21077 21554 13361 in my MQTT broker topic ‘response’, i don’t understand.

@pwhooftman Hello,

Hello,

Regarding the number of registers - it depends on the length of the device name when determining how many Modbus registers are needed. Each register is 16 bits, and since ASCII (extended) characters are 8 bits, each register can store two characters. For the string “RUT241,” which has 6 characters, 3 registers are used.

When it comes to MQTT, the format is not specified (application does not know what to expect), so you see decimal values like 21077, 21554, and 13361. Each of these decimal values can be split into two bytes, and each byte corresponds to a single ASCII character. Converting 21077 gives “RU,” 21554 gives “T2,” and 13361 gives “41.” Below is a short Python snippet that shows how to convert decimal register values to ASCII:

Here’s a short python example:

registers = [21077, 21554, 13361]  # Example 16-bit registers

# Collect ASCII characters
chars = []
for reg in registers:
    high_byte = (reg >> 8) & 0xFF
    low_byte = reg & 0xFF
    chars.append(chr(high_byte))
    chars.append(chr(low_byte))

decoded_string = ''.join(chars)
print(decoded_string)

Image for reference:

Hope this helps!

Kind Regards,

This, together with https://wiki.teltonika-networks.com/view/TRB141_Monitoring_via_Modbus made it work for me, thank you very much.

1 Like

BTW, https://wiki.teltonika-networks.com/view/RUT241_Monitoring_via_Modbus is missing the modbus register adresses for the RUT241 eSIM variant, by looking at the RUT950 Modbus registers i could conclude the registers for reading the tx and rx numbers for SIM2 are in the range 300 -322.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.