feat: example scripts (simple_rx, simple_tx, ping_pong) with shared donglora.py helper
This commit is contained in:
9898 files changed
+271434
No files matched your search
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Receive LoRa packets and print them.
|
||||
|
||||
Usage:
|
||||
uv run examples/simple_rx.py [PORT]
|
||||
"""
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = ["cobs", "pyserial"]
|
||||
# ///
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, __import__("pathlib").Path(__file__).parent.as_posix())
|
||||
import donglora as dl # noqa: E402
|
||||
|
||||
ser = dl.connect(sys.argv[1] if len(sys.argv) > 1 else None)
|
||||
print(dl.send(ser, "SetConfig", config=dl.DEFAULT_CONFIG))
|
||||
print(dl.send(ser, "StartRx"))
|
||||
|
||||
print("\nListening (Ctrl+C to stop)...\n")
|
||||
ser.timeout = 1
|
||||
|
||||
try:
|
||||
while True:
|
||||
data = dl.read_frame(ser)
|
||||
if data is None:
|
||||
continue
|
||||
resp = dl.decode_response(data)
|
||||
if resp["type"] == "RxPacket":
|
||||
p = resp["payload"]
|
||||
print(f" RSSI:{resp['rssi']:4d}dBm SNR:{resp['snr']:3d}dB len:{len(p):3d} {p.hex()}")
|
||||
except KeyboardInterrupt:
|
||||
dl.send(ser, "StopRx")
|
||||
print("\nDone.")
|
||||
Reference in new issue
Block a user