FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
574 views 4 comments
by anonymous

Hi there,

I have connected a TRB145 to Losant using the MQTT broker from the TRB145 with the bridge option. I'm now trying to use the MQTT gateway to transfer Modbus data both ways:

Using the request example from here https://wiki.teltonika-networks.com/view/TRB145_Modbus#MQTT_Gateway to retrieve uptime, I get an "Invalid request" response:

What should the payload look like for my request?

Cheers

Jules

1 Answer

0 votes
by anonymous

Hi, how are you issuing the requests?

I've tested with RUT140 and getting data via modbus TCP from RUTX11. Unfortunatelly I don't have a Serial device to test in the exactly way you want to do it.

Nevertheless, I used these commands and works as expected.

I got the RUTX11 reference from here

To get:

Required Value Register Address Register Number Number Of Registers Representation
System uptime 1 2 2 32 bit unsigned integer
Mobile signal strength (RSSI in dBm) 3 4 2 32 bit integer
Router name 71 72 16 Text

I've used:

  • mosquitto_pub -h 192.168.1.50 -t request -m "0 1 0 192.168.1.60 502 3 1 3 72 3"
  • mosquitto_pub -h 192.168.1.50 -t request -m "0 2 0 192.168.1.60 502 3 1 3 2 2"
  • mosquitto_pub -h 192.168.1.50 -t request -m "0 3 0 192.168.1.60 502 3 1 3 4 2"

The syntax is this one:

0 <COOKIE> <IP_TYPE> <IP> <PORT> <TIMEOUT> <SLAVE_ID> <MODBUS_FUNCTION> <REGISTER_NUMBER> <REGISTER_COUNT/VALUE>

Using the Router name request as example:

0 - Textual format (For now only 0 implemented)

1 - Cookie (It's the request ID, if you'll develop a software to manage your requests can use an auto-increment value)

0 - IPV4 uses 0 option

192.168.1.60 - Modbus slave IP

502 - Timeout

3 - Modbus request type (3 for read holding requests)

1 - Modbus Slave ID

3 - Modbus request type (3 for read holding requests)

72 - First register you will read

3 - Register count (Quantity of registers you will get/write in your request)

Remember that all the data is shown in decimal, texts for example should be translated to ASCII

If you have further doubts, please let me know.

Regards.

by anonymous

Thanks for your answer.

I'm issuing the request from LOSANT. I have done it the way you presented it in your answer and it worked, but that's not how I need to do it.

I think that the MQTT configuration is correct as I'm receiving a response from the gateway. I'm not sure but I assume that the problem comes the request payload, which looks like this:

Note that I do send the request message following what you mentioned in your response: "0 65432 0 192.168.2.1 502 3 1 3 2 2"

Here is the response I get:

Any idea how I should adjust the request payload?

Cheers

Jules

by anonymous

Hi,

I never used Losant, but I've tried with MQTTlens and worked as expected.

Are you sending the " " in your request? if so, please use only numbers. 0 65432 0 192.168.2.1 502 3 1 3 2 2

Remember that each device, brand working as slave has its own modbus table. You'll need to check your slave device table to know which data you can get from it.

Also, Please take a look to json structure working with mqqt packages.

Regards

by anonymous
Thanks for your reply,

I have tried it with MQTT lens successfully too.

The message is sent as a string and I can't see how I can make this a number, considering the device lan IP address only... Would it be possible that the device doesn't like the fact that I'm sending an JSON object with keys and values?
by anonymous
Hi,

Unfortunately I can't help you with this case, due I don't have big knwoledge with JSON packages and how to edit/perform its format neither Losant platform.

Probably contacting Losant support will be a good one to check their options and solutions.

Regards.