diff --git a/.DS_Store b/.DS_Store index 57e317e..7bf9595 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/software/.DS_Store b/software/.DS_Store index 475298e..62e3246 100644 Binary files a/software/.DS_Store and b/software/.DS_Store differ diff --git a/software/main/.DS_Store b/software/main/.DS_Store index dffefc3..b084c50 100644 Binary files a/software/main/.DS_Store and b/software/main/.DS_Store differ diff --git a/software/main/.idea/.name b/software/main/.idea/.name index 11a5d8e..d8613ef 100644 --- a/software/main/.idea/.name +++ b/software/main/.idea/.name @@ -1 +1 @@ -main.py \ No newline at end of file +am1.py \ No newline at end of file diff --git a/software/main/boot.py b/software/main/boot.py index 4f6b5d7..10fe88d 100644 --- a/software/main/boot.py +++ b/software/main/boot.py @@ -1,7 +1,7 @@ from machine import Pin import machine from config import config - +import time import gc gc.collect() @@ -22,20 +22,17 @@ # Network infmsg = True -dbgmsg = True +dbgmsg = False errmsg = True +global timer +peer_mac = b'\xff\xff\xff\xff\xff\xff' configuration = config["configuration"] +hive = config["hive"] if configuration == "AM1": infmsg = True networking = SSP_Networking(infmsg, dbgmsg, errmsg) -peer_mac = b'\xff\xff\xff\xff\xff\xff' - -import time - -global timer - print("{:.3f} Name: {}, ID: {}, Configuration: {}, Sta mac: {}, Ap mac: {}, Version: {}".format( (time.ticks_ms() - networking.inittime) / 1000, networking.config["name"], @@ -46,9 +43,8 @@ networking.config["version"] )) -if configuration == "AM1": +def idle(): lastPressed = 0 - message = "Boop!" def boop(pin): @@ -66,23 +62,38 @@ def boop(pin): switch_select = Pin(9, Pin.IN, Pin.PULL_UP) switch_select.irq(trigger=Pin.IRQ_FALLING, handler=boop) - def heartbeat(timer): print("") print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool Heartbeat: {gc.mem_free()} bytes") print("") gc.collect() - timer = machine.Timer(0) timer.init(period=5000, mode=machine.Timer.PERIODIC, callback=heartbeat) - -def deinit(): - networking.cleanup() +def run_config_module(module_name): try: - timer.deinit() + with open(module_name + ".py") as f: + code = f.read() + exec(code) except Exception as e: - print(e) - machine.reset() + print(f"Error running {module_name}: {e}") + +# cases for different configurations +if not hive: + if configuration == "AM1": + print("am1") + idle() + elif configuration == "SM3": + print("sm3") + run_config_module("sm3") + elif configuration == "SL1": + print("sl1") + run_config_module("sl1") + else: + print("idle") + idle() +else: + run_config_module("hm1") + # insert code here to run in case of hive motor! diff --git a/software/main/hm1.py b/software/main/hm1.py new file mode 100644 index 0000000..139597f --- /dev/null +++ b/software/main/hm1.py @@ -0,0 +1,2 @@ + + diff --git a/software/main/main.py b/software/main/main.py deleted file mode 100644 index f067d0f..0000000 --- a/software/main/main.py +++ /dev/null @@ -1,112 +0,0 @@ -from machine import Pin -import machine -from config import config - -import gc - -gc.collect() - -import network - -print("Running boot.py") - -# just to be safe -sta = network.WLAN(network.STA_IF) -ap = network.WLAN(network.AP_IF) -sta.active(True) -ap.active(True) -sta.active(False) -ap.active(False) - -from ssp_networking import SSP_Networking - -# Network -infmsg = True -dbgmsg = False -errmsg = True -configuration = config["configuration"] -if configuration == "AM1": - infmsg = True - -networking = SSP_Networking(infmsg, dbgmsg, errmsg) - -peer_mac = b'\xff\xff\xff\xff\xff\xff' - -import time - -global timer - -print("{:.3f} Name: {}, ID: {}, Configuration: {}, Sta mac: {}, Ap mac: {}, Version: {}".format( - (time.ticks_ms() - networking.inittime) / 1000, - networking.config["name"], - networking.config["id"], - networking.config["configuration"], - networking.config["ap_mac"], - networking.config["sta_mac"], - networking.config["version"] -)) - - - -lastPressed = 0 - -def idle(): - - message = "Boop!" - - def boop(pin): - global lastPressed - if (time.ticks_ms() - lastPressed > 1000): - lastPressed = time.ticks_ms() - networking.ping(peer_mac) - networking.echo(peer_mac, message) - networking.send(peer_mac, message) - print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool: Sent {message} to {peer_mac}") - print( - f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool: RSSI table: {networking.rssi()}") - - # Buttons - switch_select = Pin(9, Pin.IN, Pin.PULL_UP) - switch_select.irq(trigger=Pin.IRQ_FALLING, handler=boop) - - - def heartbeat(timer): - print("") - print(f"{(time.ticks_ms() - networking.inittime) / 1000:.3f} Networking Tool Heartbeat: {gc.mem_free()} bytes") - print("") - gc.collect() - - - timer = machine.Timer(0) - timer.init(period=5000, mode=machine.Timer.PERIODIC, callback=heartbeat) - - -def deinit(): - networking.cleanup() - try: - timer.deinit() - except Exception as e: - print(e) - machine.reset() - -def run_config_module(module_name): - try: - with open(module_name + ".py") as f: - code = f.read() - exec(code) - except Exception as e: - print(f"Error running {module_name}: {e}") - -# cases for different configurations -if configuration == "AM1": - print("idle") - idle() -elif configuration == "S M3": - print("sm3") - run_config_module("sm3") -elif configuration == "SL1": - print("sl1") - run_config_module("sl1") -else: - print("idle") - idle() diff --git a/software/release/README.qmd b/software/release/README.qmd index 9f8142b..bae1050 100644 --- a/software/release/README.qmd +++ b/software/release/README.qmd @@ -36,7 +36,11 @@ A short description of the directories can be found below. | name | description | contribution | |--------------|-----------------------------------------|--------------| | release/config.py | Smart Module Configuration File | Nick | -| main/main.py | Smart Module Main.py | Nick | +| main/boot.py | Smart Module boot.py | Nick | +| main/main.py | Smart Module main.py | Nick | +| main/hm1.py | Smart hive program | Nick | +| main/sl1.py | Smart light module main program | Milan | +| main/sm3.py | Smart motor module main program | Milan | | networking/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 | | networking/ssp_networking.py | This is the ssp networking module. It needs config.py to function. | Nick | | libraries/adxl345.py | Support for the built in accelerometer https://github.com/DFRobot/micropython-dflib/blob/master/ADXL345/user_lib/ADXL345.py | Milan | @@ -45,7 +49,5 @@ A short description of the directories can be found below. | libraries/sensors.py | Sensor support for the smart motor module | Milan | | libraries/servo.py | Servo support for the smart motor module | Milan | | libraries/smartlight.py | Smart light support for smart light module | Milan | -| main/sl1.py | Smart light module main program | Milan | -| main/sm3.py | Smart motor module main program | Milan | | libraries/ssd1306.py | Support for the built in OLED screen https://github.com/stlehmann/micropython-ssd1306/blob/master/ssd1306.py | Milan | | libraries/variableLED.py | Library that powers the variable LED grid | Sophie | diff --git a/software/release/config.py b/software/release/config.py index c342527..76a52f1 100644 --- a/software/release/config.py +++ b/software/release/config.py @@ -1,11 +1,12 @@ config = { "name": "Nickname", "configuration": "AM1", + "hive": False, "id": None, "version": None } version = {'adxl345.py': 3, - 'ssp_networking.py': 1, + 'ssp_networking.py': 1, 'files.py': 2, 'icons.py': 2, 'prefs.py': 2, @@ -15,8 +16,8 @@ 'sm3.py': 1, 'sl1.py': 1, 'smartlight.py': 1, -'networking.py': 3, -'main.py': 1, + 'networking.py': 3, + 'main.py': 1, 'boot.py': 0 } mysecrets = {"SSID": "Tufts_Robot", "key": ""}