def render(): rgb.clear() rgb.background((0, 0, 0)) for x, y in snake: rgb.pixel((255, 255, 255), (x, y)) rgb.pixel((0, 255, 200), food)
def draw_text(): global l, color rgb.clear() if l: rgb.pixel((0, 150, 0), (REFRESH_RATE, 7)) # green for new data for i, d in enumerate(l): rgb.text(d, colors[color][i], (ceil(31 / len(l)) * i, 0)) else: rgb.text('E Data')
def connect_wifi(): rgb.pixel((255, 255, 0), (31, 0)) # yellow connecting to wifi if not wifi.status(): wifi.connect() if wifi.wait(): rgb.pixel((0, 255, 0), (31, 0)) # green for wifi rgb.framerate(20) else: rgb.clear() rgb.framerate(20) data, frames = icon_no_wifi rgb.image(data, (12, 0), (8, 8)) time.sleep(3) rgb.clear() machine.reboot()
def disconnect_wifi(): if wifi.status(): wifi.disconnect() rgb.pixel((255, 0, 0), (31, 0)) # red for no wifi
global action if pressed: action = defines.BTN_DOWN buttons.register(defines.BTN_B, input_B) buttons.register(defines.BTN_UP, input_up) buttons.register(defines.BTN_DOWN, input_down) gc.collect() while True: if tick < REFRESH_RATE: gc.collect() sleep(0.1) rgb.pixel((150, 150, 0), (int(round(tick)), 7)) tick += 1 continue else: tick = 0 try: connect_wifi() print('retrieving result') result = urequests.get(WEATHER_API_SERVER) disconnect_wifi() if result.status_code == 200: rgb.pixel((0, 255, 0), (31, 7)) # green for new data try: print(gc.mem_free()) weather = result.json()
def draw_error(e): rgb.clear() rgb.pixel((255, 0, 0), (REFRESH_RATE, 7)) # red for error rgb.text('E {}'.format(e))
if not wifi.status(): if not uinterface.connect_wifi(): system.reboot() rgb.text('Hi!') # main loop count = REFRESH_RATE - 1 # start fast while True: if not wifi.status(): if not uinterface.connect_wifi(): system.reboot() if count < REFRESH_RATE and stat == old_stat: gc.collect() sleep(0.1) rgb.pixel((150, 150, 0), (count, 7)) # refresh counter count += 1 continue else: count = 0 old_stat = stat if stat == 0: # generator try: r = urequests.post( "https://dashboard.eventinfra.org/api/datasources/proxy/1/render", data= 'target=infra.ACT_PWR_1_generator_tot_kva&target=infra.ACT_PWR_2_generator_tot_kva&target=infra.ACT_PWR_3_generator_tot_kva&from=-3min&until=now&format=json&maxDataPoints=768' ) except: draw_error('req') continue