How to communicate continuously with python

Hi.
Im looking for ways to communicate between node-red and python.

Sample_code.py
while True:
text = input()
print(f'input = {text}')

This python script is excuted using exec node in node-red
Normaly input() is entered from the terminal using the keyboard,
but is there a way to enter it from node-red?

Why not use MQTT in the middle - setup Python to speak to your MQTT broker and send backwards and forwards from there.

Then you could run the python script using a daemon or a cron job after startup and just leave it running continuosly

Craig

If you just need something simple, try:

import sys
print (sys.argv)

If you truely need continuous connections though, you should consider running the Python script as its own microservice with MQTT as suggested by Craig. Or you can use TCP, UDP, or HTTP interconnections - but MQTT would be more robust at the expense of a 3rd service needing to run.

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