How to pass data from an HTTP node to Device State node

Hello, I have a Raspberry Pi running a python script that reads data from CANOpen sensors, the Pi also is running the Edge Agent. I’ve created the Raspberry Pi as an ‘Edge compute’ device and the flow and pressure sensors as ‘Peripheral’ Devices. One of your ‘Losant University’ videos suggests that the Python script and the Edge Agent can ‘talk’ to each other via HTTP.
I’ve created an ‘Edge Work Flow’ triggered by and HTTP node. This node is triggered by POST request from the Python Script. How can I pass the ‘Flow’ and ‘Pressure’ readings from the python script to the ‘Device:state’ node via the HTTP trigger node? Thanks in advance for any help/advice.

Hi @Diego_Cossio,

I would recommend checking out Losant University Course 5: Workflow Mechanics (and be sure to watch Chapter 8: Output Nodes) for a better understanding of the Workflow Engine. I would also recommend checking out the Device State Output Node, and the Debug Node, which allows inspection of the current payload at any point during a workflow.

Below is some additional documentation that may be pertinent:

Please let me know if you have any further questions!

Thanks,
Julia

An alternate way for a separate process to on a pi to communicate locally with the Edge Agent is via Redis . We tend to use this a lot. I find it is simpler to implement for a number of use cases.

this is done in two parts after you install redis server :wink:

Edge agent runs a workflow that subscribes to the local redis server and acts on whatever is published on that subscription channel

Your python code publishes JSON payload to the redis channel.

In your case the JSON payload can be already formatted so that the Edge Agent can publish it without any transformation if desired.

Cheers

T

Hi @JuliaKempf and @Tim_Hoffman,

Thank you very much for your suggestions. The Redis approach looks very interesting and for sure I will try it in the future. At moment, I’ve managed to updated the ‘Device:state’ node by sending a HTTP ‘GET’ request with the data attached as parameters.
data = {‘Flow’:‘0’, ‘Temperature’:‘0’, ‘Pressure’:‘0’}
r = requests.get(“http://localhost:8080”, params= data)
where the ‘0’ s are replaced with the actual data collected by the CANOpen sensors.

1 Like