Skip to content

Handling BrokenPipeError with meshtastic TCPInterface #727

Closed
@rickoooooo

Description

@rickoooooo

I've been working on a Python project which uses this Meshtastic Python API. I noticed that my project regularly crashes with the below stack trace. I believe what's happening is that the Meshtastic radio only permits a single TCP connection at a time. If anything else on the network connects to the Meshtastic radio, then my project is disconnected. The API does not seem to recognize or handle this and my project is no longer able to communicate with the radio. It results in an unhandled exception when the heartbeat fails. I'm unsure if there's some way I can catch and handle this in my own code, as it seems to be happening in a thread inside the Meshtastic library itself. Ideally the disconnection would be recognized immeditaely so a connection could be re-established. Any suggestions are appreciated!

DEBUG:root:Sending heartbeat, interval 300 seconds
DEBUG:root:Sending: heartbeat { }
DEBUG:root:sending header:b'\x94\xc3\x00\x02' b:b':\x00'
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1433, in run
    self.function(*self.args, **self.kwargs)
  File "/usr/lib/python3.12/site-packages/meshtastic/mesh_interface.py", line 906, in callback
    self.sendHeartbeat()
  File "/usr/lib/python3.12/site-packages/meshtastic/mesh_interface.py", line 895, in sendHeartbeat
    self._sendToRadio(p)
  File "/usr/lib/python3.12/site-packages/meshtastic/mesh_interface.py", line 970, in _sendToRadio
    self._sendToRadioImpl(toRadio)
  File "/usr/lib/python3.12/site-packages/meshtastic/stream_interface.py", line 120, in _sendToRadioImpl
    self._writeBytes(header + b)
  File "/usr/lib/python3.12/site-packages/meshtastic/tcp_interface.py", line 79, in _writeBytes
    self.socket.send(b)
BrokenPipeError: [Errno 32] Broken pipe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions