TRB145 Modbus Master to MQTT

Hi I am trying to get Modbus RTU data (TRB145 should work as Modbus serial master) and the send to a MQTT-Broker.

I was able to configure ( Period 10, Timeout 5) and see RS485 modbus data (request from TRB145 and answer from the device):

[16:34:23.536] request:01 04 88 BE 00 02 3A 4F Answer: 01 04 04 00 00 BC 38 8A 96
[16:34:28.543] 01 04 88 BE 00 02 3A 4F 01 04 04 00 00 BC 35 4B 53
[16:34:33.548] 01 04 88 BB 00 02 2A 4E 01 04 04 00 00 41 4B 8B E3
[16:34:53.567] 01 04 88 BB 00 02 2A 4E 01 04 04 00 00 41 4B 8B E3
[16:34:58.572] 01 04 88 BB 00 02 2A 4E 01 04 04 00 00 41 4B 8B E3
[16:35:03.580] 01 04 88 BE 00 02 3A 4F 01 04 04 00 00 BC 3A 0B 57

But the test function “REQUEST CONFIGURATION TESTING” in “MODBUS SLAVE DEVICE CONFIGURATION” will not work, error message:

“Failed to send test request, daemon is down”

Why the TRBG145 doesn’t seem to understand the data from the Modbus slave ?

How to send the Modbus data to a MQTT-Broker ?

Hello,

First, when you configure Modbus Master, make sure you save&apply all of the settings first, and then open the configurations again to use the ‘test’ button.

Secondly, could you please check if you get a response when you send a modbus request from CLI (make sure to change values appropriately)? Command line instructions here (in CLI, username is root).

ubus call modbus_master serial.test '{"id":5,"timeout":5,"function":3,"first_reg":4006,"reg_count":"1","data_type":"16bit_int_hi_first","no_brackets":1,"serial_type":"/dev/rs485","baudrate":9600,"databits":8,"stopbits":1,"parity":"None","flowctrl":"None"}'

Kind Regards,

Hello0,

i use the “save&Apply” button more than 100 times.

Request over CLI:
root@Teltonika-TRB145:~# ubus call modbus_master serial.test '{“id”:5,“timeou
root@Teltonika-TRB145:~#
t”:5,“function”:3,“first_reg”:4006,“reg_count”:“1”,“data_type”:“16bit_int_hi_
t”:5,“function”:3,“first_reg”:4006,“reg_count”:“1”,“data_type”:“16bit_int_hi_
first”,“no_brackets”:1,“serial_type”:“/dev/rs485”,“baudrate”:9600,“databits”:
8,“stopbits”:1,“parity”:“None”,“flowctrl”:“None”}‘ubus call modbus_master ser
8,“stopbits”:1,“parity”:“None”,“flowctrl”:“None”}’
{
“error”: 0,
“result”: “Failed to create mb context”
}
root@Teltonika-TRB145:~#
root@Teltonika-TRB145:~# ubus call modbus_master serial.test '{“id”:1,"timeou

t":5,“function”:4,“first_reg”:35007,“reg_count”:“2”,“data_type”:"16bit_int_hi

_first",“no_brackets”:1,“serial_type”:“/dev/rs485”,“baudrate”:9600,“databits”

:8,“stopbits”:1,“parity”:“None”,“flowctrl”:“None”}’
{
“error”: 0,
“result”: “Failed to create mb context”
}

Kind Regards

Hello,

The CLI returns an error because some information within the command is wrong. Could you please double-check that all variables with the command are correct? Also, try different addresses (first_reg) like 5, 7, 10, etc.

Also, is it possible that you are trying to use test button from Modbus TCP Master configuration instead of Serial Master?

There are no known issues with Modbus service. Sometimes this error can occur when the serial is incorrectly connected. Thus, check that it is properly connected to TRB.

If the issue continues, you can try is restoring the device to factory defaults in System → Backup.

Additionally, I suggest trying to simulate the connection following our example here to see if everything works. This would help us to narrow down the issue.

You can use ‘Data to Server’ functionality to send collected Modbus data to the server over HTTP or MQTT. More information about this functionality is available here.

Kind Regards,

Hello,

I will end this case with a negative result.

Nothing works, even after factory defaults , everytime when I use the test function the error message:

“Failed to send test request, daemon is down”

Regards

Hello,

Would it be possible for you to show screenshots of your configurations?

Also, it would be great if you could share some of the system logs from System → Administration → Troubleshoot → ‘View’ system logs. If something is potentially wrong with the device, the logs might provide some insight into the issue at hand.

Kind Regards,

Hello, this system allows me not to upload a log. The Kernel log is to great, to send it directly.

“Sorry, new users can not upload attachments.”

Hello,

Unfortunately, there is no way for us to share files privately. Please, post screenshots of your configurations.

Also, I made a mistake when I provided you with a CLI command. The value for parity and flowctrl ‘None’ should be written in lowercase ‘none’. Apologies. Let me know if the command works.

Kind Regards,

Hello,

CLI command do not work (no anwer after 1 Minute), but I see the configurated Master-Request and Slave-Answer is correct (over additional serial interface).

root@TRB145:~# ubus call modbus_master serial.test ‘{“id”:5,“timeout”:5,“function”:3,“first_reg”:4006,“reg_count”:“1”
,“data_type”:“16bit_int_hi_first”,“no_brackets”:1,“serial_type”:“/dev/rs485”,“baudrate”:9600,“databits”:8,“stopbits”:
1,“parity”:“none”,“flowctrl”:“none”}’
^C
root@TRB145:~# ubus call modbus_master serial.test ‘{“id”:1,“timeout”:5,“function”:4,“first_reg”:35007,“reg_count”:“1
“,“data_type”:“16bit_int_hi_first”,“no_brackets”:1,“serial_type”:”/dev/rs485”,“baudrate”:9600,“databits”:8,“stopbits”
:1,“parity”:“none”,“flowctrl”:“none”}’
^C
root@TRB145:~#

Slave device configuration:

Hello,

Would it be possible for you to describe the process of how you check if the serial link works?

The ubus command without increased timeout should timeout within 30 seconds or so. Since the timeout in the request is set to 5, it should timeout even earlier. Are you sure it hangs for 1 minute?

How is the RS485 wired? If its half duplex, could you please check this post here?

Also, if possible, can you try to test it with a different serial cable?

Kind Regards.

Hello,

the ubus command seams to be never ends (I wait over 15 Minutes), but I found my error:
I forgot the neccesary bridges for RS485 halfduplex between D+/R+ and D-/R- at the connector of the TRB145. Your quickstart-manual should be give a advice for this.
Normally we and other manufacturers use only the pins D+/D-/Gnd for RS485 half-duplex, and T+/T-/R+/R-/Gnd for RS485 full-duplex.
After using the bridges the test-function and the ubus command work as expected.
This case can therefore closed.
Thanks for your efforts.

Regards

1 Like

This topic was automatically closed after 15 days. New replies are no longer allowed.