Node-red Python exec

I am trying to access dht11 temperature and humidity data using python program on raspberrypi 4b on to node-red 'exec' module , but it is unable to capture the python data and error shows rc:-2 ,

1/22/2021, 6:25:50 PMnode: 60d44db2.3b0944msg : Object
object payload: object
topic: ""
_msgid: "6b5db153.10ae"

python program is working fine and displaying output in console.
Temp: 64.4 F / 18.0 C Humidity: 68%
Temp: 64.4 F / 18.0 C Humidity: 68%
Temp: 64.4 F / 18.0 C Humidity: 68%
Temp: 64.4 F / 18.0 C Humidity: 68%

Any one plz help how to access this data in nodered

---- Node-red -----------

[{"id":"98f0a244.a3302","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"832a19ea.93caa8","type":"exec","z":"98f0a244.a3302","command":"/home/pi/IOTstack/Adafruit_CircuitPython_DHT/sudo python3 dht_simpletest.py","addpay":true,"append":"","useSpawn":"true","timer":"15","oldrc":false,"name":"dht_simplest.py","x":400,"y":80,"wires":[["9ae44969.7d99a8"],["60d44db2.3b0944"],["60d44db2.3b0944"]]},{"id":"5bbe50.570a71b","type":"inject","z":"98f0a244.a3302","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":80,"wires":[["832a19ea.93caa8"]]},{"id":"f6b7bd75.0b361","type":"function","z":"98f0a244.a3302","name":"","func":"msg['mx:temperature_c'] = msg.payload;\nmsg['mx:humidity'] = msg.humidity;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is deployed\n\n","finalize":"","x":380,"y":240,"wires":[["3d731fff.e628"]]},{"id":"3d731fff.e628","type":"debug","z":"98f0a244.a3302","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"","statusType":"msg","x":750,"y":240,"wires":[]},{"id":"9ae44969.7d99a8","type":"debug","z":"98f0a244.a3302","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":710,"y":60,"wires":[]},{"id":"60d44db2.3b0944","type":"debug","z":"98f0a244.a3302","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":710,"y":140,"wires":[]}]

[flow edited by a moderator]

Hi, in order to make code more readable and importable it is important to surround your code with three backticks
```
like this
```

You can edit and correct your post by clicking the pencil icon.

See this post for more details - How to share code or flow json

Also add debug nodes to all outputs of the exec node, set them to show Complete Message and give them names so you can identify them in the debug pane. Probably there will be a useful error message in one of those.

Why not use node-red-contrib-dht-sensor?

how exactly are you running the python program in the exec node (and outside of Node-RED) - I suspect one of them may be using sudo .

THis will not work as this is two year old and does not work with dht11

A quick (but not elegant) solution is to use your Python program to send data via MQTT to Node Red on the RPI 4b. Node Red has easy MQTT in to get the data. In this case, you can have the Python program run separately in the background.

Of course, you are wasting a little bit system resource by adding the extra MQTT service. Fortunately, MQTT is very light weight and does not add much overhead. And you don't need to use the 'exec' module in Node Red.