Exemple #1
0
async def wifi_cb(state):
    global outages
    wifi_led(not state)  # Light LED when WiFi down
    if state:
        print('WiFi connected')
    else:
        outages += 1
        print('WiFi or broker is down')
async def wifi_han(state):
    global outages
    wifi_led(not state)  # Light LED when WiFi down
    if state:
        print('We are connected to broker.')
    else:
        outages += 1
        print('WiFi or broker is down.')
    await asyncio.sleep(1)
Exemple #3
0
async def wifi_han(state):
    global outages
    wifi_led(not state)
    if state:
        print('WiFi is up.')
    else:
        outages += 1
        print('WiFi is down.')
    await asyncio.sleep(1)
Exemple #4
0
async def wifi_han(state):
    wifi_led(not state)
    if state:
        print('WiFi is up.')

        import network
        wlan = network.WLAN(network.STA_IF)
        print(wlan.ifconfig())

        import webrepl
        webrepl.start()

        sync_time()
    else:
        print('WiFi is down.')
    await asyncio.sleep(1)
async def wifi_han(state):
    wifi_led(not state)
    print('Wifi is ', 'up' if state else 'down')
    await asyncio.sleep(1)
Exemple #6
0
from mqtt_as import MQTTClient, config
from config import wifi_led, blue_led
import uasyncio as asyncio
import ujson

from state import latest, history

wifi_led(False)
blue_led(False)


def sub_cb(topic, msg, retained):
    sensor = topic.decode()

    print((sensor, msg, retained))

    if type(msg) == int or type(msg) == float:
        data = msg
    else:
        data = ujson.loads(msg)

    if sensor in latest:
        latest[sensor] = data

    if sensor in history:
        history[sensor].append(data)
        if len(history[sensor]) > 15:
            del history[sensor][0]


# ###################################################################### #