Move espnow to seperate file
This commit is contained in:
parent
279416cded
commit
524db5e979
14
src/main.py
14
src/main.py
|
@ -9,6 +9,7 @@ import machine
|
||||||
import time
|
import time
|
||||||
import wifi
|
import wifi
|
||||||
import json
|
import json
|
||||||
|
from p2p import p2p
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
@ -26,17 +27,6 @@ async def main():
|
||||||
patterns.tick()
|
patterns.tick()
|
||||||
await asyncio.sleep_ms(1)
|
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:
|
|
||||||
data = json.loads(msg)
|
|
||||||
#print(data)
|
|
||||||
if "ids" not in data or settings["id"] in data["ids"]:
|
|
||||||
settings.set_settings(data["settings"], patterns, data.get("save", False))
|
|
||||||
print("should not print")
|
|
||||||
|
|
||||||
async def wifi_connect():
|
async def wifi_connect():
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
config = wifi.connect(settings.get("wifi_ssid", ""),
|
config = wifi.connect(settings.get("wifi_ssid", ""),
|
||||||
|
@ -60,7 +50,7 @@ async def main():
|
||||||
|
|
||||||
#asyncio.create_task(wifi_connect())
|
#asyncio.create_task(wifi_connect())
|
||||||
asyncio.create_task(tick())
|
asyncio.create_task(tick())
|
||||||
asyncio.create_task(espnow())
|
asyncio.create_task(p2p(settings, patterns))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import asyncio
|
||||||
|
import aioespnow
|
||||||
|
import json
|
||||||
|
|
||||||
|
async def p2p(settings, patterns):
|
||||||
|
e = aioespnow.AIOESPNow() # Returns AIOESPNow enhanced with async support
|
||||||
|
e.active(True)
|
||||||
|
async for mac, msg in e:
|
||||||
|
try:
|
||||||
|
data = json.loads(msg)
|
||||||
|
except:
|
||||||
|
print(f"Failed to load espnow data {msg}")
|
||||||
|
continue
|
||||||
|
#print(data)
|
||||||
|
if "ids" not in data or settings.get("id") in data.get("ids", []):
|
||||||
|
settings.set_settings(data.get("settings", {}), patterns, data.get("save", False))
|
||||||
|
print("should not print")
|
Loading…
Reference in New Issue