mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
fix for telemetry (ignore 8 last bytes)
This commit is contained in:
parent
4c72ee5197
commit
9ecc98bdc0
2 changed files with 61 additions and 1 deletions
60
examples/serial_repeater_telemetry.py
Executable file
60
examples/serial_repeater_telemetry.py
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
|
||||
from meshcore import MeshCore
|
||||
from meshcore.events import EventType
|
||||
|
||||
async def main():
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(description='Get status from a repeater via serial connection')
|
||||
parser.add_argument('-p', '--port', required=True, help='Serial port')
|
||||
parser.add_argument('-b', '--baudrate', type=int, default=115200, help='Baud rate')
|
||||
parser.add_argument('-r', '--repeater', required=True, help='Repeater name')
|
||||
parser.add_argument('-pw', '--password', required=True, help='Password for login')
|
||||
parser.add_argument('-t', '--timeout', type=float, default=10.0, help='Timeout for responses in seconds')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Connect to the device
|
||||
mc = await MeshCore.create_serial(args.port, args.baudrate, debug=True)
|
||||
|
||||
try:
|
||||
# Get contacts
|
||||
await mc.ensure_contacts()
|
||||
repeater = mc.get_contact_by_name(args.repeater)
|
||||
|
||||
if repeater is None:
|
||||
print(f"Repeater '{args.repeater}' not found in contacts.")
|
||||
return
|
||||
|
||||
# Send login request
|
||||
print(f"Logging in to repeater '{args.repeater}'...")
|
||||
login_event = await mc.commands.send_login(repeater, args.password)
|
||||
|
||||
if login_event.type != EventType.ERROR:
|
||||
print("Login successful")
|
||||
|
||||
# Send status request
|
||||
print("Sending status request...")
|
||||
await mc.commands.send_telemetry_req(repeater)
|
||||
|
||||
# Wait for status response
|
||||
telemetry_event = await mc.wait_for_event(EventType.TELEMETRY_RESPONSE, timeout=args.timeout)
|
||||
print(telemetry_event)
|
||||
|
||||
else:
|
||||
print("Login failed or timed out")
|
||||
|
||||
finally:
|
||||
# Always disconnect properly
|
||||
await mc.disconnect()
|
||||
print("Disconnected from device")
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except KeyboardInterrupt:
|
||||
print("\nOperation cancelled by user")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
|
@ -380,7 +380,7 @@ class MessageReader:
|
|||
res = {}
|
||||
|
||||
res["pubkey_pre"] = data[2:8].hex()
|
||||
buf = data[8:]
|
||||
buf = data[8:-8]
|
||||
res["data"] = buf.hex()
|
||||
res["lpp"] = LppFrame().from_bytes(buf)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue