Add espnow
This commit is contained in:
parent
ed3351a20b
commit
0aa3803f20
29
src/main.py
29
src/main.py
|
@ -1,22 +1,22 @@
|
|||
import asyncio
|
||||
from settings import Settings
|
||||
import aioespnow
|
||||
from settings import Settings, set_settings
|
||||
from web import web
|
||||
from patterns import Patterns
|
||||
import gc
|
||||
import utime
|
||||
import machine
|
||||
import ntptime
|
||||
import time
|
||||
import wifi
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
||||
patterns = Patterns(4, settings["num_leds"], selected=settings["selected_pattern"])
|
||||
patterns = Patterns(4, settings["num_leds"], selected=settings["pattern"])
|
||||
patterns.set_color1(tuple(int(settings["color1"][i:i+2], 16) for i in (1, 5, 3)))
|
||||
patterns.set_color2(tuple(int(settings["color2"][i:i+2], 16) for i in (1, 5, 3)))
|
||||
patterns.set_brightness(int(settings["brightness"]))
|
||||
|
@ -27,29 +27,34 @@ async def main():
|
|||
# start the server in a bacakground task
|
||||
print("Starting")
|
||||
server = asyncio.create_task(w.start_server(host="0.0.0.0", port=80))
|
||||
wdt = machine.WDT(timeout=10000)
|
||||
wdt.feed()
|
||||
#wdt = machine.WDT(timeout=10000)
|
||||
#wdt.feed()
|
||||
|
||||
async def tick():
|
||||
while True:
|
||||
patterns.tick()
|
||||
await asyncio.sleep_ms(1)
|
||||
|
||||
asyncio.create_task(tick())
|
||||
async def espnow():
|
||||
e = aioespnow.AIOESPNow() # Returns AIOESPNow enhanced with async support
|
||||
e.active(True)
|
||||
async for mac, msg in e:
|
||||
print(msg)
|
||||
set_settings(msg, settings, patterns)
|
||||
|
||||
first = True
|
||||
asyncio.create_task(tick())
|
||||
asyncio.create_task(espnow())
|
||||
|
||||
while True:
|
||||
|
||||
#print(time.localtime())
|
||||
|
||||
|
||||
# gc.collect()
|
||||
for i in range(60):
|
||||
wdt.feed()
|
||||
#wdt.feed()
|
||||
await asyncio.sleep_ms(500)
|
||||
|
||||
# cleanup before ending the application
|
||||
await server
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue