diff --git a/software/release/README.md b/software/release/README.md index 526cb12..7b1dbd5 100644 --- a/software/release/README.md +++ b/software/release/README.md @@ -27,6 +27,7 @@ The repository has the following directory tree. │ ├── hm3.py │ ├── icons.py │ ├── main.py + │ ├── mm1.py │ ├── networking.py │ ├── sensors.py │ ├── servo.py @@ -68,6 +69,7 @@ The repository has the following directory tree. │ ├── boot.py │ ├── config.py │ ├── main.py + │ ├── mm1.py │ ├── networking.py │ └── ssp_networking.py ├── sl1 diff --git a/software/release/all/README.md b/software/release/all/README.md index 468783b..aed626a 100644 --- a/software/release/all/README.md +++ b/software/release/all/README.md @@ -24,6 +24,7 @@ The repository has the following directory tree. ├── hm3.py ├── icons.py ├── main.py + ├── mm1.py ├── networking.py ├── sensors.py ├── servo.py @@ -45,6 +46,7 @@ A short description of the directories can be found below. | main/boot.py | Smart Module boot.py | Nick | | main/am1.py | Admin module main program | Nick | | main/hm3.py | Hive motor module main program | Nick | +| main/mm1.py | Module module main program | Nick | | main/sl1.py | Smart light module main program | Milan | | main/sm3.py | Smart motor module main program | Milan | | main/sp1.py | Smart splat module main program | Nick | diff --git a/software/release/all/boot.py b/software/release/all/boot.py index bd1ddd1..50e1da5 100644 --- a/software/release/all/boot.py +++ b/software/release/all/boot.py @@ -10,8 +10,6 @@ except Exception as e: print(f"Error {e}") -module_name = config.config["configuration"].lower() - import gc gc.collect() @@ -60,8 +58,8 @@ def deinit(): machine.reset() try: - with open(module_name + ".py") as f: + with open(config.config["configuration"].lower() + ".py") as f: code = f.read() exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) except Exception as e: - print(f"Error running {module_name}: {e}") + print(f"Error running {config.config['configuration']}: {e}") diff --git a/software/release/all/config.py b/software/release/all/config.py index 3b89270..2175fa3 100644 --- a/software/release/all/config.py +++ b/software/release/all/config.py @@ -1,5 +1,6 @@ config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': None, 'sta_channel': 1, 'type': None, 'version': None} version = { + 'mm1.py': 1, 'adxl345.py': 3, 'am1.py': 2, 'hm1.py': 1, diff --git a/software/release/all/mm1.py b/software/release/all/mm1.py new file mode 100644 index 0000000..c58fd66 --- /dev/null +++ b/software/release/all/mm1.py @@ -0,0 +1,31 @@ +import uasyncio as asyncio +import time + +try: # ensure networking is available + networking +except NameError: + from config import networking as networking + +from config import hive_config + +print("running mm1.py") + +async def heartbeat_loop(): + while hive_config["hive"]: + print("heartbeat") + if hive_config["recipients"]: + test_data = { + "test": 42, + "time_sent": time.ticks_ms() + } + networking.send_data(hive_config["recipients"], test_data) + + recv_sensor_data = networking.return_data() + for mac, data in recv_sensor_data.items(): + print(f"Received from {mac}: {data}") + + await asyncio.sleep(hive_config["refreshrate"] / 1000) + + +if hive_config["hive"]: + asyncio.run(heartbeat_loop()) diff --git a/software/release/am1/boot.py b/software/release/am1/boot.py index bd1ddd1..50e1da5 100644 --- a/software/release/am1/boot.py +++ b/software/release/am1/boot.py @@ -10,8 +10,6 @@ except Exception as e: print(f"Error {e}") -module_name = config.config["configuration"].lower() - import gc gc.collect() @@ -60,8 +58,8 @@ def deinit(): machine.reset() try: - with open(module_name + ".py") as f: + with open(config.config["configuration"].lower() + ".py") as f: code = f.read() exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) except Exception as e: - print(f"Error running {module_name}: {e}") + print(f"Error running {config.config['configuration']}: {e}") diff --git a/software/release/am1/config.py b/software/release/am1/config.py index af9b471..7562469 100644 --- a/software/release/am1/config.py +++ b/software/release/am1/config.py @@ -1,5 +1,6 @@ -config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': None, 'sta_channel': 1, 'type': None, 'version': '2025-10-14-133223'} +config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': 'AM1', 'sta_channel': 1, 'type': None, 'version': '2025-10-14-161439'} version = { + 'mm1.py': 1, 'adxl345.py': 3, 'am1.py': 2, 'hm1.py': 1, diff --git a/software/release/hm3/boot.py b/software/release/hm3/boot.py index bd1ddd1..50e1da5 100644 --- a/software/release/hm3/boot.py +++ b/software/release/hm3/boot.py @@ -10,8 +10,6 @@ except Exception as e: print(f"Error {e}") -module_name = config.config["configuration"].lower() - import gc gc.collect() @@ -60,8 +58,8 @@ def deinit(): machine.reset() try: - with open(module_name + ".py") as f: + with open(config.config["configuration"].lower() + ".py") as f: code = f.read() exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) except Exception as e: - print(f"Error running {module_name}: {e}") + print(f"Error running {config.config['configuration']}: {e}") diff --git a/software/release/hm3/config.py b/software/release/hm3/config.py index af9b471..20f2382 100644 --- a/software/release/hm3/config.py +++ b/software/release/hm3/config.py @@ -1,5 +1,6 @@ -config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': None, 'sta_channel': 1, 'type': None, 'version': '2025-10-14-133223'} +config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': 'HM3', 'sta_channel': 1, 'type': None, 'version': '2025-10-14-161439'} version = { + 'mm1.py': 1, 'adxl345.py': 3, 'am1.py': 2, 'hm1.py': 1, diff --git a/software/release/mm1/README.md b/software/release/mm1/README.md index 2d3669d..a4c6e68 100644 --- a/software/release/mm1/README.md +++ b/software/release/mm1/README.md @@ -19,6 +19,7 @@ The repository has the following directory tree. ├── boot.py ├── config.py ├── main.py + ├── mm1.py ├── networking.py └── ssp_networking.py @@ -29,5 +30,6 @@ A short description of the files can be found below. | config.py | Smart Module Configuration File | Nick | | boot.py | Smart Module boot.py | Nick | | main.py | Smart Module main.py | Nick | +| mm1.py | Module module main program | Nick | | networking.py | This is the main networking code that builds on ESP-NOW. There are many prepared functionalities (and some more that I am working on), such as long message support, sending of various variable types (bytes, bytearray, dicts, lists, int, float, char, string), as well as different types of messages such as ping, echo and more. There are also various features in place to make the networking more robust. | Nick | | ssp_networking.py | This is the ssp networking module. It needs config.py to function. | Nick | diff --git a/software/release/mm1/boot.py b/software/release/mm1/boot.py index bd1ddd1..50e1da5 100644 --- a/software/release/mm1/boot.py +++ b/software/release/mm1/boot.py @@ -10,8 +10,6 @@ except Exception as e: print(f"Error {e}") -module_name = config.config["configuration"].lower() - import gc gc.collect() @@ -60,8 +58,8 @@ def deinit(): machine.reset() try: - with open(module_name + ".py") as f: + with open(config.config["configuration"].lower() + ".py") as f: code = f.read() exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) except Exception as e: - print(f"Error running {module_name}: {e}") + print(f"Error running {config.config['configuration']}: {e}") diff --git a/software/release/mm1/config.py b/software/release/mm1/config.py index af9b471..0008f48 100644 --- a/software/release/mm1/config.py +++ b/software/release/mm1/config.py @@ -1,5 +1,6 @@ -config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': None, 'sta_channel': 1, 'type': None, 'version': '2025-10-14-133223'} +config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': 'MM1', 'sta_channel': 1, 'type': None, 'version': '2025-10-14-161439'} version = { + 'mm1.py': 1, 'adxl345.py': 3, 'am1.py': 2, 'hm1.py': 1, diff --git a/software/release/mm1/mm1.py b/software/release/mm1/mm1.py new file mode 100644 index 0000000..c58fd66 --- /dev/null +++ b/software/release/mm1/mm1.py @@ -0,0 +1,31 @@ +import uasyncio as asyncio +import time + +try: # ensure networking is available + networking +except NameError: + from config import networking as networking + +from config import hive_config + +print("running mm1.py") + +async def heartbeat_loop(): + while hive_config["hive"]: + print("heartbeat") + if hive_config["recipients"]: + test_data = { + "test": 42, + "time_sent": time.ticks_ms() + } + networking.send_data(hive_config["recipients"], test_data) + + recv_sensor_data = networking.return_data() + for mac, data in recv_sensor_data.items(): + print(f"Received from {mac}: {data}") + + await asyncio.sleep(hive_config["refreshrate"] / 1000) + + +if hive_config["hive"]: + asyncio.run(heartbeat_loop()) diff --git a/software/release/sl1/boot.py b/software/release/sl1/boot.py index bd1ddd1..50e1da5 100644 --- a/software/release/sl1/boot.py +++ b/software/release/sl1/boot.py @@ -10,8 +10,6 @@ except Exception as e: print(f"Error {e}") -module_name = config.config["configuration"].lower() - import gc gc.collect() @@ -60,8 +58,8 @@ def deinit(): machine.reset() try: - with open(module_name + ".py") as f: + with open(config.config["configuration"].lower() + ".py") as f: code = f.read() exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) except Exception as e: - print(f"Error running {module_name}: {e}") + print(f"Error running {config.config['configuration']}: {e}") diff --git a/software/release/sl1/config.py b/software/release/sl1/config.py index af9b471..f9ef44f 100644 --- a/software/release/sl1/config.py +++ b/software/release/sl1/config.py @@ -1,5 +1,6 @@ -config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': None, 'sta_channel': 1, 'type': None, 'version': '2025-10-14-133223'} +config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': 'SL1', 'sta_channel': 1, 'type': None, 'version': '2025-10-14-161439'} version = { + 'mm1.py': 1, 'adxl345.py': 3, 'am1.py': 2, 'hm1.py': 1, diff --git a/software/release/sp1/boot.py b/software/release/sp1/boot.py index bd1ddd1..50e1da5 100644 --- a/software/release/sp1/boot.py +++ b/software/release/sp1/boot.py @@ -10,8 +10,6 @@ except Exception as e: print(f"Error {e}") -module_name = config.config["configuration"].lower() - import gc gc.collect() @@ -60,8 +58,8 @@ def deinit(): machine.reset() try: - with open(module_name + ".py") as f: + with open(config.config["configuration"].lower() + ".py") as f: code = f.read() exec(code, {"networking": networking, "configuration": configuration, "__name__": "__main__"}) except Exception as e: - print(f"Error running {module_name}: {e}") + print(f"Error running {config.config['configuration']}: {e}") diff --git a/software/release/sp1/config.py b/software/release/sp1/config.py index af9b471..1c167f7 100644 --- a/software/release/sp1/config.py +++ b/software/release/sp1/config.py @@ -1,5 +1,6 @@ -config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': None, 'sta_channel': 1, 'type': None, 'version': '2025-10-14-133223'} +config = {'ap_channel': 1, 'id': None, 'name': 'Nick', 'sta_mac': None, 'ap_mac': None, 'configuration': 'SP1', 'sta_channel': 1, 'type': None, 'version': '2025-10-14-161439'} version = { + 'mm1.py': 1, 'adxl345.py': 3, 'am1.py': 2, 'hm1.py': 1,