コード例 #1
0
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()
コード例 #2
0
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)
コード例 #3
0
def nvs_erase_key(space, item):
	return machine.nvs_erase(space, item)
コード例 #4
0
from utils import *
from config import __VERSION__
import machine

wait(0.5)
# Connect network
import wifisetup
wifisetup.auto_connect()

# 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:
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
        option = 0
    elif current == 0:
        option = 1  #DISABLE
    elif current == 1:
        option = 2  #ALT
    elif current == 2:
        option = 3  #SHA
    else:
        # Invalid value, set SHA2017 type
        option = 3
        machine.nvs_set_u8('system', 'eink.dev.type', 2)
    items = []
    items.append("Use default")
    items.append("Disable display driver")
    items.append("GDEH029A1 (replacement)")
    items.append("DEPG0290B1 (SHA2017)")
    items.append("< Back")
    option = term.menu("Splash screen settings", items, option, "", 64)
    if option == 0:
        try:
            machine.nvs_erase("system", "eink.dev.type")
        except:
            pass
    if option == 1:
        machine.nvs_set_u8('system', 'eink.dev.type', 0)
    if option == 2:
        machine.nvs_set_u8('system', 'eink.dev.type', 1)
    if option == 3:
        machine.nvs_set_u8('system', 'eink.dev.type', 2)
    system.home()