diff --git a/src/main.py b/src/main.py index 6e2a194..abb821e 100644 --- a/src/main.py +++ b/src/main.py @@ -26,14 +26,15 @@ async def main(): patterns.tick() await asyncio.sleep_ms(1) + async def espnow(): e = aioespnow.AIOESPNow() # Returns AIOESPNow enhanced with async support e.active(True) async for mac, msg in e: - print(msg) data = json.loads(msg) - - settings.set_settings(data, patterns) + print(data) + if settings["id"] in data["ids"]: + settings.set_settings(data["settings"], patterns) print("should not print") async def wifi_connect(): diff --git a/src/settings.py b/src/settings.py index 4c314d3..4c4e7ab 100644 --- a/src/settings.py +++ b/src/settings.py @@ -27,6 +27,7 @@ class Settings(dict): self["wifi_password"] = "" self["wifi_ip"] = "" self["wifi_gateway"] = "" + self["id"] = 0 def save(self): try: @@ -75,6 +76,8 @@ class Settings(dict): elif key == "color_order": if value == "rbg": self.color_order = (1, 5, 3) else: self.color_order = (1, 3, 5) + elif key == "id": + pass else: return "Invalid key", 400 self[key] = value diff --git a/src/static/main.js b/src/static/main.js index da7c0a9..5ec7d59 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -150,6 +150,12 @@ async function updateName(event) { sendWebSocketData({ name: name }); } +async function updateID(event) { + event.preventDefault(); + const id = document.getElementById("id").value; + sendWebSocketData({ id: parseInt(id) }); +} + function createPatternButtons(patterns) { const container = document.getElementById("pattern_buttons"); container.innerHTML = ""; // Clear previous buttons @@ -184,6 +190,7 @@ document.addEventListener("DOMContentLoaded", async function () { .getElementById("num_leds_form") .addEventListener("submit", updateNumLeds); document.getElementById("name_form").addEventListener("submit", updateName); + document.getElementById("id_form").addEventListener("submit", updateID); document.getElementById("delay").addEventListener("touchend", updateDelay); document .getElementById("brightness") diff --git a/src/templates/index.html b/src/templates/index.html index 31c67dc..51c9daf 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -79,6 +79,16 @@ /> +
+ + + +