raspberry gpi pin state when stopping node-red

624 views
Skip to first unread message

Kovacs Alpar

unread,
Mar 4, 2016, 2:57:02 AM3/4/16
to Node-RED
Hi,

I have a flow to control some relays with raspberry. The only problem is that when I stop/restart node-red my the GPIO pins set for output will got to state of 0.
This pins initialize to the desired state on startup. Is there a way to do the same nodered shutdown?

Alpar

Dave C-J

unread,
Mar 4, 2016, 3:48:00 AM3/4/16
to node...@googlegroups.com
At the the close we call GPIO.cleanup() which is the recommended thing to do.


After that we no longer have control of the GPIO so they will default to whatever the system sets them to, before we re-start and get control.

In theory you could try removing GPIO.cleanup from the nrgpio.py file - but I'm not going to apply that generally.

Kovacs Alpar

unread,
Mar 9, 2016, 8:52:48 AM3/9/16
to Node-RED

I removed GPIO.cleanup nothing changed. When I stop the node-red service all pin that is set to be digital output going to low value instantly. In the documentation linked by you I read that GPIO.cleanup should set this pins to digital input.

I suspecting that  this command  not executed when the service is stopped ( with SIGINT)

Kovacs Alpar

unread,
Mar 14, 2016, 11:28:56 AM3/14/16
to Node-RED
finally I found  a possible solution.

I modified the the nrfpio.py file to catch the SIGINT signal ( this signal stop the node-red service in raspbian):

import signal
def signal_term_handler(signal, frame):
GPIO.cleanup()
sys.exit(0)
signal.signal(signal.SIGINT, signal_term_handler)

it's ok now, when I stop the service all my GPIO port resting to input according with the documentation.

As I'm not an experimented programmer , I'm not absolutely sure about this workaround so any feedback is appreciated :)

Dave C-J

unread,
Mar 14, 2016, 12:09:10 PM3/14/16
to node...@googlegroups.com
looks like a sensible fix to me - I'll give it a whirl and apply it to core as long as it works. (can't see why not)

NodeIdea

unread,
Mar 14, 2016, 3:35:56 PM3/14/16
to Node-RED
Hi,

I'm trying to control my relays on temperature difference with Pi?NodeRed too. What does yours do?

Dave C-J

unread,
Mar 14, 2016, 7:40:19 PM3/14/16
to node...@googlegroups.com

Hi Kovacs

I tried your solution today. I added some output to the call, but never saw it called. How exactly are you stopping it ? By ctrl-break or node-red-stop ?

Kovacs Alpar

unread,
Mar 15, 2016, 2:37:31 AM3/15/16
to Node-RED


2016. március 15., kedd 1:40:19 UTC+2 időpontban Dave C-J a következőt írta:

Hi Kovacs

I tried your solution today. I added some output to the call, but never saw it called. How exactly are you stopping it ? By ctrl-break or node-red-stop ?.


Hi Dave,

I stopping with node-red-stop or service nodered stop, both command do the same. On the service description file (/lib/systemd/system/nodered.service on my pi) I have :
# Use SIGINT to stop
KillSignal=SIGINT

it mean for me that the service is stopped with the SIGINT signal

Kovacs Alpar

unread,
Mar 15, 2016, 2:39:16 AM3/15/16
to Node-RED
Hi Nodeldea,

I'm controlling my relay on temperature difference like you

NodeIdea

unread,
Mar 16, 2016, 3:22:36 AM3/16/16
to Node-RED

Alpar,

Can you give me some help please? I sent you a pm.

THanks
Reply all
Reply to author
Forward
0 new messages