You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the python API to talk to a Meshtastic instance running on localhost. this is a Raspberry Pi 3B, if that matters.
Every so often, it gets the following error:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib/python3.11/threading.py", line 1394, in run
self.function(*self.args, **self.kwargs)
File "/home/pi/meshtastic/lib/python3.11/site-packages/meshtastic/mesh_interface.py", line 1116, in callback
self.sendHeartbeat()
File "/home/pi/meshtastic/lib/python3.11/site-packages/meshtastic/mesh_interface.py", line 1105, in sendHeartbeat
self._sendToRadio(p)
File "/home/pi/meshtastic/lib/python3.11/site-packages/meshtastic/mesh_interface.py", line 1180, in _sendToRadio
self._sendToRadioImpl(toRadio)
File "/home/pi/meshtastic/lib/python3.11/site-packages/meshtastic/stream_interface.py", line 120, in _sendToRadioImpl
self._writeBytes(header + b)
File "/home/pi/meshtastic/lib/python3.11/site-packages/meshtastic/tcp_interface.py", line 79, in _writeBytes
self.socket.send(b)
BrokenPipeError: [Errno 32] Broken pipe
I saw the following article and tried the meshtastic.connection.lost, but that does not get called when this error happens.
Brokenpipe is a common issue. In a more general sense, the meshtastic code needs to built with the same design criteria as all embedded code--a graceful exit from every possible error.
When we stick a solar-powered device high in a tree and turn off WiFi to conserve power, we shouldn't have to climb the tree to retrive the device, open the enclosure and touch the reset button. the device needs to recover, reset, and resume.
I ended up getting around this by doing the following. The code reaches in the interface object and uses socket calls to get the status directly from the network socket. Not the best, but works.
def isSocketConnected(sock):
r, _, _ = select.select([sock], [], [], 0)
if r:
data = sock.recv(1, socket.MSG_PEEK)
if not data:
return False
return True
try:
#this line connects to meshtasticd
interface = meshtastic.tcp_interface.TCPInterface(hostname='localhost')
while True:
time.sleep(2)
#keep an eye on the socket to see if it closed
if isSocketConnected(interface.socket):
None
#print("Socket is connected")
else:
print("Socket is disconnected")
interface.close()
exit(4)
except :
print("meshtastic.tcp_interface.TCPInterface failed")
I'm using the python API to talk to a Meshtastic instance running on localhost. this is a Raspberry Pi 3B, if that matters.
Every so often, it gets the following error:
I saw the following article and tried the meshtastic.connection.lost, but that does not get called when this error happens.
#727
using try/except doesn't help because the error happens in a thread that the Meshtastic python lib kicks off.
the following property, doesn't change either when this error happens:
interface.isConnected
Looking at the python code, I don't see any error handling for when _writeBytes fails.
Any thoughts on how best to handle this error?
The text was updated successfully, but these errors were encountered: