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
905 views 6 comments
by anonymous
I want to use Python on the Router to read the state of the input, and then from that send an mqtt message to Azure. Can I do this, even if I want the message to be specific and not just the state?

1 Answer

0 votes
by anonymous

Hi,

It is a bit unclear what exactly is needed here.

Even though you can read the state of the I/O from the router via Modbus (reading from itself) and then send it to Azure IoT Hub via 'Data to server', you can send other information that is not available via the Modbus default registers.

Teltonika devices are running on RutOS, an operating system based on OpenWRT. So, it is possible to run Python code on Teltonika devices. For this, you will need to install Python. Keep in mind, that RUT240 does not have much RAM or Flash memory available. There should be around ~4 MB of userspace flash available for you, which should be enough to install a light version of Python via opkg (package manager), but you will likely be very tight on flash memory:

  • opkg update
  • opkg install python3-light

If you want to send data to Azure IoT Hub via MQTT, what you can do is use a custom Modbus custom register block and data to server functionalities. Basically, you can write a script that will obtain the information and perform the logic, then save the values in a separate file. This file will be used as a custom register for Modbus server. Then, with Data to the server and Modbus data as a source, the Modbus can take the data from that custom register (file) and send it to Azure IoT Hub via MQTT.

To obtain information about different I/O's, I suggest using ubus commands. To see what's available, execute:

  • ubus list | grep ioman

Then, for more information on some specific I/O (based on the output of the previous command), for example, you can execute:

  • ubus -v list ioman.gpio.dout2

Then, you can do 'status' and 'update' to view and change I/O status (output), respectively. For example:

  • ubus call ioman.gpio.dout2 status
  • ubus call ioman.gpio.dout2 update '{"value":"1"}'

So basically, you obtain the information that you want via ubus, apply some Python/shell scripting logic, and save it to a custom Modbus register. Then, configure the device to use a custom register block and read Modbus data from itself. After, configure 'Data to server' to send Modbus data to the Azure IoT Hub.

Kind Regards,

Andzej

by anonymous
Thank you for the answer. It has given me some ideas for a solution, but not quite what I'm looking for.

What I essentially want to happen, is for the Router to publish an mqtt message when the state of the input either turns high or low.

When high, the message format or topic should be:

/rut240/event/runtime

When low, the message format or should be:

/rut240/event/downtime

I don't know if it makes more sense, but my IoT-Hub isn't made for direct data values, but more commands coming from my devices. But I will try and see what I can do, with your supposed solution.

Thank you again!
by anonymous

Hi,

Another thing that you can take a look at is the I/O juggler triggers. Basically, you can configure your device to send an MQTT message when the I/O state changes. For this, you will need to create a rule and an action in Services -> Input/Output -> I/O juggler. The action can be set to MQTT. You can find more information on our wiki here.

Kind Regards,

by anonymous
Hello again!

I've already looked into I/O Juggler, but I don't seem to have the MQTT option to make an action?

I have installed MQTT in the package manager, and configured both Broker and Publisher.
by anonymous

Hi,

Are you looking in I/O Juggler -> Actions -> Type: MQTT?

Are you using the latest firmware version? If not, please update the firmware with 'keep settings' turned off. In case you are on the latest, restore the device to factory defaults.

Also, make sure you have advanced more enabled in the top right corner of the WebUI when you cannot find some of the settings. The MQTT option should still be visible in basic mode though, so I suggest updating the firmware / restoring to defaults.

Kind Regards,

Andzej

by anonymous
For some reason, my device had problems finding the new firmware through the server, so I had to manually update. But from what I could see from my current version and the newest available, I had to update. And that the most recent update, contained the MQTT option in I/O Juggler.

So, I can confirm after doing an update, I now have the MQTT option as an action, thank you! I am now testing it out.
by anonymous
Hi,

That's great to hear that the firmware update helped. Thanks for letting me know!

Kind Regards,

Andzej