33 lines
691 B
Python
Executable File
33 lines
691 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Transmit a single LoRa packet.
|
|
|
|
Usage:
|
|
python examples/simple_tx.py [PORT] [MESSAGE]
|
|
"""
|
|
|
|
import sys
|
|
|
|
import serial
|
|
|
|
import donglora as dl
|
|
|
|
port = None
|
|
message = "Hello from DongLoRa!"
|
|
|
|
args = sys.argv[1:]
|
|
if args and not args[0].startswith("/dev"):
|
|
message = " ".join(args)
|
|
elif args:
|
|
port = args[0]
|
|
if len(args) > 1:
|
|
message = " ".join(args[1:])
|
|
|
|
try:
|
|
ser = dl.connect(port)
|
|
print(dl.send(ser, "SetConfig", config=dl.DEFAULT_CONFIG))
|
|
print(dl.send(ser, "Transmit", payload=message.encode()))
|
|
print(f"Sent: {message!r}")
|
|
except serial.SerialException as e:
|
|
print(f"\nSerial error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|