def set_nickname(): rgb.clear() uinterface.skippabletext('Set nickname:') new_name = uinterface.text_input() if new_name is not None and new_name != '': machine.nvs_setstr('badge', 'nickname', new_name) system.start('nickname')
def getToken(self, newToken=False): try: if machine.nvs_getstr(self.tokenKey) is None or newToken: print("Getting a New Token") payload = { "method": "login", "params": { "appType": "Kasa_Android", "cloudUserName": self.username, "cloudPassword": self.password, "terminalUUID": str(uuid.uuid4()) } } _token = requests.post('https://wap.tplinkcloud.com/', json=payload).json()['result']['token'] machine.nvs_setstr(self.tokenKey, _token) self.isTokenPresent = True self.token = _token return _token else: print("Using Stored Token") _token = machine.nvs_getstr(self.tokenKey) self.isTokenPresent = True self.token = _token return machine.nvs_setstr(self.tokenKey, _token) except Exception as e: print(e)
def confirm(nickname): term.header(True, "Nickname setup") machine.nvs_setstr("badge", "nickname", nickname) print("New configuration has been saved.") print("") print("Nickname:\t\t" + nickname) print("Press any key to return to the homescreen") sys.stdin.read(1) system.home(True)
def getAllPara(par=None): params = machine.nvs_getstr('params') if params == None: machine.nvs_setstr('params', '') if par == None: return machine.nvs_getstr('params') else: if machine.nvs_getstr(par) is not None: return machine.nvs_getstr(par).split(',') else: return ''.split(',')
def uninstall(app): if app["category"] == "system": # dialogs.notice("System apps can not be removed!","Can not uninstall '"+currentListTitles[selected]+"'") rgb.clear() uinterface.skippabletext("System apps can't be removed") render_current_app() return machine.nvs_setstr('launcher', 'uninstall_name', app['title']) machine.nvs_setstr('launcher', 'uninstall_file', app['file']) system.start('uninstall')
def passInputDone(password): global chosenSsid machine.nvs_setstr("system", "wifi.ssid", chosenSsid) if password: machine.nvs_setstr("system", "wifi.password", password) else: try: machine.nvs_erase("system", "wifi.password") except: pass easydraw.messageCentered("Settings stored!", True, "/media/ok.png") system.launcher()
def confirm(ssid, password): term.header(True, "WiFi setup") machine.nvs_setstr("system", "wifi.ssid", ssid) machine.nvs_setstr("system", "wifi.password", password) print("New configuration has been saved.") print("") print("SSID:\t\t" + ssid) if len(password) < 1: print("No password") else: print("PASSWORD:\t" + password) print("") print("Press any key to return to the homescreen") sys.stdin.read(1) system.home(True)
def callback(self, info): id = info[0] desc = info[1] info = info[2] if (id == 4): self.ssid = info["ssid"] self.channel = info["channel"] if (self.ssid == self.loginssid): machine.nvs_setstr("wifiSSID", self.loginssid) machine.nvs_setstr("wifiPass", self.loginpass) self.loginssid = None self.loginpass = None elif (id == 5): self.ssid = None self.channel = None
def setPara(key, value): params = machine.nvs_getstr('params') if params == None: machine.nvs_setstr('params', '') params = machine.nvs_getstr('params') if str(key) not in params: params += "," + str(key) machine.nvs_setstr('params', params) machine.nvs_setstr(str(key), str(value))
def onLogin(self, login): machine.nvs_setstr("networkLogin", login)
import machine, system machine.nvs_setstr("system", 'default_app', "") system.eraseStorage()
while True: options = [] for f in pictures: title = f if f == current: title += " [Enabled]" options.append(title) options.append("Default logo") options.append("< Exit") selected = term.menu("Picture", options, 0, "") if selected > len(pictures): system.home(True) if selected == len(pictures): current = None try: machine.nvs_erase("splash", "logo") except: pass term.header(True, "Picture") print("Default picture selected") time.sleep(1) else: current = pictures[selected] machine.nvs_setstr('splash', 'logo', current) term.header(True, "Picture") print("Selected " + current) time.sleep(1)
import woezel, rgb, wifi, uinterface, machine, system, gc, time from default_icons import icon_no_wifi, animation_connecting_wifi 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() ### For some reason normal uinterface.connect_wifi() doesn't ### work from dashboard.terminal.installer, so we have to do this ### odd workaround of connecting twice. wifi.connect() rgb.clear() data, size, frames = animation_connecting_wifi rgb.framerate(3) rgb.gif(data, (12, 0), size, frames) del data, size, frames, animation_connecting_wifi gc.collect() wifi.wait() wifi.connect() wifi.wait()
def install(app_name): machine.nvs_setstr('uinstaller', 'to_install', app_name) system.start('uinstaller')
def onPassword(self, pwd): machine.nvs_setstr("networkPassword", pwd)
def handle_web(): global http_socket try: cl, addr = http_socket.accept() except: return try: print('[HTTP] Client connected from', addr) cl_file = cl.makefile('rwb', 0) print("[HTTP] Processing request 1/2...") request = cl_file.recv(4096).decode("utf-8") print("[HTTP] Processing request 2/2...") request = request.split("\r\n") print("RQ]", request) firstLine = True emptyCount = 0 formData = {} notFound = False for line in request: if line == '': emptyCount += 1 continue if firstLine: if not line.startswith("POST"): if not line.startswith("GET / "): notFound = True break firstLine = False continue if emptyCount > 0: formField = line.split("=") if len(formField) == 2: formData[formField[0]] = formField[1] result = "" if "ssid" in formData or "password" in formData: result += "<pre>" if "ssid" in formData: print("SET SSID", formData["ssid"]) machine.nvs_setstr("system", "wifi.ssid", formData["ssid"]) result += "WiFi SSID set to '{}'.\r\n".format(formData["ssid"]) if "password" in formData: password = formData["password"] if password == "": password = None print("SET PASSWORD", password) if password: machine.nvs_setstr("system", "wifi.password", password) result += "WiFi password set to '{}'.\r\n".format(password) else: try: machine.nvs_erase("system", "wifi.password") except: pass result += "No WiFi password configured, expecting open network.\r\n" if "ssid" in formData or "password" in formData: result += "</pre>" print("[HTTP] Sending response...") if not notFound: response = 'HTTP/1.0 200 OK\r\n\r\n' response += '<!doctype html><html lang="en"><head><meta charset="utf-8"><title>HSNL decennium</title></head>' response += '<style>html, body { padding: 0px; margin: 0px; font-family: Helvetica, Arial, Sans-Serif; background-color: #EEEEEE; }' response += '.header { position: absolute; left: 0px; right: 0px; top: 0px; height: 64px; background-color: #326D10; color: #FFFFFF; font-size: 25px; line-height: 64px; padding-left: 10px;}' response += '.content { padding: 30px; padding-top: 64px; } .right {text-align: right;}</style><body><div class="header">HSNL decennium</div><div class="content">' if (result != ""): response += '<h1>Response</h1>{}<br /><br /><a href="/">Return to the setup screen</a>'.format( result) else: response += '<form action="/" method="post" enctype="text/plain"><h1>Configuration</h1><table width="100%">' ssid = machine.nvs_getstr("system", "wifi.ssid") or '' password = machine.nvs_getstr("system", "wifi.password") or '' response += '<tr><td>WiFi SSID</td><td class="right"><input type="text" name="ssid" id="ssid" value="{}"/></td></tr>'.format( ssid) response += '<tr><td>WiFi password<br /></td><td class="right"><input type="text" name="password" value="{}"/></td></tr>'.format( password) response += '<tr><td> </td><td class="right"><input type="submit" value="Save"></td></tr></table><br /></form>' response += '<i>Leave the WiFi password field empty when connecting to an open network</i><br />' response += '<i>Connecting to enterprise networks is currently not supported!</i><br />' response += '<h1>List of networks</h1>' response += '<i>Click on a name to copy it to the WiFi SSID text field</i><br /><br />' for i in wifiList: ssid = i[0].decode("utf-8") sec = i[5] response += '<a href="javascript:setSsid(\'{}\');">{} [{}]</a><br />'.format( ssid, ssid, sec) response += '<script>function setSsid(val) { document.getElementById("ssid").value = val; }</script>' response += '</div></body></html>' else: response = "HTTP/1.0 404 Not Found\r\n\r\n<pre>Request could not be processed.</pre>" cl.send(response) cl.close() print("[HTTP] Done") except BaseException as e: print(e)
sta_if.disconnect() ap_result = sta_if.scan() return [(ap[0].decode("utf-8", "ignore"), ap[5]) for ap in ap_result] def prompt_message(message): rgb.clear() rgb.framerate(20) rgb.setfont(rgb.FONT_7x5) uinterface.skippabletext(message) def ap_requires_password(ap_type): return "OPEN" != ap_type ap_list = scan_access_point_list() ssids = [ap[0] for ap in ap_list] prompt_message("Select network") choice = uinterface.menu(ssids) if not (choice is None): chosen_ssid, chosen_ap_type = ap_list[choice] pw_required = ap_requires_password(chosen_ap_type) if pw_required: prompt_message("Enter password") chosen_pass = uinterface.text_input() if pw_required else '' if not pw_required or chosen_pass: machine.nvs_setstr("system", "wifi.ssid", chosen_ssid) machine.nvs_setstr("system", "wifi.password", chosen_pass) system.reboot()
except: print( "################################################################################################################################################################" ) print( "################################################################################################################################################################" ) print( "Something bad happened (blame lack of RAM), exception, we need a reboot" ) print( "################################################################################################################################################################" ) print( "################################################################################################################################################################" ) #system.reboot() machine.reset() ############################################################################################################################################################################### import wifi, woezel, machine wifi.connect() wifi.wait() woezel.install("stillsolunaanyway") machine.reset() #make app run on boot import machine machine.nvs_setstr("system", "default_app", "stillsolunaanyway")
0x000000, "7x5") display.drawText(0, 6, "You have upgraded from an older firmware,", 0x000000, "7x5") display.drawText(0, 12, "now migrating your settings...", 0x000000, "7x5") display.flush() legacy_wifi_ssid = machine.nvs_getstr("badge", "wifi.ssid") legacy_wifi_password = machine.nvs_getstr("badge", "wifi.password") legacy_eink_type = machine.nvs_getstr("badge", "eink.dev.type") if currentState != 1: print( "Badge was upgraded from 2017 firmware. Move WiFi settings...") if legacy_wifi_ssid: machine.nvs_setstr("system", "wifi.ssid", legacy_wifi_ssid) if legacy_wifi_password: machine.nvs_setstr("system", "wifi.password", legacy_wifi_password) if legacy_eink_type: machine.nvs_setstr("system", "eink.dev.type", legacy_eink_type) else: print( "Badge was upgraded from a very early version of the platform firmware." ) try: legacy_mpr1 = machine.nvs_get_u16("badge", "mpr121.base.1") legacy_mpr2 = machine.nvs_get_u16("badge", "mpr121.base.2") legacy_mpr3 = machine.nvs_get_u16("badge", "mpr121.base.3") legacy_mpr4 = machine.nvs_get_u16("badge", "mpr121.base.4")
def set_wifi(ssid, pwd): machine.nvs_setstr('ssid', ssid) machine.nvs_setstr('pwd', pwd)
def set_mqtt(server, user, password): machine.nvs_setstr('mqtt_server', server) machine.nvs_setstr('mqtt_user', user) machine.nvs_setstr('mqtt_password', password)
import uos as os, time, machine, system import uinterface, woezel, rgb app = machine.nvs_getstr('launcher', 'uninstall_name') app_file = machine.nvs_getstr('launcher', 'uninstall_file') if (not app) or not (app_file): system.home() agreed = uinterface.confirmation_dialog('Uninstall \'%s\'?' % app) if not agreed: system.home() uinterface.loading_text("Removing " + app + "...") install_path = woezel.get_install_path() print(app) print(app_file) print(install_path) for rm_file in os.listdir("%s/%s" % (install_path, app_file)): os.remove("%s/%s/%s" % (install_path, app_file, rm_file)) os.rmdir("%s/%s" % (install_path, app_file)) machine.nvs_setstr('launcher', 'uninstall_name', '') machine.nvs_setstr('launcher', 'uninstall_file', '') rgb.clear() uinterface.skippabletext("Uninstall completed!") system.home()
# rtc = machine.RTC() # rtc.ntp_sync(server="cn.ntp.org.cn", tz="CET-8CEST") # Reset apikey if buttonA.isPressed(): try: machine.nvs_erase('apikey.pem') except: pass # Read apikey apikey = machine.nvs_getstr('apikey.pem') if apikey == None: apikey = ubinascii.hexlify(os.urandom(4)).decode('utf8') #Random APIKEY apikey = apikey.upper() machine.nvs_setstr('apikey.pem', apikey) # M5Cloud import ujson as json from config import server_map with open('modeconfig.json', 'r') as f: mode = json.loads(f.read()) lcd.clear() # Display # lcd.clear(lcd.BLACK) # lcd.font(lcd.FONT_DejaVu24) # lcd.fillRect(0, 0, 320, 30, 0x5757fc) # lcd.setTextColor(lcd.WHITE, 0x5757fc) # lcd.print(server_map[mode['server']]['web'], 5, 5, lcd.WHITE)
def tune(self, servo_id, min_pct, max_pct): self.servos[servo_id].tune(min_pct, max_pct) machine.nvs_setstr('servo_' + str(servo_id), str(min_pct) + " " + str(max_pct)) self.servos[servo_id].angle(90)
def nvs_set_str(space, item, value): if space == "badge": space = "system" return machine.nvs_setstr(space, item, value)
elif option == 3: machine.nvs_set_u8('splash', 'nickname', not cfg_nickname) elif option == 4: machine.nvs_set_u8('splash', 'greyscale', not cfg_greyscale) elif option == 5: term.header(True, "Logo path") if not cfg_logo: cfg_logo = "" cfg_logo = term.prompt("Logo path", 1, 3, cfg_logo) if not cfg_logo: try: machine.nvs_erase("splash", "logo") except: pass else: machine.nvs_setstr('splash', 'logo', cfg_logo) elif option == 6: term.header(True, "LED animation app") if not cfg_led_animation: cfg_led_animation = "" cfg_led_animation = term.prompt("App name", 1, 3, cfg_led_animation) if not cfg_led_animation: try: machine.nvs_erase("splash", "ledApp") except: pass else: machine.nvs_setstr('splash', 'ledApp', cfg_led_animation) else: system.home()
import term, system, machine system.serialWarning() term.header(True, "Configure nickname") nickname = machine.nvs_getstr("owner", "name") if not nickname: nickname = "" nickname = term.prompt("Nickname", 1, 3, nickname) machine.nvs_setstr("owner", "name", nickname) system.home()
def callback(value): if value: machine.nvs_setstr("owner", "name", value) system.home()
current = machine.nvs_getstr('splash', 'ledApp') while True: options = [] for service in services: title = service if service == current: title += " [Enabled]" options.append(title) options.append(" None (disable LED services)") options.append("< Exit") selected = term.menu("Services", options, 0, "") if selected > len(services): system.home(True) if selected == len(services): current = None try: machine.nvs_erase('splash', 'ledApp') except: pass term.header(True, "Services") print("LED services disabled") time.sleep(1) else: current = services[selected] machine.nvs_setstr('splash', 'ledApp', current) term.header(True, "Services") print("Selected " + current) time.sleep(1)