2025-03-29 12:32:10 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
import json
|
|
|
|
|
from meshcore import MeshCore
|
2025-03-30 08:42:52 +02:00
|
|
|
from meshcore import TCPConnection
|
2025-04-14 09:40:06 +02:00
|
|
|
from meshcore import EventType
|
2025-03-29 12:32:10 +01:00
|
|
|
|
2025-03-30 08:42:52 +02:00
|
|
|
HOSTNAME = "mchome"
|
|
|
|
|
PORT = 5000
|
2025-04-14 09:40:06 +02:00
|
|
|
DEST = "t114_fdl"
|
2025-03-29 12:32:10 +01:00
|
|
|
MSG = "Hello World"
|
|
|
|
|
|
|
|
|
|
async def main () :
|
2025-03-30 08:42:52 +02:00
|
|
|
con = TCPConnection(HOSTNAME, PORT)
|
2025-03-29 12:32:10 +01:00
|
|
|
await con.connect()
|
|
|
|
|
mc = MeshCore(con)
|
|
|
|
|
await mc.connect()
|
|
|
|
|
|
|
|
|
|
await mc.ensure_contacts()
|
2025-04-13 22:19:08 -07:00
|
|
|
contact = mc.get_contact_by_name(DEST)
|
|
|
|
|
if contact is None:
|
|
|
|
|
print(f"Contact '{DEST}' not found in contacts.")
|
|
|
|
|
return
|
2025-04-14 11:10:59 -07:00
|
|
|
result = await mc.commands.send_msg(contact, MSG)
|
|
|
|
|
print(result)
|
|
|
|
|
|
|
|
|
|
if result.type == EventType.ERROR:
|
|
|
|
|
print(f"⚠️ Failed to send message: {result.payload}")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
exp_ack = result.payload["expected_ack"].hex()
|
2025-04-14 09:40:06 +02:00
|
|
|
print(await mc.wait_for_event(EventType.ACK, attribute_filters={"code": exp_ack}, timeout=5))
|
2025-03-29 12:32:10 +01:00
|
|
|
|
|
|
|
|
asyncio.run(main())
|