Ejemplo n.º 1
0
def _httpHandlerTestPost(httpClient, httpResponse):
    formData = httpClient.ReadRequestPostedFormData()
    print(httpResponse)
    print("/test/post de data con: ", formData)
    flujo = formData["FLUJO"]
    corriente = formData["CORRIENTE"]
    content = """\
	<!DOCTYPE html>
	<html lang=en>
		<head>
			<meta charset="UTF-8" />
            <title>TEST POST</title>
        </head>
        <body>
            <h1>TEST POST</h1>
            Flujo = %s<br />
            Corriente = %s<br />
        </body>
    </html>
	""" % (MicroWebSrv.HTMLEscape(flujo), MicroWebSrv.HTMLEscape(corriente))

    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)
Ejemplo n.º 2
0
def _httpHandlerTestPost(httpClient, httpResponse):
    formData = httpClient.ReadRequestPostedFormData()
    firstname = formData["firstname"]
    lastname = formData["lastname"]
    content = """\
	<!DOCTYPE html>
	<html lang=en>
		<head>
			<meta charset="UTF-8" />
            <title>OHS Badge Configuration Post</title>
        </head>
        <body>
            <h1>Name sent to badge</h1>
            Firstname = %s<br />
            Lastname = %s<br />
        </body>
    </html>
	""" % (MicroWebSrv.HTMLEscape(firstname), MicroWebSrv.HTMLEscape(lastname))
    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)
    writeName(firstname, lastname)

    epd.set_rotate(gxgde0213b1.ROTATE_90)
    namestr = firstname + "\n" + lastname
    epd.clear_frame(fb)
    epd.G_display_string_at(fb, 0, 0, namestr, G_FreeSans24pt7b, 1,
                            gxgde0213b1.COLORED)
    epd.display_frame(fb)
    goto_deepsleep()
Ejemplo n.º 3
0
def _httpHandlerTestPost(httpClient, httpResponse):
    formData = httpClient.ReadRequestPostedFormData()
    display0 = formData["display0"]
    display1 = formData["display1"]
    display2 = formData["display2"]
    display3 = formData["display3"]

    db[b"display0"] = str.encode(display0)
    db[b"display1"] = str.encode(display1)
    db[b"display2"] = str.encode(display2)
    db[b"display3"] = str.encode(display3)
    db.flush()

    content = """\
	<!DOCTYPE html>
	<html lang=fr>
		<head>
			<meta charset="UTF-8" />
            <title>Settings saved</title>
        </head>
        <body>
            <h1>Settings saved</h1>
            Display0 = %s<br />
            Display1 = %s<br />
            Display2 = %s<br />
            Display3 = %s<br />
        </body>
    </html>
	""" % (MicroWebSrv.HTMLEscape(display0), MicroWebSrv.HTMLEscape(display1),
        MicroWebSrv.HTMLEscape(display2), MicroWebSrv.HTMLEscape(display3))
    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)
Ejemplo n.º 4
0
def _httpHandlerFinish(httpClient, httpResponse) :
  f = open( web_dir + 'config_1.html', 'r')
  content = str(f.read())
  f.close()
  
  content += str("Reset Wifi Settings to Default")
  
  f = open( web_dir + 'config_2.html', 'r')
  content += str(f.read())
  f.close()

  httpResponse.WriteResponseOk( headers         = None,
                                contentType     = "text/html",
                                contentCharset  = "UTF-8",
                                content         = content )
  print("User hit the RESET Page.")
  try:
    config = wifi_config.readConfig(wifi_config_file)
    custom_message = config["custom_message"]
  except OSError:
    custom_message = default_custom_message
  config_data = {'ssid': MicroWebSrv.HTMLEscape(default_ssid), 'password': MicroWebSrv.HTMLEscape(default_password), 'custom_message': MicroWebSrv.HTMLEscape(custom_message)}
  
  f = open(wifi_config_file, "w")
  json = ujson.dumps(config_data)
  f.write(json)
  f.close()
