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
314 views 4 comments
by anonymous
I thought MQTT is report by exception. When I read the Teltonika MQTT tutorial, I have to send a "get" command to the broker every time I want a particular value. Shouldn't I simply subscribe to the broker, and the value, say the uptime, will be pushed to my subscriber every time it changes?

1 Answer

0 votes
by anonymous

Hello,

  

It can be configured both ways.

The way you are looking for can be achieved by using Modbus TCP Slave → Modbus TCP Master → Data to Server flow.

  • Modbus TCP Slave
    • Navigate to Services → Modbus → Modbus TCP Slave;
    • Enable the instance;
    • Change the port and ID if needed;
  • Modbus TCP Master
    • Navigate to Services → Modbus → Modbus TCP Master;
    • Create a new instance;
    • Specify the IP as 127.0.0.1, the port and ID will be the same as in the Slave configuration;
    • Specify the period how often you would like the data to be read from the device (not sent);
    • In the request configuration, specify the parameters you would like to read. Their Register numbers, lengths, and data types can be found on this page (use the second column - Register Number);
    • Once all of the requests are configured, press Save & Apply and re-open the instance.
    • Now you can test if the registers are being read correctly by selecting the needed register and pressing the Test button;
  • Data to Server
    • Navigate to Services → Data to Server;
    • Create a new instance;
    • Data source: Modbus data;
    • Protocol: MQTT;
    • JSON format: specify in what format should your data be sent. The variables listed below can be used to add additional information. Use %a to add the actual register data;
    • Segment count specifies how many registers are being sent in one message;
    • Specify the MQTT connection settings;
    • Specify the period (I recommend using the same as in the Modbus Master package);
And that should be it, you should start receiving the device data to your MQTT subscriber. Let me know if any additional information is needed.

  

Best regards,
DaumantasG 

by anonymous
Thanks, Daumantas. That seems to work if I want "report by interval."

For report by exception, I installed the mosquitto client, then used i/o juggler to trigger a script. I know the script runs because I see the logger update. But the data does not publish.

/usr/bin/logger "MQTT Script Initiated"
mosquitto_pub -h localhost -p 1883 -t router/get -m uptime
/usr/bin/logger "MQTT Script Completed"

However, if I paste

mosquitto_pub -h localhost -p 1883 -t router/get -m uptime

directly into an ssh session, it works great.

Do you know why this doesn't work in a script? Thanks.
by anonymous

Hello,

  

Sorry for the misunderstanding.

I'm not sure about the script, but perhaps using Modbus Alarms would work here?

They can be configured in the Modbus TCP Master instance, where the router is configured. We have a Wiki article about the Modbus alarms here.

  

Best regards,
DaumantasG

by anonymous
Thanks for the help. Even with that option, it looks like that is only for subscribing, not publishing?

Here's what I found to be the problem.

When I write a user script in the Windows program notepad++, then copy it to the modem using WinSCP, the mosquitto_pub command within the script does not work.

However, when I open the file off of the modem directly in WinSCP, edit it using the WinSCP editor, then save it using WinSCP, the script works great. I think there is something about the way it is saved in notepad++ that the modem doesn't like. I don't know why. Thanks for the help.
by anonymous
I didn't really help, but if any more information is needed, let me know!

  

Best regards,
DaumantasG