From ede064d9933a968ec38d3f106f2cccecd55d8172 Mon Sep 17 00:00:00 2001 From: Florent Date: Sat, 29 Mar 2025 12:32:10 +0100 Subject: [PATCH] some examples --- examples/mchome_contacts.py | 18 ++++++++++++++++++ examples/mchome_infos.py | 18 ++++++++++++++++++ examples/mchome_msg.py | 22 ++++++++++++++++++++++ examples/mchome_readmsgs.py | 25 +++++++++++++++++++++++++ examples/mepo_mc_gps.py | 24 ++++++++++++++++++++++++ examples/node_infos.py | 18 ++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100755 examples/mchome_contacts.py create mode 100755 examples/mchome_infos.py create mode 100755 examples/mchome_msg.py create mode 100755 examples/mchome_readmsgs.py create mode 100755 examples/mepo_mc_gps.py create mode 100755 examples/node_infos.py diff --git a/examples/mchome_contacts.py b/examples/mchome_contacts.py new file mode 100755 index 0000000..3e730d8 --- /dev/null +++ b/examples/mchome_contacts.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +import asyncio +import json +from meshcore import TCPConnection +from meshcore import MeshCore + +HOSTNAME = "mchome" +PORT = 5000 + +async def main () : + con = TCPConnection(HOSTNAME, PORT) + await con.connect() + mc = MeshCore(con) + await mc.connect() + + print(json.dumps(await mc.get_contacts(),indent=4)) +asyncio.run(main()) diff --git a/examples/mchome_infos.py b/examples/mchome_infos.py new file mode 100755 index 0000000..1c494c6 --- /dev/null +++ b/examples/mchome_infos.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +from meshcore import TCPConnection +from meshcore import MeshCore +import asyncio + +HOSTNAME = "mchome" +PORT = 5000 + +async def main () : + con = TCPConnection(HOSTNAME, PORT) + await con.connect() + mc = MeshCore(con) + await mc.connect() + + print(mc.self_info) + +asyncio.run(main()) diff --git a/examples/mchome_msg.py b/examples/mchome_msg.py new file mode 100755 index 0000000..3f9d99a --- /dev/null +++ b/examples/mchome_msg.py @@ -0,0 +1,22 @@ +#!/usr/bin/python + +import asyncio +import json +from meshcore import TCPConnection +from meshcore import MeshCore + +HOSTNAME = "mchome" +PORT = 5000 +DEST = "t1000" +MSG = "Hello World" + +async def main () : + con = TCPConnection(HOSTNAME, PORT) + await con.connect() + 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()) diff --git a/examples/mchome_readmsgs.py b/examples/mchome_readmsgs.py new file mode 100755 index 0000000..e575000 --- /dev/null +++ b/examples/mchome_readmsgs.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +import asyncio +import json +from meshcore import TCPConnection +from meshcore import MeshCore + +HOSTNAME = "mchome" +PORT = 5000 +DEST = "t1000" +MSG = "Hello World" + +async def main () : + con = TCPConnection(HOSTNAME, PORT) + await con.connect() + mc = MeshCore(con) + await mc.connect() + + res = True + while res: + res = await mc.get_msg() + if res : + print (res) + +asyncio.run(main()) diff --git a/examples/mepo_mc_gps.py b/examples/mepo_mc_gps.py new file mode 100755 index 0000000..c10636f --- /dev/null +++ b/examples/mepo_mc_gps.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +DISPLAYNAME="Center at MC node location" + +from meshcore import BLEConnection +from meshcore import MeshCore +import asyncio + +ADDRESS = "t1000" + +async def main () : + con = BLEConnection(ADDRESS) + await con.connect() + mc = MeshCore(con) + await mc.connect() + + infos = mc.self_info + + lat=infos["adv_lat"] + lon=infos["adv_lon"] + + print('[{"cmd":"prefset_n","args":{"pref":"lat","value":' + str(lat) + '}},') + print('{"cmd":"prefset_n","args":{"pref":"lon","value":' + str(lon) + '}}]') + +asyncio.run(main()) diff --git a/examples/node_infos.py b/examples/node_infos.py new file mode 100755 index 0000000..1c494c6 --- /dev/null +++ b/examples/node_infos.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +from meshcore import TCPConnection +from meshcore import MeshCore +import asyncio + +HOSTNAME = "mchome" +PORT = 5000 + +async def main () : + con = TCPConnection(HOSTNAME, PORT) + await con.connect() + mc = MeshCore(con) + await mc.connect() + + print(mc.self_info) + +asyncio.run(main())