From ec5077110d0bf4d77fc4e6f01940c8cc4e21a3dc Mon Sep 17 00:00:00 2001 From: Florent de Lamotte Date: Mon, 5 May 2025 15:10:29 +0200 Subject: [PATCH] set custom vars --- examples/ble_t1000_custom_vars.py | 17 +++++++++++++++++ examples/ble_t1000_set_cv.py | 20 ++++++++++++++++++++ src/meshcore/commands.py | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 examples/ble_t1000_custom_vars.py create mode 100755 examples/ble_t1000_set_cv.py diff --git a/examples/ble_t1000_custom_vars.py b/examples/ble_t1000_custom_vars.py new file mode 100755 index 0000000..db0a153 --- /dev/null +++ b/examples/ble_t1000_custom_vars.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import asyncio +from meshcore import MeshCore +from meshcore import BLEConnection + +ADDRESS = "T1000_S" # node ble adress or name + +async def main () : + con = BLEConnection(ADDRESS) + await con.connect() + mc = MeshCore(con) + await mc.connect() + + print(await mc.commands.get_custom_vars()) + +asyncio.run(main()) diff --git a/examples/ble_t1000_set_cv.py b/examples/ble_t1000_set_cv.py new file mode 100755 index 0000000..a18f227 --- /dev/null +++ b/examples/ble_t1000_set_cv.py @@ -0,0 +1,20 @@ +#!/usr/bin/python + +import asyncio +from meshcore import MeshCore +from meshcore import BLEConnection + +ADDRESS = "T1000_S" # node ble adress or name +VAR = "gps" +VALUE = "1" + +async def main () : + con = BLEConnection(ADDRESS) + await con.connect() + mc = MeshCore(con, debug=True) + await mc.connect() + + print(await mc.commands.set_custom_var(VAR, VALUE)) + + +asyncio.run(main()) diff --git a/src/meshcore/commands.py b/src/meshcore/commands.py index c2306bc..9937f2f 100644 --- a/src/meshcore/commands.py +++ b/src/meshcore/commands.py @@ -320,7 +320,7 @@ class CommandHandler: async def set_custom_var(self, key, value) -> Event: logger.debug(f"Setting custom var {key} to {value}") - data = b"\x29" + key.encode("utf-8") + ":" + value.encode("utf-8") + data = b"\x29" + key.encode("utf-8") + b":" + value.encode("utf-8") return await self.send(data, [EventType.OK, EventType.ERROR]) async def send_cli(self, cmd) -> Event: