Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote_rpi_gpio broken pipe after remote machine rebooted or temporarily disconnected #64441

Closed
scarre opened this issue Jan 19, 2022 · 19 comments

Comments

@scarre
Copy link

scarre commented Jan 19, 2022

The problem

remote_rpi_gpio is working fine until the remote machine is temporarily unavailable/disconnected from the network or rebooted.
Trying to interact with the remote gpio (e.g. switch on/off) results in error: Failed to call service switch/turn_on (/turn_off) [Errno 32] Broken pipe.
Functional connection to remote machine can only be recovered by restarting Home Assistant core.
Already reported as #45770 and closed, but apparently not solved.
#45770

What version of Home Assistant Core has the issue?

core-2021.12.9

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

remote_rpi_gpio

Link to integration documentation on our website

https://www.home-assistant.io/integrations/remote_rpi_gpio/

Example YAML snippet

switch:
  - platform: remote_rpi_gpio
    host: 192.168.xxx.xxx
    invert_logic: true
    ports:
      17: relay1
      18: relay2
      26: relay3

Anything in the logs that might be useful for us?

Logger: homeassistant.components.websocket_api.http.connection
Source: components/remote_rpi_gpio/__init__.py:54
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 14:29:54 (1 occurrences)
Last logged: 14:29:54

[2779057864] [Errno 32] Broken pipe
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 948, in async_turn_on
    await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/switch.py", line 73, in turn_on
    remote_rpi_gpio.write_output(self._switch, 1)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/__init__.py", line 54, in write_output
    switch.on()
  File "/usr/local/lib/python3.9/site-packages/gpiozero/output_devices.py", line 229, in on
    self._write(True)
  File "/usr/local/lib/python3.9/site-packages/gpiozero/output_devices.py", line 106, in _write
    self.pin.state = self._value_to_state(value)
  File "/usr/local/lib/python3.9/site-packages/gpiozero/pins/__init__.py", line 305, in <lambda>
    lambda self, value: self._set_state(value),
  File "/usr/local/lib/python3.9/site-packages/gpiozero/pins/pigpio.py", line 267, in _set_state
    elif self.function == 'input':
  File "/usr/local/lib/python3.9/site-packages/gpiozero/pins/__init__.py", line 283, in <lambda>
    lambda self: self._get_function(),
  File "/usr/local/lib/python3.9/site-packages/gpiozero/pins/pigpio.py", line 240, in _get_function
    return self.GPIO_FUNCTION_NAMES[self.factory.connection.get_mode(self.number)]
  File "/usr/local/lib/python3.9/site-packages/pigpio.py", line 1402, in get_mode
    return _u2i(_pigpio_command(self.sl, _PI_CMD_MODEG, gpio, 0))
  File "/usr/local/lib/python3.9/site-packages/pigpio.py", line 1025, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
BrokenPipeError: [Errno 32] Broken pipe

Additional information

It would probably be good to try recovering the connection ( at least a few times - 2 or 3) after a broken pipe error ,before abandoning. I think that trying to recover upon error is better than continuously monitoring the connection: it is less "invasive" and not so costly.
There are many situations where a remote machine can be temporarily disconnected from the network or rebooted, and it shouldn't require a reboot of the core to recover.
With other integrations (e.g. deconz with a remote hub), temporarily disconnecting the remote hub or rebooting it will not affect home assistant core. I understand that accessing a deconz remote hub via a web service is not exactly comparable to maintaining a TCP connection with a remote rapsberry pi; however not trying to re-establish a TCP connection when we know it is broken seems a bit "incomplete".

@probot-home-assistant
Copy link

remote_rpi_gpio documentation
remote_rpi_gpio source
(message by IssueLinks)

@Electronlibre2012
Copy link

Hello,

i got the same problem and see your post...thanks...

just reboot of the core is ok but your comment is great, its bad to have to reboot the Core to have the pipe alive again...

@ne0c0de
Copy link

ne0c0de commented Feb 15, 2022

hey guys @scarre @Electronlibre2012 how did (actually where) you setup this:

Environment = GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=YOUR_RPi_IP_ADDRESS

I still couldn't find any usefull information about where to setup environment variables in home assistant

@ne0c0de
Copy link

ne0c0de commented Feb 15, 2022

i just ssh ed to HA and just run the export command and now it's stored in env variables,

reboot the host but still can't access the remote raspberry's gpio ports even it's configured and allowed to HA IP,

is there any magic that I should do?

@Electronlibre2012
Copy link

hello @ne0c0de ,

that was never clear for me but it works great for a while, this is what i do :

