Exemplo n.º 1
0
def await_network():
    while True:
        easywifi.enable()
        if easywifi.state:
            break
        show('No internet!')
        badge.eink_busy_wait()
        show('Checking connection...', speed='fast')
Exemplo n.º 2
0
def main():
    easywifi.enable()
    for site in SITES:
        opts = {}
        if isinstance(site, dict):
            opts = site
            site = opts["host"]

        try:
            test_one(site, opts)
            print(site, "ok")
        except Exception as e:
            print(site, repr(e))
Exemplo n.º 3
0
def install():
    easydraw.msg("Installing resources...")
    if not easywifi.status():
        if not easywifi.enable():
            return False
    import woezel
    woezel.install("resources")
    appglue.home()
Exemplo n.º 4
0
def install():
    if not easywifi.status():
        if not easywifi.enable():
            return False
    print("[SPONSORS] Installing...")
    easydraw.msg("Installing sponsors...")
    import woezel
    woezel.install("sponsors")
    easydraw.msg("OK")
Exemplo n.º 5
0
def configure():
    import easywifi
    import easydraw
    import ntp
    if not easywifi.status():
        if not easywifi.enable():
            return False
    easydraw.msg("Configuring clock...")
    ntp.set_NTP_time()
    easydraw.msg("Done")
    return True
Exemplo n.º 6
0
def available(update=False):
    if update:
        if not easywifi.status():
            if not easywifi.enable():
                return badge.nvs_get_u8('badge', 'OTA.ready', 0)

        info = download_info()
        if info:
            if info["build"] > version.build:
                badge.nvs_set_u8('badge', 'OTA.ready', 1)
                return True

        badge.nvs_set_u8('badge', 'OTA.ready', 0)
    return badge.nvs_get_u8('badge', 'OTA.ready', 0)
Exemplo n.º 7
0
import ugfx, woezel, easywifi, easydraw, appglue, time, os


def stop():
    time.sleep(2)
    appglue.start_app("launcher")


easydraw.msg("Welcome!", "Updating...", True)

if not easywifi.status():
    if not easywifi.enable():
        stop()

try:
    apps = os.listdir('lib')
except OSError:
    easydraw.msg("There are no apps installed.")
    stop()

for app in apps:
    easydraw.msg("Updating '" + app + "'...")
    try:
        woezel.install(app)
        easydraw.msg("Done!")
    except:
        print("failed update. Already newest version?")

easydraw.msg("All your apps are now up-to-date!")
stop()
Exemplo n.º 8
0
def setup(drawCb=None):
    global services
    global drawCallbacks

    if drawCb:
        print("[SERVICES] Draw callback registered")
        global drawCallback
        drawCallback = drawCb  #This might need a better name...

    # Status of wifi
    wifiFailed = False

    #Check if lib folder exists and get application list, else stop
    try:
        apps = uos.listdir('lib')
    except OSError:
        return [False, False]

    #For each app...
    for app in apps:
        print("APP: " + app)
        try:
            #Try to open and read the json description
            fd = open('/lib/' + app + '/service.json')
            description = ujson.loads(fd.read())
            fd.close()
        except:
            print("[SERVICES] No description found for " + app)
            continue  #Or skip the app

        try:
            #Try to open the service itself
            fd = open('/lib/' + app + '/service.py')
            fd.close()
        except:
            print("[SERVICES] No script found for " + app)
            continue  #Or skip the app

        rtcRequired = False  # True if RTC should be set before starting service
        loopEnabled = False  # True if loop callback is requested
        drawEnabled = False  # True if draw callback is requested

        wifiInSetup = False  # True if wifi needed in setup
        wifiInLoop = False  # True if wifi needed in loop

        try:
            if description['apiVersion'] != 2:
                print("[SERVICES] Service for " + app +
                      " is not compatible with current firmware")
                continue  #Skip the app
            wifiInSetup = description['wifi']['setup']
            wifiInLoop = description['wifi']['setup']
            rtcRequired = description['rtc']
            loopEnabled = description['loop']
            drawEnabled = description['draw']
        except:
            print("[SERVICES] Could not parse description of app " + app)
            continue  #Skip the app

        print("[SERVICES] Found service for " + app)

        # Import the service.py script
        try:
            srv = __import__('lib/' + app + '/service')
        except BaseException as e:
            print("[SERVICES] Could not import service of app " + app + ": ")
            sys.print_exception(e)
            continue  #Skip the app

        if wifiInSetup or wifiInLoop:
            if wifiFailed:
                print(
                    "[SERVICES] Service of app " + app +
                    " requires wifi and wifi failed so the service has been disabled."
                )
                continue
            if not easywifi.status():
                if not easywifi.enable():
                    wifiFailed = True
                    print("[SERVICES] Could not connect to wifi!")
                    continue  # Skip the app

        if rtcRequired and time.time() < 1482192000:
            if not wifiFailed:
                print("[SERVICES] RTC required, configuring...")
                easyrtc.configure()
            else:
                print(
                    "[SERVICES] RTC required but not available. Skipping service."
                )
                continue  # Skip the app (because wifi failed and rtc not available)

        try:
            srv.setup()
        except BaseException as e:
            print("[SERVICES] Exception in service setup " + app + ":")
            sys.print_exception(e)
            continue

        if loopEnabled:
            try:
                virtualtimers.new(1, srv.loop)
            except:
                print("[SERVICES] Loop requested but not defined in service " +
                      app)

        if drawEnabled and drawCb:
            drawCallbacks.append(srv)

        # Add the script to the global service list
        services.append(srv)

    handleDraw = False
    if len(drawCallbacks) > 0 and drawCb:
        print("[SERVICES] The service subsystem now handles screen redraws")
        handleDraw = True
        virtualtimers.new(1, draw_task, True)
    return handleDraw
def init():
    badge.init()
    ugfx.init()
    easywifi.enable()
    easyrtc.configure()
    clear_screen()
Exemplo n.º 10
0
import easywifi
import time
import machine
import gc
import time
from umqtt.simple import MQTTClient

state="CLOSED"
oldstate=state
oldtest=-1
pin=machine.Pin(33,machine.Pin.IN,machine.Pin.PULL_UP)

def test():
    return pin.value()

X=MQTTClient("openlabs42","clamans.mobach.de")
while True:
    thetest = test()
    if oldtest != thetest:
        easywifi.enable()
        X.connect()
        oldtest = thetest
        state = "CLOSED" if thetest == 1 else "OPEN"
        X.publish("openlabs/state/state",state,1)
        ugfx.clear(ugfx.WHITE if state=="OPEN" else ugfx.BLACK)
        ugfx.string_box(0,45,296,38, state, "PermanentMarker36", ugfx.BLACK if state=="OPEN" else ugfx.WHITE, ugfx.justifyCenter)
        ugfx.flush(ugfx.LUT_FULL)
        X.disconnect()
        easywifi.disable()
    time.sleep(1)