Hi all,
we are working on a pilot project that needs to link some sensors (inclinometers and accelerometers) with our IOT platform.
Our IoT platform needs to receive the JSON payload messages.
These sensors send a message using a hexadecimal payload, so we need to add a new layer that has to transform their message payload into JSON and then send the result to our IoT Platform.
The sensor provider suggested we use your devices, in particular, they suggested “Router RUT950/951 with d MQTT broker”.
Using this approach the sensor publishes messages to your router’sMQTT Broker.
Are we able to deploy Python scripts in the router, so it subscribes to the topic from your broker and performs the parser operations (transforming the payload from hexadecimal to JSON) prior to communication with our external IOTP platform?
Can you suggest another approach to using your device?
Is it possible to configure a specific codec to the router’s MQTT Broker in order to push directly a JSON payload?
You can set up the MQTT broker and configure Data to Server using MQTT data input. The MQTT data input will listen for MQTT messages on the broker (RUT itself). This means that when your sensors publish messages to the MQTT broker running on your RUT device, the Data to Server will receive that message and send it to your platform via HTTP or MQTT, depending on your requirements.
If your sensors transmit data in HEX format, the HEX value will be converted to a decimal value. Here’s an example:
If you simply publish 0x48454C4C4F (HEX) to the broker on the topic /RUT/Data, you will receive something like this on your server:
This is default JSON format, but you have the flexibility to define your own custom format. Therefore, feel free to customize the format based on your preferences, such as removing CollectionName, topic, etc.
Information about Data to Server feature can be found on our wiki here.
While Python can be installed, please be aware that the devices have hardware limitations, such as RAM and Flash. You could potentially write a script to retrieve and parse the data as needed. However, it might be easier to modify how the data is presented on your server.
thanks for your response.
Unfortunately, it is not possible to change the behavior of our platform, so we have to change the payload content before it arrives in our environments.
Do you think that adopting a different device ( with more RAM for example of kind TRB1xx or RUTX) is it possible to meet our requirements?
In a unique device ( of a kind TRB1xx or RUTX), we can have the
MQTT broker and Python3 module to install a Python script that transforms the hexadecimal message received from the topic subscribed on the MQTT broker in a JSON in this format:
{
temperature: 30,
positionX:20,
positionY:30,
…
…
}
Furthermore, after message transformation, the Phyton script will publish the JSON message on the external MQTT broker (without the use of a bridge).
Is it a workable solution? If not, can you suggest us another device that allow our needs?
The Data to Server will transmit data in JSON format. The HEX payload of the MQTT message, upon being published to the MQTT broker on the RUT device, undergoes conversion to decimal and is formatted according to your specified configuration for Data to Server (JSON).
I uploaded an example of a Python parser script used with our sensors (I can’t upload the script).
We will add JSON formatting and the instruction to send the parser result to the external MQTT broker.
I hide the provider company name in the script.
Yes, if the data to server feature is not enough for you and you want to parse the data your way via a python script, you can do that. Simply run the broker on RUT and subscribe via your python script on the required topic. MQTT broker information is available here.
Though, please be careful when it comes to device memory - both flash and RAM, as the device is quite limited. On RUT9, there’s only a few MB of flash (around 3.5 MB for users). Since you need Python and paho-mqtt, it may not fit. RUT956 for example, has a USB port and can expand the memory via USB drive. More information on it here.
I would suggest installing python3-light to avoid unnecessary librararies:
opkg update
opkg install python3-light
Then simply execute your script with python command.
If you want to execute the script with each device boot, then you could place it in /etc/rc.local file. This way, the script will be executed after each reboot.