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

**URL:** https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226
**Category:** General
**Created:** [16 January 2021 12:19 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226 "2021-01-16T12:19:38Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [16 January 2021 12:19 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/1 "2021-01-16T12:19:38Z")

</div>

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.

Johannes

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 January 2021 13:19 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/2 "2021-01-16T13:19:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [16 January 2021 13:24 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/3 "2021-01-16T13:24:33Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 January 2021 13:38 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/4 "2021-01-16T13:38:12Z")

</div>

> [@JGKK](#):
>
> Thats what the node tries by default when localhost is entered

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

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

```

but I that on a recent raspbian I get

```auto
$ 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

```auto
127.0.0.1	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?

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [16 January 2021 13:40 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/5 "2021-01-16T13:40:49Z")

</div>

> [@Colin](#):
>
> What does `ping localhost` show

```auto
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

```

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [16 January 2021 13:47 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/6 "2021-01-16T13:47:20Z")

</div>

> [@Colin](#):
>
> It shouldn't it should pass localhost to the OS

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 January 2021 13:57 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/7 "2021-01-16T13:57:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [16 January 2021 14:09 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/8 "2021-01-16T14:09:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 January 2021 14:23 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/9 "2021-01-16T14:23:35Z")

</div>

OK, that makes sense.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [17 March 2021 14:23 UTC](https://discourse.nodered.org/t/node-red-node-pi-gpiod-localhost-connection-refused-try-this/39226/10 "2021-03-17T14:23:42Z")

</div>

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