Ejemplo n.º 5
0
def _httpHandlerConfigurePost(httpClient, httpResponse) :
  formData  = httpClient.ReadRequestPostedFormData()
  ssid  = formData["ssid"]
  password  = formData["password"]
  custom_message = formData["custom_message"]
  f = open( web_dir + 'config_1.html', 'r')
  content = str(f.read())
  f.close()
  
  config_data = {'ssid': MicroWebSrv.HTMLEscape(ssid), 'password': MicroWebSrv.HTMLEscape(password), 'custom_message': MicroWebSrv.HTMLEscape(custom_message)}

  content += str(config_data)
  
  f = open( web_dir + 'config_2.html', 'r')
  content += str(f.read())
  f.close()
  
  httpResponse.WriteResponseOk( headers         = None,
                                contentType     = "text/html",
                                contentCharset  = "UTF-8",
                                content         =  content)

  f = open(wifi_config_file, "w")
  json = ujson.dumps(config_data)
  f.write(json)
  f.close()
  print("User POSTED settings to /configure")
  print("Wrote the following to " + wifi_config_file + "\n" + json)
Ejemplo n.º 6
0
def _httpHandlerTestPost(httpClient, httpResponse):
    formData = httpClient.ReadRequestPostedFormData()
    devadd = formData["devadd"]
    nwskey = formData["nwskey"]
    appkey = formData["appkey"]
    content = """\
    <!DOCTYPE html>
    <html lang=en>
	<head>
		<meta charset="UTF-8" />
		<title>AlphaX MHM Configuration Page</title>
		<link rel="stylesheet" href="style.css" />
	</head>
	<body style="min-width: 480px;text-align: center">
		<div style="text-align: center;padding-top: 10px">
			<img src="ax_logo.png" />
			<h1>MHM4 LoRaWAN ABP Configuration</h1>
		</div><br>
        <div style="max-width:480px;padding:10px;margin: auto;text-align: center">
	    <form action="" method="post" accept-charset="ISO-8859-1">
		<div style="padding:10px;text-align: center">
			<label style="font-size:11px">Device Address: </label>
			<input type="text" name="devadd" style="color:#fff" value="%s" disabled>
		</div>
           <div width="480px" style="padding:10px;text-align: center">
			<label style="font-size:11px">Network Session Key: </label>
			<input type="text" name="nwskey" style="color:#fff" value="%s" disabled>
		</div>
		<div  style="padding:10px;text-align: center">
			<label style="font-size:11px">App Session KEY: </label>
			<input type="text" name="appkey" style="color:#fff" value="%s" disabled>
		</div>
		<div  style="padding:10px;">
			<h5 style="color:green">Success. Device will reboot Now.</h5> 
		</div>	
	</form>
	<br>
		<p style="font-size:9px">If you wish to connect via ABP (which is the recommended method) the network will provide you with a Device ID, Network Key and Application Key. The former identifies what application your device is connecting to, the latter is a shared secret key unique to your device to generate the session keys that prove its identity on the network. </p>
		<br />
	</div>
	</body>
    </html>
    """ % (MicroWebSrv.HTMLEscape(devadd), MicroWebSrv.HTMLEscape(nwskey),
           MicroWebSrv.HTMLEscape(appkey))
    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)

    f = open('/flash/config.py', 'w')
    f.write('#############################################\n')
    f.write('####### sys generated file do not edit ######\n')
    f.write('#############################################\n')
    f.write('devadd = "' + str(devadd) + '"\n')
    f.write('nwskey = "' + str(nwskey) + '"\n')
    f.write('appkey = "' + str(appkey) + '"\n')
    f.close()

    machine.reset()
Ejemplo n.º 7
0
def _httpHandlerTestPost(httpClient, httpResponse):

    formData = httpClient.ReadRequestPostedFormData()
    firstname = formData["firstname"]
    lastname = formData["lastname"]

    content = CONTENT_TEST_POST % (MicroWebSrv.HTMLEscape(firstname),
                                   MicroWebSrv.HTMLEscape(lastname))

    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)
