def webform_load(self): ws.addFormTextBox("Remote station address", "plugin_89_addr", str(self.taskdevicepluginconfig[0]), 128) ws.addFormNumericBox("Timeout", "plugin_89_timeout", self.taskdevicepluginconfig[1], 0, 10000) ws.addUnit("millisec") return True
def webform_load(self): ws.addFormNote( "Please make sure to select <a href='hardware'>pin configured for Output!</a>" ) ws.addFormCheckBox("Preserve state at startup", "p029_preserve", self.taskdevicepluginconfig[0]) ws.addFormNumericBox("Auto OFF after", "p029_off", self.taskdevicepluginconfig[1], 0, 3600) ws.addUnit("s") return True
def webform_load(self): # create html page for settings choice2 = int(float( self.taskdevicepluginconfig[1])) # store i2c address options = ["0x3c", "0x3d"] optionvalues = [0x3c, 0x3d] ws.addFormSelector("Address", "p023_adr", len(options), options, optionvalues, None, choice2) ws.addFormNote( "Enable <a href='hardware'>I2C bus</a> first, than <a href='i2cscanner'>search for the used address</a>!" ) choice3 = int(float( self.taskdevicepluginconfig[2])) # store rotation state options = ["Normal", "Rotate by 180"] optionvalues = [0, 2] ws.addFormSelector("Mode", "p023_rotate", len(optionvalues), options, optionvalues, None, choice3) options = [ "128x64", "128x128", "128x32", "96x96", "96x64", "64x48", "64x32" ] choice4 = self.taskdevicepluginconfig[3] # store resolution ws.addHtml("<tr><td>Resolution:<td>") ws.addSelector_Head("p023_res", False) for d in range(len(options)): ws.addSelector_Item(options[d], options[d], (choice4 == options[d]), False) ws.addSelector_Foot() choice5 = int(float( self.taskdevicepluginconfig[4])) # store line count ws.addHtml("<tr><td>Number of lines:<td>") ws.addSelector_Head("p023_linecount", False) for l in range(1, self.P23_Nlines + 1): ws.addSelector_Item(str(l), l, (l == choice5), False) ws.addSelector_Foot() ws.addFormNumericBox("Try to display # characters per row", "p023_charperl", self.taskdevicepluginconfig[5], 1, 32) ws.addFormNote("Leave it '1' if you do not care") ws.addFormCheckBox("Clear only used lines", "p023_partialclear", self.taskdevicepluginconfig[6]) if choice5 > 0 and choice5 < 9: lc = choice5 else: lc = self.P23_Nlines for l in range(lc): try: linestr = self.lines[l] except: linestr = "" ws.addFormTextBox("Line" + str(l + 1), "p023_template" + str(l), linestr, 128) return True
def webform_load(self): # create html page for settings ws.addFormTextBox("Server", "server", self.server, 128) ws.addFormNumericBox("Port", "port", self.port, 1, 65535) ws.addFormPasswordBox("Token", "passw", self.passw, 64) ws.addHtml( "<TR><TD>Body:<TD><textarea name='body' rows='5' cols='80' size=255 wrap='off'>" ) ws.addHtml(str(self.body)) ws.addHtml("</textarea>") ws.addFormNote( "SSL is currently broken in WROOM, plugin will not work without PSRAM!" ) return True
def webform_load(self): # create html page for settings ws.addFormTextBox("Server","server",self.server,64) options = ["Plain","SSL"] optionvalues = [0,1] ws.addFormSelector("Protocol","security",len(options),options,optionvalues,None,self.security) ws.addFormNumericBox("Port","port",self.port,1,65535) ws.addFormTextBox("Sender","sender",self.sender,64) ws.addFormTextBox("Receiver","receiver",self.receiver,64) ws.addFormTextBox("SMTP login name","login",self.login,64) ws.addFormPasswordBox("STMP password","passw",self.passw,64) ws.addFormTextBox("Subject","subject",self.subject,64) ws.addHtml("<TR><TD>Body:<TD><textarea name='body' rows='5' cols='80' size=512 wrap='off'>") ws.addHtml(str(self.body)) ws.addHtml("</textarea>") return True
def webform_load(self): # create html page for settings ws.addFormTextBox("Report topic", "inchannel", self.inchannel, 255) ws.addFormTextBox("Command topic", "outchannel", self.outchannel, 255) try: kp = self.keepalive except: kp = 60 ws.addFormNumericBox("Keepalive time", "keepalive", kp, 2, 600) ws.addUnit("s") try: am = self.authmode fname = self.certfile except: am = 0 fname = "" options = ["MQTT", "MQTTS"] optionvalues = [0, 1] ws.addFormSelector("Mode", "c014_mode", len(optionvalues), options, optionvalues, None, int(am)) return True
def webform_load(self): # create html page for settings ws.addFormNumericBox("Led Count", "p038_leds", self.taskdevicepluginconfig[0], 1, 2700) return True
def handle_devices(httpResponse, responsearr): ws.navMenuIndex = 4 ws.TXBuffer = "" httpResponse.WriteResponseOk(headers=({ 'Cache-Control': 'no-cache' }), contentType='text/html', contentCharset='UTF-8', content="") taskdevicenumber = ws.arg('TDNUM', responsearr) if taskdevicenumber == '': taskdevicenumber = 0 else: taskdevicenumber = int(float(taskdevicenumber)) taskdevicetimer = ws.arg('TDT', responsearr) if taskdevicetimer == '': taskdevicetimer = 0 else: taskdevicetimer = float(taskdevicetimer) edit = ws.arg("edit", responsearr) page = ws.arg("page", responsearr) setpage = ws.arg("setpage", responsearr) taskIndex = ws.arg("index", responsearr) runIndex = ws.arg("run", responsearr) if page == '': page = 0 else: page = int(float(page)) if page == 0: page = 1 if setpage == '': setpage = 0 else: setpage = int(float(setpage)) if (setpage > 0): if setpage <= (pglobals.TASKS_MAX / ws.TASKS_PER_PAGE): page = setpage else: page = int(pglobals.TASKS_MAX / ws.TASKS_PER_PAGE) ws.sendHeadandTail("TmplStd", ws._HEAD) taskIndexNotSet = (taskIndex == 0) or (taskIndex == '') if taskIndex != "": taskIndex = int(taskIndex) - 1 if ws.arg('del', responsearr) != '': taskdevicenumber = 0 ttid = -1 try: ttid = settings.Tasks[taskIndex].pluginid except: ttid = -1 if ttid != -1: try: settings.Tasks[taskIndex].plugin_exit() taskIndexNotSet = True settings.Tasks[taskIndex] = False settings.savetasks() # savetasksettings!!! except Exception as e: misc.addLog(pglobals.LOG_LEVEL_ERROR, "Deleting failed: " + str(e)) if runIndex != "": if len(settings.Tasks) < 1: return False try: s = int(runIndex) except: s = -1 try: if s > 0 and (s <= len(settings.Tasks)): s = s - 1 # array is 0 based, tasks is 1 based if (type(settings.Tasks[s]) != bool) and (settings.Tasks[s]): if (settings.Tasks[s].enabled): settings.Tasks[s].plugin_read() except Exception as e: print(e) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" if taskIndexNotSet == False: #Show edit form if a specific entry is chosen with the edit button ws.TXBuffer += "<form name='frmselect' method='post'><table class='normal'>" ws.addFormHeader("Task Settings") ws.TXBuffer += "<TR><TD style='width:150px;' align='left'>Device:<TD>" tte = taskdevicenumber try: tte = settings.Tasks[taskIndex].pluginid except: pass if (tte <= 0): ws.addSelector_Head("TDNUM", True) for y in range(0, len(pglobals.deviceselector)): pname = pglobals.deviceselector[y][2] try: if int(pglobals.deviceselector[y][1]) != 0: pname = "P" + str(int( pglobals.deviceselector[y][1])).rjust( 3, "0") + " - " + pglobals.deviceselector[y][2] except: pass ws.addSelector_Item(pname, int(pglobals.deviceselector[y][1]), (pglobals.deviceselector[y][1] == tte), False, "") ws.addSelector_Foot() httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" else: # device selected createnewdevice = True try: if (settings.Tasks[taskIndex].getpluginid() == int(tte)): createnewdevice = False except: pass exceptstr = "" gc.collect() if createnewdevice: for y in range(len(pglobals.deviceselector)): if int(pglobals.deviceselector[y][1]) == int(tte): if len(settings.Tasks) <= taskIndex: while len(settings.Tasks) <= taskIndex: settings.Tasks.append(False) try: m = __import__(pglobals.deviceselector[y][0]) except Exception as e: settings.Tasks[taskIndex] = False exceptstr += str(e) m = False if m: try: settings.Tasks[taskIndex] = m.Plugin(taskIndex) except Exception as e: settings.Tasks.append(m.Plugin(taskIndex)) exceptstr += str(e) break if settings.Tasks[taskIndex] == False: ws.TXBuffer += "Importing failed: {0}</td></tr></table>".format( exceptstr) ws.sendHeadandTail("TmplStd", ws._TAIL) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" return True else: try: enableit = (ws.arg("TDE", responsearr) == "on") # print("plugin init",enableit) if enableit: settings.Tasks[taskIndex].plugin_init( True ) # call plugin init / (ws.arg("TDE",responsearr) == "on") else: settings.Tasks[taskIndex].plugin_init( ) # call plugin init / (ws.arg("TDE",responsearr) == "on") except: pass if edit != '' and not (taskIndexNotSet): # when form submitted if taskdevicenumber != 0: # save settings if taskdevicetimer > 0: settings.Tasks[taskIndex].interval = taskdevicetimer else: if not (settings.Tasks[taskIndex].timeroptional ): # set default delay settings.Tasks[ taskIndex].interval = settings.Settings[ "Delay"] else: settings.Tasks[taskIndex].interval = 0 tasknamestr = str(ws.arg("TDN", responsearr)).strip() settings.Tasks[taskIndex].taskname = tasknamestr.replace( " ", "") if tasknamestr: settings.Tasks[taskIndex].taskdeviceport = ws.arg( "TDP", responsearr) maxcon = len(settings.Controllers) if maxcon > pglobals.CONTROLLER_MAX: maxcon = pglobals.CONTROLLER_MAX for controllerNr in range(0, maxcon): if ((settings.Controllers[controllerNr]) and (settings.Controllers[controllerNr].enabled)): sid = "TDSD" sid += str(controllerNr + 1) settings.Tasks[taskIndex].senddataenabled[ controllerNr] = (ws.arg(sid, responsearr) == "on") if (settings.Tasks[taskIndex]. senddataenabled[controllerNr]): if (settings.Controllers[controllerNr]): if (settings.Controllers[controllerNr]. enabled): settings.Tasks[taskIndex].controllercb[ controllerNr] = settings.Controllers[ controllerNr].senddata if (settings.Tasks[taskIndex]. senddataenabled[controllerNr]): sid = "TDID" sid += str(controllerNr + 1) ctrlidx = str(ws.arg(sid, responsearr)).strip() if ctrlidx == "": ctrlidx = -1 else: ctrlidx = int(ctrlidx) settings.Tasks[taskIndex].controlleridx[ controllerNr] = ctrlidx for pins in range(0, 4): pinnum = ws.arg("taskdevicepin" + str(pins + 1), responsearr) if pinnum: settings.Tasks[taskIndex].taskdevicepin[ pins] = int(pinnum) # if settings.Tasks[taskIndex].pullupoption: # settings.Tasks[taskIndex].pullup = (ws.arg("TDPPU",responsearr) == "on") if settings.Tasks[taskIndex].inverselogicoption: settings.Tasks[taskIndex].pininversed = (ws.arg( "TDPI", responsearr) == "on") for varnr in range(0, settings.Tasks[taskIndex].valuecount): tvname = str( ws.arg("TDVN" + str(varnr + 1), responsearr)) if tvname: settings.Tasks[taskIndex].valuenames[ varnr] = tvname.replace(" ", "") settings.Tasks[taskIndex].formula[varnr] = ws.arg( "TDF" + str(varnr + 1), responsearr) tvdec = ws.arg("TDVD" + str(varnr + 1), responsearr) if tvdec == "" or tvdec == False or tvdec == None: tvdec = 0 settings.Tasks[taskIndex].decimals[varnr] = tvdec else: settings.Tasks[taskIndex].valuenames[varnr] = "" try: settings.Tasks[taskIndex].i2c = int( ws.arg("i2c", responsearr)) except: settings.Tasks[taskIndex].i2c = -1 try: settings.Tasks[taskIndex].spi = int( ws.arg("spi", responsearr)) except: settings.Tasks[taskIndex].spi = -1 if settings.Tasks[taskIndex].taskname == "": settings.Tasks[taskIndex].enabled = False settings.Tasks[taskIndex].webform_save( responsearr) # call plugin read FORM settings.Tasks[taskIndex].enabled = (ws.arg( "TDE", responsearr) == "on") settings.savetasks() # savetasksettings!!! ws.TXBuffer += "<input type='hidden' name='TDNUM' value='{0}'>{1}".format( settings.Tasks[taskIndex].pluginid, settings.Tasks[taskIndex].getdevicename()) ws.addFormTextBox("Name", "TDN", str(settings.Tasks[taskIndex].gettaskname()), 40) ws.addFormCheckBox("Enabled", "TDE", settings.Tasks[taskIndex].enabled) # section: Sensor / Actuator httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" if (settings.Tasks[taskIndex].dtype >= pglobals.DEVICE_TYPE_SINGLE and settings.Tasks[taskIndex].dtype <= pglobals.DEVICE_TYPE_QUAD): ws.addFormSubHeader("Sensor" if settings.Tasks[taskIndex]. senddataoption else "Actuator") # if (Settings.Tasks[taskIndex].ports != 0): # addFormNumericBox("Port", "TDP", Settings.Tasks[taskIndex].taskdeviceport) # if (settings.Tasks[taskIndex].pullupoption): # ws.addFormCheckBox("Internal PullUp", "TDPPU", settings.Tasks[taskIndex].pullup) if (settings.Tasks[taskIndex].inverselogicoption): ws.addFormCheckBox("Inversed Logic", "TDPI", settings.Tasks[taskIndex].pininversed) if (settings.Tasks[taskIndex].dtype >= pglobals.DEVICE_TYPE_SINGLE and settings.Tasks[taskIndex].dtype <= pglobals.DEVICE_TYPE_QUAD): ws.addFormPinSelect( "1st GPIO", "taskdevicepin1", settings.Tasks[taskIndex].taskdevicepin[0], settings.Tasks[taskIndex].pinfilter[0]) if (settings.Tasks[taskIndex].dtype >= pglobals.DEVICE_TYPE_DUAL and settings.Tasks[taskIndex].dtype <= pglobals.DEVICE_TYPE_QUAD): ws.addFormPinSelect( "2nd GPIO", "taskdevicepin2", settings.Tasks[taskIndex].taskdevicepin[1], settings.Tasks[taskIndex].pinfilter[1]) if (settings.Tasks[taskIndex].dtype >= pglobals.DEVICE_TYPE_TRIPLE and settings.Tasks[taskIndex].dtype <= pglobals.DEVICE_TYPE_QUAD): ws.addFormPinSelect( "3rd GPIO", "taskdevicepin3", settings.Tasks[taskIndex].taskdevicepin[2], settings.Tasks[taskIndex].pinfilter[2]) if (settings.Tasks[taskIndex].dtype == pglobals.DEVICE_TYPE_QUAD): ws.addFormPinSelect( "4th GPIO", "taskdevicepin4", settings.Tasks[taskIndex].taskdevicepin[3], settings.Tasks[taskIndex].pinfilter[3]) if (settings.Tasks[taskIndex].dtype == pglobals.DEVICE_TYPE_I2C): try: import inc.libhw as libhw options = libhw.geti2clist() except: options = [] ws.addHtml("<tr><td>I2C line:<td>") ws.addSelector_Head("i2c", True) for d in range(len(options)): ws.addSelector_Item( "I2C" + str(options[d]), options[d], (settings.Tasks[taskIndex].i2c == options[d]), False) ws.addSelector_Foot() if (settings.Tasks[taskIndex].dtype == pglobals.DEVICE_TYPE_SPI): try: import inc.libhw as libhw options = libhw.getspilist() except: options = [] ws.addHtml("<tr><td>SPI line:<td>") ws.addSelector_Head("spi", True) for d in range(len(options)): ws.addSelector_Item( "SPI" + str(options[d]), options[d], (settings.Tasks[taskIndex].spi == options[d]), False) ws.addSelector_Foot() httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" try: settings.Tasks[taskIndex].webform_load( ) # call plugin function to fill ws.TXBuffer except Exception as e: print(e) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" if (settings.Tasks[taskIndex].senddataoption ): # section: Data Acquisition ws.addFormSubHeader("Data Acquisition") maxcon = len(settings.Controllers) if maxcon > pglobals.CONTROLLER_MAX: maxcon = pglobals.CONTROLLER_MAX for controllerNr in range(0, maxcon): if ((settings.Controllers[controllerNr]) and (settings.Controllers[controllerNr].enabled)): sid = "TDSD" sid += str(controllerNr + 1) ws.TXBuffer += "<TR><TD>Send to Controller {0}<TD>".format( ws.getControllerSymbol(controllerNr)) ws.addCheckBox( sid, settings.Tasks[taskIndex]. senddataenabled[controllerNr]) sid = "TDID" sid += str(controllerNr + 1) if (settings.Controllers[controllerNr].enabled ) and settings.Tasks[taskIndex].senddataenabled[ controllerNr]: if (settings.Controllers[controllerNr].usesID): ws.TXBuffer += "<TR><TD>IDX:<TD>" ws.addNumericBox( sid, settings.Tasks[taskIndex]. controlleridx[controllerNr], 0, 9999) else: ws.TXBuffer += "<input type='hidden' name='{0}' value='0'>".format( sid) # no id, set to 0 else: ws.TXBuffer += "<input type='hidden' name='{0}' value='-1'>".format( sid) # disabled set to -1 ws.addFormSeparator(2) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" if (settings.Tasks[taskIndex].timeroption): ws.addFormNumericBox("Interval", "TDT", settings.Tasks[taskIndex].interval, 0, 65535) ws.addUnit("sec") if (settings.Tasks[taskIndex].timeroptional): ws.TXBuffer += " (Optional for this Device)" if (settings.Tasks[taskIndex].valuecount > 0): # //section: Values ws.addFormSubHeader("Values") ws.TXBuffer += "</table><table class='normal'><TR><TH style='width:30px;' align='center'>#<TH align='left'>Name" if (settings.Tasks[taskIndex].formulaoption): ws.TXBuffer += "<TH align='left'>Formula" if (settings.Tasks[taskIndex].formulaoption or settings.Tasks[taskIndex].decimalsonly): ws.TXBuffer += "<TH style='width:30px;' align='left'>Decimals" for varNr in range(0, settings.Tasks[taskIndex].valuecount): ws.TXBuffer += "<TR><TD>{0}<TD>".format(str(varNr + 1)) sid = "TDVN" + str(varNr + 1) ws.addTextBox( sid, settings.Tasks[taskIndex].getdevicevaluenames()[varNr], 40) if (settings.Tasks[taskIndex].formulaoption): ws.TXBuffer += "<TD>" sid = "TDF" + str(varNr + 1) ws.addTextBox(sid, settings.Tasks[taskIndex].formula[varNr], 140) if (settings.Tasks[taskIndex].formulaoption or settings.Tasks[taskIndex].decimalsonly): ws.TXBuffer += "<TD>" sid = "TDVD" + str(varNr + 1) ws.addNumericBox( sid, settings.Tasks[taskIndex].decimals[varNr], 0, 6) ws.addFormSeparator(4) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" gc.collect() ws.TXBuffer += "<TR><TD><TD colspan='3'><a class='button link' href='devices?setpage={0}'>Close</a>".format( page) ws.addSubmitButton() ws.TXBuffer += "<input type='hidden' name='edit' value='1'>" if taskIndex != '': ws.TXBuffer += "<input type='hidden' name='index' value='{0}'>".format( taskIndex + 1) ws.TXBuffer += "<input type='hidden' name='page' value='1'>" if (tte > 0): # if user selected a device, add the delete button ws.addSubmitButton("Delete", "del") ws.TXBuffer += "</table></form>" ws.sendHeadandTail("TmplStd", ws._TAIL) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = ""
def handle_config(httpResponse, responsearr): ws.navMenuIndex = 1 saved = ws.arg("Submit", responsearr) if (saved): settings.Settings["Name"] = ws.arg("name", responsearr).replace(" ", "") settings.Settings["Unit"] = ws.arg("unit", responsearr) tpw = ws.arg("password", responsearr) if "**" not in tpw: settings.Settings["Password"] = tpw tpw = ws.arg("apkey", responsearr) if "**" not in tpw: settings.Settings['APKEY'] = tpw settings.Settings['APSSID'] = ws.arg("apssid", responsearr) settings.Settings['AP1SSID'] = ws.arg("ssid", responsearr) settings.Settings['AP2SSID'] = ws.arg("ssid2", responsearr) tpw = ws.arg("apkey", responsearr) if "**" not in tpw: settings.Settings["APKEY"] = tpw tpw = ws.arg("key", responsearr) if "**" not in tpw: settings.Settings["AP1KEY"] = tpw tpw = ws.arg("key2", responsearr) if "**" not in tpw: settings.Settings["AP2KEY"] = tpw settings.Settings['WifiClient'] = (ws.arg("wifista", responsearr) == "on") settings.Settings['WifiAP'] = int(ws.arg("apmode", responsearr)) settings.Settings['APCAPTIVE'] = (ws.arg("ap_captive", responsearr) == "on") settings.Settings['WDHCP'] = (ws.arg("w_dhcp", responsearr) == "on") if settings.Settings['WDHCP'] == False: settings.Settings['WIP'] = ws.arg("w_ip", responsearr) settings.Settings['WMask'] = ws.arg("w_mask", responsearr) settings.Settings['WGW'] = ws.arg("w_gw", responsearr) settings.Settings['WDNS'] = ws.arg("w_dns", responsearr) settings.Settings['LANIF'] = (ws.arg("lanif", responsearr) == "on") if settings.Settings['LANIF']: settings.Settings['LDHCP'] = (ws.arg("l_dhcp", responsearr) == "on") if settings.Settings['LDHCP'] == False: settings.Settings['LIP'] = ws.arg("l_ip", responsearr) settings.Settings['LMask'] = ws.arg("l_mask", responsearr) settings.Settings['LGW'] = ws.arg("l_gw", responsearr) settings.Settings['LDNS'] = ws.arg("l_dns", responsearr) settings.savesettings() else: settings.loadsettings() ws.TXBuffer = "" httpResponse.WriteResponseOk(headers=({ 'Cache-Control': 'no-cache' }), contentType='text/html', contentCharset='UTF-8', content="") ws.sendHeadandTail("TmplStd", ws._HEAD) ws.TXBuffer += "<form name='frmselect' method='post'><table class='normal'>" ws.addFormHeader("Main Settings") ws.addFormTextBox("Unit Name", "name", settings.Settings["Name"], 25) ws.addFormNumericBox("Unit Number", "unit", settings.Settings["Unit"], 0, 256) ws.addFormPasswordBox("Admin Password", "password", settings.Settings["Password"], 25) ws.addFormSeparator(2) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" ws.addFormSubHeader("Wifi STA Settings") ws.addFormCheckBox("Enable Wifi STA mode", "wifista", settings.Settings["WifiClient"]) ws.addFormTextBox("SSID", "ssid", settings.Settings["AP1SSID"], 32) ws.addFormPasswordBox("Wifi Key", "key", settings.Settings["AP1KEY"], 64) ws.addFormTextBox("Fallback SSID", "ssid2", settings.Settings["AP2SSID"], 32) ws.addFormPasswordBox("Fallback Wifi Key", "key2", settings.Settings["AP2KEY"], 64) ws.addFormCheckBox("DHCP", "w_dhcp", settings.Settings["WDHCP"]) ws.addFormNote( "If DHCP enabled the settings below will not be saved or used!") ws.addFormTextBox("IP", "w_ip", settings.Settings["WIP"], 15) ws.addFormTextBox("Mask", "w_mask", settings.Settings["WMask"], 15) ws.addFormTextBox("GW", "w_gw", settings.Settings["WGW"], 15) ws.addFormTextBox("DNS", "w_dns", settings.Settings["WDNS"], 128) ws.addFormSubHeader("Wifi AP Settings") options = [ "Disable", "At startup always", "When Wifi STA not connected", "When LAN not connected" ] optionvalues = [0, 1, 2, 4] ws.addFormSelector("Start AP when", "apmode", len(optionvalues), options, optionvalues, None, int(settings.Settings["WifiAP"])) ws.addFormTextBox("SSID", "apssid", settings.Settings["APSSID"], 32) ws.addFormPasswordBox("Wifi Key", "apkey", settings.Settings["APKEY"], 64) try: tpw = settings.Settings["APCAPTIVE"] except: tpw = False ws.addFormCheckBox("Captive AP", "ap_captive", tpw) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" if int(settings.HW["lan-phy"]) > -1: ws.addFormSubHeader("LAN Settings") ws.addFormCheckBox("Enable LAN", "lanif", settings.Settings["LANIF"]) ws.addFormCheckBox("DHCP", "l_dhcp", settings.Settings["LDHCP"]) ws.addFormNote( "If DHCP enabled the settings below will not be saved or used!") ws.addFormTextBox("IP", "l_ip", settings.Settings["LIP"], 15) ws.addFormTextBox("Mask", "l_mask", settings.Settings["LMask"], 15) ws.addFormTextBox("GW", "l_gw", settings.Settings["LGW"], 15) ws.addFormTextBox("DNS", "l_dns", settings.Settings["LDNS"], 128) ws.TXBuffer += "<TR><TD style='width:150px;' align='left'><TD>" ws.addSubmitButton() ws.TXBuffer += "</table></form>" ws.sendHeadandTail("TmplStd", ws._TAIL) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = ""
def handle_controllers(httpResponse, responsearr): edit = ws.arg("edit", responsearr) controllerindex = ws.arg("index", responsearr) controllerNotSet = (controllerindex == 0) or (controllerindex == '') if controllerindex != "": controllerindex = int(controllerindex) - 1 controllerip = ws.arg("controllerip", responsearr) controllerport = ws.arg("controllerport", responsearr) protocol = ws.arg("protocol", responsearr) if protocol != "": protocol = int(protocol) else: protocol = 0 controlleruser = ws.arg("controlleruser", responsearr) controllerpassword = ws.arg("controllerpassword", responsearr) enabled = (ws.arg("controllerenabled", responsearr) == "on") if ((protocol == 0) and (edit == '') and (controllerindex != '')) or (ws.arg('del', responsearr) != ''): try: settings.Controllers[controllerindex].controller_exit() except: pass settings.Controllers[controllerindex] = False controllerNotSet = True settings.savecontrollers() if (controllerNotSet == False): # submitted if (protocol > 0): # submitted try: if (settings.Controllers[controllerindex]): settings.Controllers[ controllerindex].controllerip = controllerip settings.Controllers[ controllerindex].controllerport = controllerport settings.Controllers[ controllerindex].controlleruser = controlleruser if "**" not in controllerpassword: settings.Controllers[ controllerindex].controllerpassword = controllerpassword settings.Controllers[controllerindex].enabled = enabled settings.Controllers[controllerindex].webform_save( responsearr) settings.savecontrollers() except: pass else: try: if (settings.Controllers[controllerindex]): protocol = settings.Controllers[ controllerindex].controllerid except: pass ws.TXBuffer = "" httpResponse.WriteResponseOk(headers=({ 'Cache-Control': 'no-cache' }), contentType='text/html', contentCharset='UTF-8', content="") ws.navMenuIndex = 2 ws.sendHeadandTail("TmplStd", ws._HEAD) ws.TXBuffer += "<form name='frmselect' method='post'>" if (controllerNotSet): # show all in table ws.TXBuffer += "<table class='multirow' border=1px frame='box' rules='all'><TR><TH style='width:70px;'>" ws.TXBuffer += "<TH style='width:50px;'>Nr<TH style='width:100px;'>Enabled<TH>Protocol<TH>Host<TH>Port" for x in range(pglobals.CONTROLLER_MAX): ws.TXBuffer += "<tr><td><a class='button link' href=\"controllers?index=" ws.TXBuffer += str(x + 1) ws.TXBuffer += "&edit=1\">Edit</a><td>" ws.TXBuffer += ws.getControllerSymbol(x) ws.TXBuffer += "</td><td>" try: if (settings.Controllers[x]): ws.addEnabled(settings.Controllers[x].enabled) ws.TXBuffer += "</td><td>" ws.TXBuffer += str( settings.Controllers[x].getcontrollername()) ws.TXBuffer += "</td><td>" ws.TXBuffer += str(settings.Controllers[x].controllerip) ws.TXBuffer += "</td><td>" ws.TXBuffer += str(settings.Controllers[x].controllerport) else: ws.TXBuffer += "<td><td><td>" except: ws.TXBuffer += "<td><td><td>" httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" ws.TXBuffer += "</table></form>" httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" else: # edit ws.TXBuffer += "<table class='normal'><TR><TH style='width:150px;' align='left'>Controller Settings<TH>" ws.TXBuffer += "<tr><td>Protocol:<td>" ws.addSelector_Head("protocol", True) for x in range(len(pglobals.controllerselector)): ws.addSelector_Item( pglobals.controllerselector[x][2], int(pglobals.controllerselector[x][1]), (str(protocol) == str(pglobals.controllerselector[x][1])), False, "") ws.addSelector_Foot() httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" # print(protocol)#debug if (int(protocol) > 0): createnewcontroller = True try: if (settings.Controllers[controllerindex].getcontrollerid() == int(protocol)): createnewcontroller = False except: pass exceptstr = "" if createnewcontroller: for y in range(len(pglobals.controllerselector)): if int(pglobals.controllerselector[y][1]) == int(protocol): if len(settings.Controllers) <= controllerindex: while len(settings.Controllers) <= controllerindex: settings.Controllers.append(False) try: m = __import__(pglobals.controllerselector[y][0]) except Exception as e: # print(str(e)) settings.Controllers[controllerindex] = False exceptstr += str(e) m = False gc.collect() if m: try: settings.Controllers[ controllerindex] = m.Controller( controllerindex) except Exception as e: settings.Controllers.append( m.Controller(controllerindex)) exceptstr += str(e) break if settings.Controllers[controllerindex] == False: ws.TXBuffer += "Importing failed: {0}</td></tr></table>".format( exceptstr) ws.sendHeadandTail("TmplStd", ws._TAIL) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" return True else: try: settings.Controllers[controllerindex].controller_init( ) # call plugin init if (settings.Controllers[controllerindex]): if (settings.Controllers[controllerindex].enabled): settings.Controllers[ controllerindex].setonmsgcallback( settings.callback_from_controllers) for x in range(0, len(settings.Tasks)): if (settings.Tasks[x] and type(Settings.Tasks[x]) is not bool): # device exists if (settings.Tasks[x].enabled): # device enabled if (settings.Tasks[x]. senddataenabled[controllerindex]): if (settings.Controllers[controllerindex]): if (settings.Controllers[ controllerindex].enabled): settings.Tasks[x].controllercb[ controllerindex] = settings.Controllers[ controllerindex].senddata except: pass if controllerindex != '': ws.TXBuffer += "<input type='hidden' name='index' value='" + str( controllerindex + 1) + "'>" if int(protocol) > 0: ws.addFormCheckBox( "Enabled", "controllerenabled", settings.Controllers[controllerindex].enabled) ws.addFormTextBox( "Controller Host Address", "controllerip", settings.Controllers[controllerindex].controllerip, 96) ws.addFormNumericBox( "Controller Port", "controllerport", settings.Controllers[controllerindex].controllerport, 1, 65535) if settings.Controllers[controllerindex].usesAccount: ws.addFormTextBox( "Controller User", "controlleruser", settings.Controllers[controllerindex].controlleruser, 96) if settings.Controllers[controllerindex].usesPassword: ws.addFormPasswordBox( "Controller Password", "controllerpassword", settings. Controllers[controllerindex].controllerpassword, 96) # try: settings.Controllers[controllerindex].webform_load() # except: # pass ws.addFormSeparator(2) ws.TXBuffer += "<tr><td><td>" ws.TXBuffer += "<a class='button link' href=\"controllers\">Close</a>" ws.addSubmitButton() if controllerindex != '': ws.addSubmitButton("Delete", "del") ws.TXBuffer += "</table></form>" ws.sendHeadandTail("TmplStd", ws._TAIL) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = ""
def handle_hw(httpResponse,responsearr): ws.navMenuIndex=3 ws.TXBuffer = "" httpResponse.WriteResponseOk( headers = ({'Cache-Control': 'no-cache'}), contentType = 'text/html', contentCharset = 'UTF-8', content = "" ) method = ws.arg("method",responsearr) saved = ws.arg("Submit",responsearr) if (saved): try: tvar = int(ws.arg('freq',responsearr)) esp_os.setfreq(tvar) settings.HW['freq']=int(tvar) settings.HW['psram-cs']= int(ws.arg('psram-cs',responsearr)) settings.HW['psram-clk']= int(ws.arg('psram-clk',responsearr)) except: pass iname="" tname="" try: if "i2c0-freq" in responsearr: for i in range(2): iname = "i2c{0}".format(i) settings.HW[iname] = (ws.arg(iname,responsearr) == "on") if settings.HW[iname]: tname = iname+"-freq" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-sda" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-scl" settings.HW[tname] = int(ws.arg(tname,responsearr)) except: pass try: if 'spic-baud' in responsearr: iname = 'spic' settings.HW[iname] = (ws.arg(iname,responsearr) == "on") tname = iname+"-clk" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-mosi" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-miso" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-baud" settings.HW[tname] = int(ws.arg(tname,responsearr)) except: pass try: if "spi1-baud" in responsearr: for i in range(1,3): iname = "spi{0}".format(i) if 'spic' in responsearr: settings.HW[iname] = False else: settings.HW[iname] = (ws.arg(iname,responsearr) == "on") if settings.HW[iname]: # tname = iname+"-cs" # settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-baud" settings.HW[tname] = int(ws.arg(tname,responsearr)) except: pass try: if "uart1-baud" in responsearr: for i in range(1,3): iname = "uart{0}".format(i) settings.HW[iname] = (ws.arg(iname,responsearr) == "on") if settings.HW[iname]: tname = iname+"-rx" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-tx" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-baud" settings.HW[tname] = int(ws.arg(tname,responsearr)) tname = iname+"-timeout" settings.HW[tname] = int(ws.arg(tname,responsearr)) except: pass try: li = int(ws.arg("lanphy",responsearr)) except: li = -1 settings.HW["lan-phy"] = li if li >-1 and ("lanphy" in responsearr): settings.HW["lan-mdc"] = int(ws.arg("lanmdc",responsearr)) settings.HW["lan-mdio"] = int(ws.arg("lanmdio",responsearr)) settings.HW["lan-pwr"] = int(ws.arg("lanpwr",responsearr)) settings.HW["lan-addr"] = int(ws.arg("lanaddr",responsearr)) settings.HW["lan-clk"] = int(ws.arg("lanclk",responsearr)) if "p0" in responsearr: for p in range(40): pv = -1 try: pv = int(ws.arg("p"+str(p),responsearr)) except: pv = -1 if pv > -1: psuc = False for ap in range(len(settings.Pinout)): if int(settings.Pinout[ap]['p']) == int(p): settings.Pinout[ap]['m'] = pv psuc = True break if psuc==False: settings.Pinout.append({'p':p,'m':pv}) settings.savehwsettings() settings.savepinout() try: libhw.initgpio() except: pass # else: # settings.loadhwsettings() # settings.loadpinout() ws.sendHeadandTail("TmplStd",ws._HEAD) ws.addHtml("<p><div><a class='menu2' href='hardware'>Main</a> | <a class='menu2' href='hardware?method=i2c'>I2C</a> | <a class='menu2' href='hardware?method=spi'>SPI</a> | <a class='menu2' href='hardware?method=uart'>UART</a> | <a class='menu2' href='hardware?method=lan'>LAN</a></div>") ws.TXBuffer += "<form name='frmselect' method='post'><table class='normal'>" if method=="": # ws.addFormSeparator(3) ws.addFormHeader("Main") httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" options = ['80','160','240'] optionvalues = [80000000, 160000000, 240000000] afreq = int(esp_os.getfreq()) if afreq not in optionvalues: optionvalues.append(afreq) options.append(str(afreq)) ws.addFormSelector("Core speed","freq",len(optionvalues),options,optionvalues,None,afreq) ws.addUnit('MHz') ws.addFormPinSelect("PSRAM-CS",'psram-cs',settings.HW['psram-cs'],1) ws.addFormPinSelect("PSRAM-CLK",'psram-clk',settings.HW['psram-clk'],1) ws.addFormNote("Set to none only when no PSRAM connected!") httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" if method=="i2c": ws.addFormHeader("I2C") options = ['100','400'] optionvalues = [100000, 400000] iname = "" tname = "" for i in range(2): iname = "i2c{0}".format(i) ws.addFormCheckBox("Enable I2C-"+str(i),iname,settings.HW[iname]) tname = iname+"-freq" ws.addFormSelector("Speed",tname,len(optionvalues),options,optionvalues,None,settings.HW[tname]) ws.addUnit('kHz') tname = iname+"-sda" tval = settings.HW[tname] if tval<0: if i==0: tval = 21 else: tval = 16 ws.addFormPinSelect("SDA",tname,tval,1) tname = iname+"-scl" tval = settings.HW[tname] if tval<0: if i==0: tval = 22 else: tval = 17 ws.addFormPinSelect("SCL",tname,tval,1) httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" if method=="spi": ws.addFormHeader("SPI") options = ['1','5','10','18','20','26','40','48','80'] optionvalues = [10000000,50000000,10000000,18000000,20000000,26000000,40000000,48000000,80000000] for i in range(1,3): iname = "spi{0}".format(i) ws.addFormCheckBox("Enable Hardware SPI-"+str(i),iname,settings.HW[iname]) if i==1: ws.addFormNote('MOSI=13, MISO=12, CLK=14') elif i==2: ws.addFormNote('MOSI=23, MISO=19, CLK=18') tname = iname+"-baud" aspd = settings.HW[tname] if aspd<1: aspd = 18000000 ws.addFormSelector("Speed",tname,len(optionvalues),options,optionvalues,None,aspd) ws.addUnit("Mhz") # tname = iname+"-cs" # tval = settings.HW[tname] # if tval<0: # if i==1: # tval = 15 # else: # tval = 5 # ws.addFormPinSelect("CS",tname,tval,1) try: iname = "spic" ws.addFormCheckBox("Enable Custom SPI",iname,settings.HW[iname]) tname = iname+"-baud" aspd = settings.HW[tname] if aspd<1: aspd = 18000000 ws.addFormSelector("Speed",tname,len(optionvalues),options,optionvalues,None,aspd) ws.addUnit("Mhz") tname = iname+"-clk" ws.addFormPinSelect("CLK",tname,settings.HW[tname],1) tname = iname+"-mosi" ws.addFormPinSelect("MOSI",tname,settings.HW[tname],1) tname = iname+"-miso" ws.addFormPinSelect("MISO",tname,settings.HW[tname],0) except Exception as e: settings.HW[iname] = 0 settings.HW[iname+"-clk"] = -1 settings.HW[iname+"-mosi"] = -1 settings.HW[iname+"-miso"] = -1 settings.HW[iname+"-baud"] = 0 httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" if method=="uart": ws.addFormHeader("UART") for i in range(1,3): iname = "uart{0}".format(i) ws.addFormCheckBox("Enable UART-"+str(i),iname,settings.HW[iname]) tname = iname+"-baud" ws.addFormNumericBox("Baud",tname,settings.HW[tname],0,921600) tname = iname+"-timeout" ws.addFormNumericBox("Timeout",tname,settings.HW[tname],0,50000) tname = iname+"-rx" tval = settings.HW[tname] if tval<0: if i==0: tval = 9 else: tval = 16 ws.addFormPinSelect("RX",tname,tval,1) tname = iname+"-tx" tval = settings.HW[tname] if tval<0: if i==0: tval = 10 else: tval = 17 ws.addFormPinSelect("TX",tname,tval,1) httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" if method=="lan": try: optionvalues1 = unet.get_net_const("phy") optionvalues2 = unet.get_net_const("clk") lanok = True except Exception as e: # print("LAN failed ",e)#debug lanok = False if lanok: ws.addFormHeader("LAN RMII interface") options = ['Disabled','LAN8720','TLK110','IP101'] ws.addFormSelector("LAN PHY","lanphy",len(optionvalues1),options,optionvalues1,None,settings.HW["lan-phy"]) options = ['GPIO0 (default)','GPIO16','GPIO17'] ws.addFormSelector("LAN CLK mode","lanclk",len(optionvalues2),options,optionvalues2,None,settings.HW["lan-clk"]) ws.addFormNumericBox("PHY Address","lanaddr",settings.HW["lan-addr"],0,0x1F) ws.addFormPinSelect("PHY MDC","lanmdc",settings.HW["lan-mdc"],1) ws.addFormPinSelect("PHY MDIO","lanmdio",settings.HW["lan-mdio"],1) ws.addFormPinSelect("PHY Power enable","lanpwr",settings.HW["lan-pwr"],1) httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" if method=="": ws.addHtml("<tr><th>GPIO</th><th>Requested startup state</th><th>Value</th></tr>") for p in range(40): if gpiohelp.is_pin_valid(p): reserved = False value = "" if settings.HW['psram-cs']==p: reserved = True value = "PSRAM-CS" elif settings.HW['psram-clk']==p: reserved = True value = "PSRAM-CLK" if settings.HW["lan-phy"]>-1: cpin = 0 if unet.get_net_const("c16o")==settings.HW["lan-clk"]: cpin = 16 elif unet.get_net_const("c17o")==settings.HW["lan-clk"]: cpin = 17 if p==settings.HW["lan-mdc"]: reserved = True value = "LAN MDC" elif p==settings.HW["lan-mdio"]: reserved = True value = "LAN MDIO" elif p==settings.HW["lan-pwr"]: reserved = True value = "LAN PWR" elif p==cpin: reserved = True value = "LAN CLK" if p in [22,19,21,26,25,27]: reserved = True value = "RMII LAN" if settings.HW['i2c0']: if settings.HW['i2c0-sda']==p: reserved = True value = "I2C0-SDA" elif settings.HW['i2c0-scl']==p: reserved = True value = "I2C0-SCL" if settings.HW['i2c1']: if settings.HW['i2c1-sda']==p: reserved = True value = "I2C1-SDA" elif settings.HW['i2c1-scl']==p: reserved = True value = "I2C1-SCL" if settings.HW['uart1']: if settings.HW['uart1-rx']==p: reserved = True value = "UART1-RX" elif settings.HW['uart1-tx']==p: reserved = True value = "UART1-TX" if settings.HW['uart2']: if settings.HW['uart2-rx']==p: reserved = True value = "UART2-RX" elif settings.HW['uart2-tx']==p: reserved = True value = "UART2-TX" if settings.HW['spi1']: # hspi # if settings.HW['spi1-cs']==p: # reserved = True # value = "SPI1-CS" if p==12: reserved = True value = "SPI1-MISO" elif p==13: reserved = True value = "SPI1-MOSI" elif p==14: reserved = True value = "SPI1-CLK" if settings.HW['spi2']: # vspi # if settings.HW['spi2-cs']==p: # reserved = True # value = "SPI2-CS" if p==19: reserved = True value = "SPI2-MISO" elif p==23: reserved = True value = "SPI2-MOSI" elif p==18: reserved = True value = "SPI2-CLK" try: if settings.HW['spic']: # custom spi if settings.HW['spic-clk']==p: reserved = True value = "SPI-CLK" elif settings.HW['spic-miso']==p: reserved = True value = "SPI-MISO" elif settings.HW['spic-mosi']==p: reserved = True value = "SPI-MOSI" except: pass if reserved==False: if p==1: reserved = True value = "UART0-TX" elif p==3: reserved = True value = "UART0-RX" options = settings.PinStates amode = 0 apin = -1 nonres = False try: if str(value).strip()=="": nonres = True except: pass try: for pin in range(len(settings.Pinout)): if int(settings.Pinout[pin]['p']) == int(p): if settings.Pinout[pin]['m']==9: if nonres: settings.Pinout[pin]['m']=0 amode = settings.Pinout[pin]['m'] apin = pin except Exception as e: amode = 0 if reserved: amode = 9 if reserved and value and value != "": svalue = str(value) else: svalue = "" if apin==-1: settings.Pinout.append({'p':p,'m':amode,'d':svalue}) else: settings.Pinout[apin] = {'p':p,'m':amode,'d':svalue} attr = [] if amode==9: for a in range(9): attr.append("DISABLED") attr.append("") else: if p<34: for a in range(7): attr.append("") for a in range(2): attr.append("DISABLED") else: for a in range(2): attr.append("") for a in range(2,12): attr.append("DISABLED") optionvalues = [0,1,2,3,4,5,6,7,8,9] ws.addHtml("<tr><td align=right>D"+str(p)+"</td><td>") try: ws.addSelector("p"+str(p),len(options),options,optionvalues,attr,amode,False) except Exception as e: pass ws.addHtml("</td><td>"+str(value)+"</td></tr>") if (p % 5)==0: httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" ws.addFormSeparator(3) ws.TXBuffer += "<tr><td colspan=3>" ws.addSubmitButton() ws.addFormNote('WARNING: Some changes needed to reboot after submitting changes!') ws.TXBuffer += "</table></form>" ws.sendHeadandTail("TmplStd",ws._TAIL) httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = ""
def handle_adv(httpResponse, responsearr): ws.navMenuIndex = 7 ws.TXBuffer = "" httpResponse.WriteResponseOk(headers=({ 'Cache-Control': 'no-cache' }), contentType='text/html', contentCharset='UTF-8', content="") saved = ws.arg("Submit", responsearr) if (saved): settings.AdvSettings["webloglevel"] = int( ws.arg("webloglevel", responsearr)) settings.AdvSettings["consoleloglevel"] = int( ws.arg("consoleloglevel", responsearr)) settings.AdvSettings["usentp"] = (ws.arg("usentp", responsearr) == "on") settings.AdvSettings["ntpserver"] = ws.arg("ntpserver", responsearr) settings.AdvSettings["timezone"] = int(ws.arg("timezone", responsearr)) try: settings.AdvSettings["rtci2c"] = int(ws.arg("rtci2c", responsearr)) if settings.AdvSettings["rtci2c"] >= 0: settings.AdvSettings["extrtc"] = int( ws.arg("extrtc", responsearr)) if settings.AdvSettings["rtcaddr"] >= 0: settings.AdvSettings["rtcaddr"] = int( ws.arg("rtcaddr", responsearr)) except: settings.AdvSettings["extrtc"] = 0 settings.AdvSettings["rtci2c"] = 0 try: settings.AdvSettings["dangerouspins"] = ws.arg( "dangerouspins", responsearr) except: settings.AdvSettings["dangerouspins"] = False try: settings.AdvSettings["Latitude"] = float( ws.arg("latitude", responsearr)) settings.AdvSettings["Longitude"] = float( ws.arg("longitude", responsearr)) except: settings.AdvSettings["Latitude"] = 0 settings.AdvSettings["Longitude"] = 0 try: settings.AdvSettings["startpage"] = str( ws.arg("startpage", responsearr)) except: settings.AdvSettings["startpage"] = "/" settings.saveadvsettings() ws.sendHeadandTail("TmplStd", ws._HEAD) ws.TXBuffer += "<form method='post'><table class='normal'>" ws.addFormHeader("Advanced Settings") ws.addFormSubHeader("Log Settings") httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = "" ws.addFormLogLevelSelect("Console log Level", "consoleloglevel", settings.AdvSettings["consoleloglevel"]) ws.addFormLogLevelSelect("Web log Level", "webloglevel", settings.AdvSettings["webloglevel"]) ws.addFormSubHeader("Time Settings") ws.addFormCheckBox("Enable NTP", "usentp", settings.AdvSettings["usentp"]) ws.addFormTextBox("NTP server name", "ntpserver", settings.AdvSettings["ntpserver"], 100) ws.addFormNumericBox("Timezone offset", "timezone", settings.AdvSettings["timezone"], -720, 840) ws.addUnit("min") try: extrtc = settings.AdvSettings["extrtc"] except: settings.AdvSettings["extrtc"] = 0 extrtc = 0 options = ["Disable", "DS1307", "DS3231", "PCF8523"] optionvalues = [0, 1307, 3231, 8523] ws.addFormSelector("External RTC type", "extrtc", len(optionvalues), options, optionvalues, None, extrtc) try: import inc.libhw as libhw options = libhw.geti2clist() except: options = [] try: rtci2c = settings.AdvSettings["rtci2c"] except: rtci2c = 0 settings.AdvSettings["rtci2c"] = 0 ws.addHtml("<tr><td>RTC I2C line:<td>") ws.addSelector_Head("rtci2c", True) for d in range(len(options)): ws.addSelector_Item("I2C" + str(options[d]), options[d], (rtci2c == options[d]), False) ws.addSelector_Foot() try: rtcaddr = settings.AdvSettings["rtcaddr"] except: rtcaddr = 0 settings.AdvSettings["rtcaddr"] = 0 options = ["0", "0x68", "0x51"] optionvalues = [0, 0x68, 0x51] ws.addFormSelector("RTC I2C address", "rtcaddr", len(optionvalues), options, optionvalues, None, rtcaddr) res = "" try: if settings.AdvSettings['extrtc'] > 0 and settings.AdvSettings[ 'rtci2c'] >= 0: import inc.mrtc as mrtc try: import inc.libhw as libhw except: pass if mrtc.I2C_RTC is None: if settings.AdvSettings['rtci2c'] == 0: rtcok = mrtc.rtcinit(settings.AdvSettings['extrtc'], libhw.i2c0, settings.AdvSettings["rtcaddr"]) elif settings.AdvSettings['rtci2c'] == 1: rtcok = mrtc.rtcinit(settings.AdvSettings['extrtc'], libhw.i2c1, settings.AdvSettings["rtcaddr"]) ret = mrtc.getrtctime() res = '{:04}-{:02}-{:02} {:02}:{:02}:{:02}'.format( ret[0], ret[1], ret[2], ret[4], ret[5], ret[6]) except Exception as e: res = "RTC not available " + str(e) if settings.AdvSettings['extrtc'] > 0: ws.addFormNote(res) ws.addFormSubHeader("Misc Settings") try: dpins = settings.AdvSettings["dangerouspins"] except: dpins = False ws.addFormCheckBox("Show dangerous pins", "dangerouspins", dpins) try: sp = settings.AdvSettings["startpage"] except: sp = "/" ws.addFormTextBox("Start page", "startpage", sp, 64) ws.addFormSubHeader("Location Settings") try: lat = settings.AdvSettings["Latitude"] lon = settings.AdvSettings["Longitude"] except: lat = 0 lon = 0 ws.addFormFloatNumberBox("Latitude", "latitude", lat, -90.0, 90.0) ws.addUnit("°") ws.addFormFloatNumberBox("Longitude", "longitude", lon, -180.0, 180.0) ws.addUnit("°") ws.addFormSeparator(2) ws.TXBuffer += "<TR><TD style='width:150px;' align='left'><TD>" ws.addSubmitButton() ws.TXBuffer += "<input type='hidden' name='edit' value='1'>" ws.TXBuffer += "</table></form>" ws.sendHeadandTail("TmplStd", ws._TAIL) httpResponse._write(ws.TXBuffer, strEncoding='UTF-8') ws.TXBuffer = ""
def webform_load(self): ws.addFormNote("IP and Port parameter is not used!") ws.addFormNote("SX127x hardware supported by uPyLoRa library") ws.addHtml( "<p>Example sender sketches could be find <a href='https://github.com/enesbcs/EasyLora'>here</a>." ) ws.addTableSeparator("Hardware settings", 2, 3) try: options = libhw.getspilist() except: options = [] ws.addHtml("<tr><td>SPI line:<td>") ws.addSelector_Head("spi", True) for d in range(len(options)): ws.addSelector_Item("SPI" + str(options[d]), options[d], (self.spi == options[d]), False) ws.addSelector_Foot() ws.addFormPinSelect("DIO0 (IRQ) pin", "dio_0", self.dio_0, 0) ws.addFormPinSelect("SS pin", "ss", self.ss, 1) ws.addFormPinSelect("RST pin", "rst", self.rst, 1) ws.addFormNote("Optional") ws.addFormPinSelect("LED pin", "led", self.led, 1) ws.addFormNote("Optional") try: ws.addTableSeparator("LoRa settings", 2, 3) ws.addFormFloatNumberBox("Frequency", "freq", self.freq, 433, 928) ws.addUnit("Mhz") if self._lora is not None: try: afreq = (self._lora._frequency) / 1000000 except: afreq = "UNINITIALIZED" ws.addFormNote("Current frequency: " + str(afreq) + " Mhz") ws.addFormNote( "Please check local regulations for your selected frequency!") options = ["10%", "1%", "0.1%"] optionvalues = [10, 100, 1000] ws.addFormSelector("Duty cycle", "duty", len(optionvalues), options, optionvalues, None, self.duty) ws.addFormNote( "Please check your local Duty cycle regulations for your selected frequency!" ) ws.addFormNumericBox("Spreading factor", "spreading", self.sf, 6, 12) options = [ "7.8", "10.4", "15.6", "20.8", "31.25", "41.7", "62.5", "125", "250" ] optionvalues = [ 7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3, 41.7E3, 62.5E3, 125E3, 250E3 ] ws.addFormSelector("Bandwidth", "bw", len(optionvalues), options, optionvalues, None, self.bw) ws.addUnit("khz") options = ["CR4/5", "CR4/6", "CR4/7", "CR4/8"] optionvalues = [5, 6, 7, 8] ws.addFormSelector("Coding rate", "coding", len(optionvalues), options, optionvalues, None, self.coding) ws.addFormNumericBox("Sync Word", "sync", self.sync, 0, 255) ws.addHtml('( 0x{:02x} )'.format(self.sync)) ws.addFormNote( "Default 0x12, LoRaWAN is 0x34. Nodes can only communicate each other if uses same sync word!" ) ws.addFormCheckBox("Enable Sending", "sender", self.enablesend) ws.addFormNumericBox("Default destination node index", "defaultnode", self.defaultunit, 0, 255) ws.addFormNote("Default node index for data sending") except Exception as e: misc.addLog(pglobals.LOG_LEVEL_ERROR, str(e)) return True
def webform_load(self): # create html page for settings gc.collect() ws.addFormNote("Enable <a href='hardware'>SPI bus</a> first!") ws.addFormPinSelect("CS", "p302_cs", self.cs, 1) ws.addFormPinSelect("DC", "p302_dc", self.dc, 1) ws.addFormPinSelect("RST", "p302_rst", self.rst, 1) ws.addFormNote("Optional") try: ws.addHtml("<tr><td>Variant:<td>") options = ['Red/M5StickC', 'Blue', 'Blue2', 'Green'] optionvalues = ['r', 'b', 'b2', 'g'] ws.addSelector_Head("p302_disptype", False) for d in range(len(options)): ws.addSelector_Item(options[d], optionvalues[d], (self.disptype == optionvalues[d]), False) ws.addSelector_Foot() except: pass gc.collect() ws.addFormNumericBox("Width", "p302_width", self.width, 1, 320) ws.addFormNumericBox("Height", "p302_height", self.height, 1, 320) ws.addFormNumericBox("X offset", "p302_xoffset", self.xoffset, 0, 100) ws.addFormNumericBox("Y offset", "p302_yoffset", self.yoffset, 0, 100) options = ["RGB", "BGR"] optionvalues = [1, 0] ws.addFormSelector("Color mode", "p302_rgb", len(optionvalues), options, optionvalues, None, self.rgb) options = ["0", "90", "180", "270"] optionvalues = [0, 90, 180, 270] ws.addFormSelector("Rotation", "p302_rotate", len(optionvalues), options, optionvalues, None, self.rotate) ws.addUnit("deg") try: choice5 = int(float( self.taskdevicepluginconfig[4])) # store line count ws.addHtml("<tr><td>Number of lines:<td>") ws.addSelector_Head("p302_linecount", False) for l in range(1, self.P302_Nlines + 1): ws.addSelector_Item(str(l), l, (l == choice5), False) ws.addSelector_Foot() except: pass ws.addFormNumericBox("Try to display # characters per row", "p302_charperl", self.taskdevicepluginconfig[5], 1, 32) ws.addFormNote("Leave it '1' if you do not care") ws.addFormCheckBox("Clear only used lines", "p302_partialclear", self.taskdevicepluginconfig[6]) if choice5 > 0 and choice5 < 9: lc = choice5 else: lc = self.P302_Nlines for l in range(lc): try: linestr = self.lines[l] except: linestr = "" ws.addFormTextBox("Line" + str(l + 1), "p302_template" + str(l), linestr, 128) return True