How to send data from python console to Node-Red on raspberry pi

Hello Guys,

I am reading the data of some temperature sensors using python on Raspberry pi. Now i want to send that data to node red application running on the same Raspberry pi. Does node-red has some built in node to receive this data on node-red?

How can i easily do it?

Thank you!

Depends - if it is a one time request then use the exec node to call your program - If it supplies data continuously then use the node-red-node-daemon node to call it.

I've found MQTT perfect for this. My Python code "publishes" the data and node-red "subscribes" and reads it with an MQTT input node. I usually use a local mosquitto "broker" running on the Pi to do this "interprocess communication".

Node-RED has lots of ways:

  • exec node
  • MQTT
  • TCP
  • UDP
  • HTTP
  • Websockets

For example, I use some BASH scripts that end with a call to a web page that Node-RED hosts with suitable data POSTed.

I use python scripts to send MQTT to MQTT Node Red all the time. Easy to do, and keeps loading on sending device light. I even have a python based systemd service that accepts MQTT directives from NR via MQTT and then return data via MQTT to NR. In my case, I use a dedicated MQTT broker, to keep broker loading off front end device, and off NR device as well.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.