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.
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 127.0.0.1 but I also tried entering it directly no change, only ::1 will work.
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 127.0.0.1.
Other people have solved it by adding the -n 127.0.0.1 to their pigpiod exec argument to also bind it to ip v4 localhost.
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 127.0.0.1 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.
EDIT
Just confirmed this by adding the -n 127.0.0.1 argument to the systemd service file that starts the daemon to also bind it to ipv4 localhost 127.0.0.1 and now the node can connect with both localhost or 127.0.0.1 to the daemon.
So either using ::1 in the node or starting the daemon with a binding also to 127.0.0.1 will work.