Ejemplo n.º 8
0
def _httpHandlerTestPost(httpClient, httpResponse):
    formData = httpClient.ReadRequestPostedFormData()
    status = formData["status"]
    content = """\
    <!DOCTYPE html>
    <html lang=en>
		<head>
			<meta charset="UTF-8" />
            <title>MODE SWITCH</title>
        </head>
        <body style="background-color: lightgrey; text-align: center;">
            <h1><b>===MODE SWITCH===</b></h1>
            Choice = %s<br />
        </body>
    </html>
	""" % (MicroWebSrv.HTMLEscape(status))
    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)

    if status == "mqtt":
        print(">>MQTT mode selected<<")
        mf = open("status.txt", "w")
        mf.write("yes")
        mf.close()
Ejemplo n.º 9
0
def _httpHandlerTestPost(httpClient, httpResponse):
    formData = httpClient.ReadRequestPostedFormData()
    firstname = formData["firstname"]
    lastname = formData["lastname"]
    content = """\
	<!DOCTYPE html>
	<html lang=en><head><meta charset="UTF-8" /><title>TEST POST</title></head>
        <body><h1>TEST POST</h1>
	Firstname = %s<br />				# MicroWebSrv.HTMLEscape(firstname)
	Lastname = %s<br />				# MicroWebSrv.HTMLEscape(lastname)
	</body></html>
	""" % (MicroWebSrv.HTMLEscape(firstname), MicroWebSrv.HTMLEscape(lastname))
    # publie la page POST
    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)
Ejemplo n.º 10
0
def _httpHandlerTestPost(httpClient, httpResponse):
    formData = httpClient.ReadRequestPostedFormData()
    ssid = formData["ssid"]
    lines = ssid.split("\r")
    content = """\
	<!DOCTYPE html>
	<html lang=en>
		<head>
			<meta charset="UTF-8" />
            <title>TEST POST</title>
        </head>
        <body>
            <h1>WiFi Config</h1>
            SSID = %s<br />
        </body>
    </html>
	""" % (MicroWebSrv.HTMLEscape(ssid))
    httpResponse.WriteResponseOk(headers=None,
                                 contentType="text/html",
                                 contentCharset="UTF-8",
                                 content=content)
Ejemplo n.º 11
0
def _httpHandlerFinish(httpClient, httpResponse) :
  
  try:
    print("1")
    config = wifi_config.readConfig(wifi_config_file)
    ssid = config["ssid"]
    password = config["password"]
    custom_message = config["custom_message"]
  except OSError:
    print("2")
    ssid = default_ssid
    password = default_password
    custom_message = default_custom_message
    
  print("3")
  f = open( web_dir + 'index_1.html', 'r')
  page = str(f.read())
  f.close()
  print("4")
  page = page + """<table style="margin-left: auto; margin-right: auto;"><tbody><tr><td>SSIDs:</td><td><input name="ssid" type="text" value="%s" /></td></tr><tr><td>Wifi Password:</td><td><input name="password" type="password" value="%s" /></td></tr><tr><td></td><td><input type="button" class="button" value="Reset Wifi Settings" Onclick="window.location.href='/reset'"></td></tr><tr><td><h1 style="text-align: center;"><span style="color: #f90;">Other Settings</span></h1></td></tr><tr><td>Hacker's Challenge ID:</td><td>%s</td></tr><tr><td>Custom Message:</td><td><input name="custom_message" maxlength="250" type="text" value="%s" /></td></tr></tbody></table>""" % ( MicroWebSrv.HTMLEscape(ssid), MicroWebSrv.HTMLEscape(password), MicroWebSrv.HTMLEscape(hcid), MicroWebSrv.HTMLEscape(custom_message) )f = open( web_dir + 'index_2.html', 'r')
  page = page + str(f.read())
  f.close()
  print("5")

  httpResponse.WriteResponseOk( headers         = None,
                                contentType     = "text/html",
                                contentCharset  = "UTF-8",
                                content         = page )
  print("User hit the Main Page.")