Running a Python Script in Node Red

Hi everyone,

I am having issues with running a python script in Node Red. A bit of background into what I am trying to do:

I have a Raspberry Pi that use to run CraftBeerPi which is a Python based brewing application. I have decided to try and implement the brewery into Node Red. I have 4 PT100's that use the Max31865 boards. Currently the plugin for CBPI allows you to specify the CS pin to suit your application. I am using every GPIO pin on my Pi to run the brewery. The only option currently is to use the Max31865 node to do this communication, however it only allows you to use the fixed CS pins CS0.0 and 0.1 or CS1.0, 1.1 or 1.2 I believe. I can not add a second lot of SPI pins to use the other specified CS pins for the second SPI bus due to not having the available space. What I want to do is implement the PT100 plugin written in python into Node Red. Here is the issue..... I can't code. I can follow instructions and try things but my coding skills are very limited. I am learning however I tend to jump into the deep end with concrete blocks on my feet.

What I have done is download the python script onto the pi, and tried to use the exc node and also the pythonshell node. So far I have been unsucessful.

Here is the EXC flow I have tried

[{"id":"6a1243c1.c1df5c","type":"debug","z":"7b5c5210.c7dc5c","name":"HLT Temp Feedback","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":780,"y":240,"wires":[]},[MAX31865 Modified Code.txt|attachment](upload://peBgRtBcNUrXLMiXsf4P9eQbCUk.txt) (9.2 KB) {"id":"e5b43415.3285f8","type":"exec","z":"7b5c5210.c7dc5c","command":"python ~/MAX31865/max31865.py 8 ","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":350,"y":300,"wires":[["6a1243c1.c1df5c"],["542f6378.7aea1c"],["24dd757c.e54d1a"]]},{"id":"542f6378.7aea1c","type":"debug","z":"7b5c5210.c7dc5c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":320,"wires":[]},{"id":"24dd757c.e54d1a","type":"debug","z":"7b5c5210.c7dc5c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":400,"wires":[]},{"id":"d17a44af.52f008","type":"inject","z":"7b5c5210.c7dc5c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":360,"wires":[["e5b43415.3285f8"]]}]

The python Shell I managed to get working but not by adding any valves to change the cs pin assignment.

I have attached the python script where I have changed a couple of things to suit. First is to make csPin=sys.argv[1] and then I have adjusted the ref resistor to suit that of the board and one other parameter to account for the PT100 wiring.

When using a debug node, I get the following

Traceback (most recent call last): File "/home/pi/MAX31865/max31865.py", line 215, in <module> max = max31865.max31865(csPin,misoPin,mosiPin,clkPin) File "/home/pi/MAX31865/max31865.py", line 43, in __init__ self.setupGPIO() File "/home/pi/MAX31865/max31865.py", line 48, in setupGPIO GPIO.setup(self.csPin, GPIO.OUT)ValueError: Channel must be an integer or list/tuple of integers

Is anyone able to help?

Kind Regards,
Sam

I haven't tried your code yet, but looking at your errors I think you might be dealing with a parsing issue. When taking arguments from the shell, through sys.argv, they are by default seen as string.

If you don't convert it to an integer first, the GPIO setup function isn't kind enough to parse it to an integer by itself, which results in that error. Try changing your line to csPin=int(sys.argv[1]) and see if that fixes it.

Thank you for that. That has helped for one bit. It seems to only still be reading off the one pin. When I change it, it does not change the input. Do you think you could have a look at the code and see if I am missing something.

Kind Regards,
Sam

Actually never mind. I found it. It was right down the bottom. I forgot about that part

Regards,
Sam

HI Afelix,

Another question, do you know if you can run the same script multiple times at once? My arg value as I think I mentioned above is the CS pin. I have 4 sensors so need to run the script 4 times to get the values. Can I use 4 exec nodes addressing the same python code but changing the arg it sends? Or am I best to copy the python script 3 times with different names and do it that way?

Kind Regards,
Sam

I’ve seen your message and I’m answering quickly to prevent I forget. I need to read the full script to give an actual answer and I’ll wait with that until my fever drops. It depends on the circumstances and how you run it in the flow but repurposing the script with arguments would likely be my solution. Again, haven’t seen the code yet.

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