1-intall SSH & Web Terminal Addon
2-in "init_commands:" i have put

  • pip3 install virtualenv
  • virtualenv -p python3 env
  • source env/bin/activate
  • pip3 install gpiozero pigpio
  • GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.1.xxx
    it works...dont know exactly if its the good way to make it work...never found someone to help and give a step by step guide...i have just follow the instructions of the docs...but i am not an expert...like sometimes dont know exactly what i am doing...but it works... ;)

@github-actions
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 18, 2022
@bergerb-com
Copy link

bergerb-com commented May 19, 2022

Same problem here. It also does that, when the GPIO is taken over by a local script.
And from what I can see, it looks like the CPU Usage is also at 100%, when that happens.

@github-actions github-actions bot removed the stale label May 19, 2022
@zi3lo
Copy link

zi3lo commented May 20, 2022

I can confirm. Problem persist, even after update to 2022.5.5. Remote gpio works with my rpi until restart this remote host. Then I have 'broken pipe' and connection doesn't resume. I have to restart home assistant to resume connection.

@benkibejs
Copy link

I was thinking of just modifying the code for https://github.com/home-assistant/core/blob/dev/homeassistant/components/remote_rpi_gpio/switch.py to restart the connection if it is broken when you do turn_on or turn_off

@meldarionqeusse
Copy link

same problem using rpiw as a binary sensor. It should at least let you know if the remote raspberry pi becomes unavailable.

@sIush
Copy link

sIush commented Dec 29, 2022

same problem with remote GPIO as switch. If a raspberry pi reboots whole pipeline breaks. So far unusable. I was also not able to add multiple remote GPIO from different pi's.

also discussed here

@cescobaz
Copy link

I tried to solve the issue by adding a try ... except ..., the re-connection works, but the CPU load doesn't fix. So I reproduce the CPU bug with the underline lib pigpio for python, then I opened an issue joan2937/pigpio#563

@Bluscream
Copy link

I had the same problem for a long time, but it seems to work now

@klona
Copy link

klona commented May 6, 2023

Hi, same here with switch and digital inputs on raspberry pi3 & PiZero
Need to reboot Home Assistant after reboot rasp or network disconnect (what happen every time Ubiquiti controller upgrade firmware on Wifi...)

BTW, not related, but that would be nice to have unique_ID option...

@Ventusfahrer
Copy link

Ventusfahrer commented Jun 21, 2023

Same problem here wiith digital outputs on Raspi B+ (yes, very old, but still sufficient to switch relais).

I will switch over to mqtt-io.app (https://mqtt-io.app), which, as an mqtt client, has all options to handle all kinds of network connection problems and program crashes in an excelet manner.

It looks very much like remote_gpio integration is using the hassio network stack directly and some parameters did prevent to reconnect after an network error.

Why re-inventing the wheel, if there is already a solution available which offers a lot of error detection and -handling by default.

@cescobaz
Copy link

Same problem here wiith digital outputs on Raspi B+ (yes, very old, but still sufficient to switch relais).

I will switch over to mqtt-io.app (https://mqtt-io.app), which, as an mqtt client, has all options to handle all kinds of network connection problems and program crashes in an excelet manner.

It looks very much like remote_gpio integration is using the hassio network stack directly and some parameters did prevent to reconnect after an network error.

Why re-inventing the wheel, if there is already a solution available which offers a lot of error detection and -handling by default.

At the end I did the same and this solution is much better: mqtt decouples the device so you can attach multiple software to it: home-assistant, nodered, your custom software etc.

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
@Bluscream
Copy link

Same problem here wiith digital outputs on Raspi B+ (yes, very old, but still sufficient to switch relais).

I will switch over to mqtt-io.app (https://mqtt-io.app), which, as an mqtt client, has all options to handle all kinds of network connection problems and program crashes in an excelet manner.

It looks very much like remote_gpio integration is using the hassio network stack directly and some parameters did prevent to reconnect after an network error.

Why re-inventing the wheel, if there is already a solution available which offers a lot of error detection and -handling by default.

is there a good tutorial on mqtt for gpio?

@Electronlibre2012
Copy link

hello,

i have any problem with remote_rpi_gpio,

what i do is the same config in the first post AND i install advanced ssh and web terminal and add this in the init_commands part of the addon config :

init_commands:
  - pip3 install virtualenv
  - virtualenv -p python3 env
  - source env/bin/activate
  - pip3 install gpiozero pigpio
  - GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.1.113 python3

and it work great, even after a reboot of the remote pi. its a rpi4.

hope it will help

@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests