Enhance testing and error handling; update documentation and examples

This commit is contained in:
pdxlocations
2026-08-01 01:14:46 -07:00
parent d242a82d1d
commit dbaa3b38b8
21 changed files with 228 additions and 61 deletions
+10 -4
View File
@@ -16,13 +16,19 @@ def on_packet(packet):
if packet.WhichOneof("payload_variant") != "decoded":
return
if packet.decoded.portnum == PortNum.TEXT_MESSAGE_APP:
print("from !%08x: %s" % (
packet.from_, packet.decoded.payload.decode("utf-8", "replace")
))
try:
text = packet.decoded.payload.decode("utf-8")
except UnicodeError:
text = repr(packet.decoded.payload)
print("from !%08x: %s" % (packet.from_, text))
def on_error(error, payload):
print("skipping undecodable radio frame:", error, "(%d bytes)" % len(payload))
uart = UART(0, 115200, tx=Pin(0), rx=Pin(1), timeout=0, rxbuf=1024)
mesh = SerialInterface(uart, on_packet=on_packet, on_log=print)
mesh = SerialInterface(uart, on_packet=on_packet, on_log=print, on_error=on_error)
mesh.connect()
hello_sent = False