meshcore_py/examples/serial_msg.py

25 lines
532 B
Python
Raw Normal View History

2025-03-29 12:32:10 +01:00
#!/usr/bin/python
import asyncio
import json
from meshcore import MeshCore
2025-03-30 08:36:39 +02:00
from meshcore import SerialConnection
2025-03-29 12:32:10 +01:00
2025-03-30 08:36:39 +02:00
PORT = "/dev/ttyUSB0"
BAUDRATE = 115200
DEST = "mchome"
MSG = "hello from serial"
2025-03-29 12:32:10 +01:00
async def main () :
2025-03-30 08:36:39 +02:00
con = SerialConnection(PORT, BAUDRATE)
2025-03-29 12:32:10 +01:00
await con.connect()
2025-03-30 08:36:39 +02:00
await asyncio.sleep(0.1) # time for transport to establish
2025-03-29 12:32:10 +01:00
mc = MeshCore(con)
await mc.connect()
await mc.ensure_contacts()
await mc.send_msg(bytes.fromhex(mc.contacts[DEST]["public_key"])[0:6],MSG)
asyncio.run(main())