Node-red-node-pi-gpiod localhost connection refused, try this

Just thought id leave this here as i had some trouble with it:
If you are trying to use node-red-node-pi-gpiod and you are getting an error that the connection on localhost was refused although the daemon is running try changing localhost to ::1.
This is the way to loopback to localhost via ipv6 which when available is now being used by default by raspberry pi os if available. The daemon binds to this if started with the -l flag and up v6 is the Standard.
Maybe this saves somebody some googling.


That is odd, I would have thought both would work. Does work?

Thats what the node tries by default when localhost is entered.
I think if it actually tried localhost it might work but the problem is that its trying but I also tried entering it directly no change, only ::1 will work.

It shouldn't it should pass localhost to the OS. Traditonally localhost is mapped to by the OS

$ ping localhost
PING localhost ( 56(84) bytes of data.
64 bytes from localhost ( icmp_seq=1 ttl=64 time=0.100 ms

but I that on a recent raspbian I get

$ ping localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.061 ms

This happens because in /etc/hosts is	localhost
::1		localhost ip6-localhost ip6-loopback

so if IPV6 is enabled it uses ::1. I am surprised that pigpiod cares though, either should work. What does ping localhost show?

pi@testipi3:~ $ ping localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.104 ms

The underlying js-pigpio library seems to automatically convert it. I think the problem might be also that when the pgpio daemon is started with the -l flag that only allows local connections it binds to ip v6 if enabled and than won’t accept the connection on
Other people have solved it by adding the -n to their pigpiod exec argument to also bind it to ip v4 localhost.

OK. I am not going to say I fully understand, as I don't.

The pigpiod node tries to connect to the pigpio daemon that can be installed and run on raspberries. For some things like pmw it’s a lot more efficient to use this daemon instead of the normal gpio nodes to control them directly.
This daemon has as one of its start arguments the option to bind it to localhost so that it can’t be accessed from other machines as you don’t want to necessarily expose your gpio control on the network.
I think what happens is that when it v6 is enabled it binds the daemon to only listen on ::1 and this way connections via are refused by the daemon.
Unfortunately the node or it’s underlying library tries to do just that if localhost is entered. I think this happens somewhere in the underlying python libraries used.
Well at least that’s what I think is happening.


Just confirmed this by adding the -n argument to the systemd service file that starts the daemon to also bind it to ipv4 localhost and now the node can connect with both localhost or to the daemon.
So either using ::1 in the node or starting the daemon with a binding also to will work.

OK, that makes sense.

1 Like

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