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
|
import asyncio
|
||||||
from settings import Settings
|
import aioespnow
|
||||||
|
from settings import Settings, set_settings
|
||||||
from web import web
|
from web import web
|
||||||
from patterns import Patterns
|
from patterns import Patterns
|
||||||
import gc
|
import gc
|
||||||
import utime
|
import utime
|
||||||
import machine
|
import machine
|
||||||
import ntptime
|
|
||||||
import time
|
import time
|
||||||
import wifi
|
import wifi
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
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_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_color2(tuple(int(settings["color2"][i:i+2], 16) for i in (1, 5, 3)))
|
||||||
patterns.set_brightness(int(settings["brightness"]))
|
patterns.set_brightness(int(settings["brightness"]))
|
||||||
|
@ -27,29 +27,34 @@ async def main():
|
||||||
# start the server in a bacakground task
|
# start the server in a bacakground task
|
||||||
print("Starting")
|
print("Starting")
|
||||||
server = asyncio.create_task(w.start_server(host="0.0.0.0", port=80))
|
server = asyncio.create_task(w.start_server(host="0.0.0.0", port=80))
|
||||||
wdt = machine.WDT(timeout=10000)
|
#wdt = machine.WDT(timeout=10000)
|
||||||
wdt.feed()
|
#wdt.feed()
|
||||||
|
|
||||||
async def tick():
|
async def tick():
|
||||||
while True:
|
while True:
|
||||||
patterns.tick()
|
patterns.tick()
|
||||||
await asyncio.sleep_ms(1)
|
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:
|
while True:
|
||||||
|
|
||||||
#print(time.localtime())
|
#print(time.localtime())
|
||||||
|
|
||||||
# gc.collect()
|
# gc.collect()
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
wdt.feed()
|
#wdt.feed()
|
||||||
await asyncio.sleep_ms(500)
|
await asyncio.sleep_ms(500)
|
||||||
|
|
||||||
# cleanup before ending the application
|
# cleanup before ending the application
|
||||||
await server
|
await server
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue