Beispiel #1
0
def update_cache():
    last_update = get_last_updated()
    if last_update > 0 and utime.time() < last_update + (600):
        global activities
        try:
            filestream = open(cache_path + cache_file, 'r')
            activities = sorted(ujson.load(filestream),
                                key=lambda x: int(x['time']))
            filestream.close()
            parse_activities()
        except:
            print("Err reading")
        return True
    print("Update required")
    try:
        os.mkdir(cache_path)
    except:
        pass

    print('Updating activities cache..')
    if not wifi.status():
        uinterface.connect_wifi()
        if not wifi.wait():
            print("Failed to connect to WiFi.")
            return False

    show_progress("Downloading activities...")
    try:
        request = urequests.get(url, timeout=5)
        show_progress("Saving activities...")
        with open(cache_path + cache_file, 'w') as activities_file:
            activities_file.write(request.text)
        request.close()

        show_progress("Parsing activities...")
        global activities
        filestream = open(cache_path + cache_file, 'r')
        activities = sorted(ujson.load(filestream),
                            key=lambda x: int(x['time']))
        filestream.close()
        parse_activities()
        set_last_updated()
        show_progress("Done!")
        gc.collect()
        return True
    except BaseException as e:
        sys.print_exception(e)
        show_progress("Failed!")
        gc.collect()
    return False
Beispiel #2
0
  def switch(self, type):
    if not badgehelper.on_badge():
      return True

    if type == GAME_HOST_NETWORK_TYPE_NORMAL or type == GAME_CLIENT_NETWORK_TYPE_NORMAL:
      if not wifi.status():
        print("Connecting to Wi-Fi...")
        return uinterface.connect_wifi()
    elif type == GAME_HOST_NETWORK_TYPE_HOTSPOT:
      # define unique hotspot
      return wifi_extended.hotspot_setup(GAME_NETWORK_TYPE_HOTSPOT_SSID, GAME_NETWORK_TYPE_HOTSPOT_CHANNEL, GAME_NETWORK_TYPE_HOTSPOT_HIDDEN, GAME_NETWORK_TYPE_HOTSPOT_PASSWD, GAME_NETWORK_TYPE_HOTSPOT_AUTHMODE, True)
    elif type == GAME_CLIENT_NETWORK_TYPE_HOTSPOT:
      return wifi_extended.hotspot_connect(GAME_NETWORK_TYPE_HOTSPOT_SSID, GAME_NETWORK_TYPE_HOTSPOT_PASSWD, True)

    pass
def _retrieve_latest_update():
    if not connect_wifi():
        raise ValueError("No WiFi connection")
    try:
        _show_progress("Checking for updates")
        gc.collect()
        ota_version_url = 'https://' + consts.OTA_WEB_SERVER + ':' + consts.OTA_WEB_PORT.replace(
            '"', '') + '/' + consts.OTA_WEB_VERSION_PATH
        request = requests.get(ota_version_url, timeout=10)
        result = request.json()
        request.close()
        update_information = {"name": result["name"], "build": result["build"]}
        return update_information
    except Exception as e:
        raise Exception("Update check failed")
    buttons.register(defines.BTN_UP, input_up)
    buttons.register(defines.BTN_DOWN, input_down)
    buttons.register(defines.BTN_LEFT, input_left)
    buttons.register(defines.BTN_RIGHT, input_right)

    populate_apps()
    render_current_app()


start()
init_power_management()

# Install CZ countdown app to replace activities app
if not machine.nvs_getint('system', 'czcount_inst'):
    import uinterface
    if uinterface.connect_wifi():
        import woezel
        uinterface.loading_text('Installing CZ20 countdown')
        if woezel.is_installed('campzone_2020_countdown') or woezel.install(
                'campzone_2020_countdown'):
            machine.nvs_setint('system', 'czcount_inst', 1)
            system.reboot()
        else:
            rgb.clear()
            uinterface.skippabletext('Installation failed')

    render_current_app()

menu = term_menu.UartMenu(deepsleep.start_sleeping, pm)
menu.main()
import woezel, rgb, uinterface, machine, system, gc


def install(app_name):
    machine.nvs_setstr('uinstaller', 'to_install', app_name)
    system.start('uinstaller')


if system.__current_app__ == 'uinstaller':
    to_install = machine.nvs_getstr('uinstaller', 'to_install')
    machine.nvs_setstr('uinstaller', 'to_install', '')
    print('Installing %s' % to_install)
    if not to_install:
        system.reboot()

    if not uinterface.connect_wifi():
        system.reboot()

    rgb.clear()
    uinterface.loading_text('Installing %s' % to_install)
    gc.collect()
    if woezel.install(to_install):
        # Reset launcher's selected index to newly installed app
        machine.nvs_setint('launcher', 'index', 0)
        rgb.clear()
        uinterface.skippabletext('Install succeeded')
    else:
        rgb.clear()
        uinterface.skippabletext('Failed to install "%s"' % to_install)

    system.reboot()
Beispiel #6
0
def connect_wifi(duration=None):
    return uinterface.connect_wifi(duration)