def webform_load(self): # create html page for settings choice1 = self.taskdevicepluginconfig[0] options = ["0x23", "0x5c"] optionvalues = [0x23, 0x5c] ws.addFormSelector("I2C address", "plugin_010_addr", 2, options, optionvalues, None, int(choice1)) ws.addFormNote( "Enable <a href='hardware'>I2C bus</a> first, than <a href='i2cscanner'>search for the used address</a>!" ) 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("Remote Device Address", "plugin_527_addr", str(self.address), 20) ws.addFormNote( "Supported device types: LYWSD02, CGQ, CGG1, MiFlora, ATC") ws.addFormNote( "If you are using Sniffer, you can not use any other BLE plugin, as scanning is continous! Although multiple sniffer task can be used." ) choice1 = self.taskdevicepluginconfig[0] choice2 = self.taskdevicepluginconfig[1] choice3 = self.taskdevicepluginconfig[2] choice4 = self.taskdevicepluginconfig[3] options = [ "None", "Temperature", "Humidity", "Light", "Moisture", "Fertility", "Battery", "RSSI" ] optionvalues = [-1, 4, 6, 7, 8, 9, 10, 200] ws.addFormSelector("Indicator1", "plugin_527_ind0", len(optionvalues), options, optionvalues, None, choice1) ws.addFormSelector("Indicator2", "plugin_527_ind1", len(optionvalues), options, optionvalues, None, choice2) ws.addFormSelector("Indicator3", "plugin_527_ind2", len(optionvalues), options, optionvalues, None, choice3) ws.addFormSelector("Indicator4", "plugin_527_ind3", len(optionvalues), options, optionvalues, None, choice4) return True
def webform_load(self): # create html page for settings ws.addFormNote("Default I2C address is 0x34") ws.addFormHeader("Initialization states") ws.addFormCheckBox("LD02", "p301_p0", self.axparams[0]) ws.addFormCheckBox("LD03", "p301_p1", self.axparams[1]) ws.addFormCheckBox("RTC", "p301_p2", self.axparams[2]) ws.addFormCheckBox("DCDC1", "p301_p3", self.axparams[3]) ws.addFormCheckBox("DCDC3", "p301_p4", self.axparams[4]) ws.addFormHeader("Values") choice1 = self.taskdevicepluginconfig[0] choice2 = self.taskdevicepluginconfig[1] choice3 = self.taskdevicepluginconfig[2] choice4 = self.taskdevicepluginconfig[3] options = [ "None", "Button", "Temperature", "BATT Voltage", "BATT Current", "BATT Power", "BATT Charge", "IN Voltage", "IN Current", "Bus Voltage", "Bus Current" ] optionvalues = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ws.addFormSelector("Indicator1", "plugin_301_ind0", len(options), options, optionvalues, None, choice1) ws.addFormSelector("Indicator2", "plugin_301_ind1", len(options), options, optionvalues, None, choice2) ws.addFormSelector("Indicator3", "plugin_301_ind2", len(options), options, optionvalues, None, choice3) ws.addFormSelector("Indicator4", "plugin_301_ind3", len(options), options, optionvalues, None, choice4) return True
def webform_load(self): # create html page for settings try: choice1 = self.taskdevicepluginconfig[0] options = ["DHT11", "DHT22/AM2302"] optionvalues = [11, 22] ws.addFormSelector("Sensor type", "plugin_005_type", 2, options, optionvalues, None, int(choice1)) except: pass ws.addFormCheckBox("Oversampling", "plugin_005_over", self.timer2s) ws.addFormNote( "Strongly recommended to enable oversampling for reliable readings!" ) 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): # ws.addFormNote("Please make sure to select <a href='hardware'>pin configured</a> for input for default (or output to report back its state)!") ws.addFormCheckBox("Force 10/sec periodic checking of pin", "p001_per", self.taskdevicepluginconfig[0]) # ws.addFormNote("For output pin, only 10/sec periodic method will work!") # ws.addFormNumericBox("De-bounce (ms)","p001_debounce",self.taskdevicepluginconfig[1],0,1000) options = [ "Normal Switch", "Push Button Active Low", "Push Button Active High" ] optionvalues = [0, 1, 2] ws.addFormSelector("Switch Button Type", "p001_button", len(optionvalues), options, optionvalues, None, self.taskdevicepluginconfig[2]) ws.addFormNote("Use only normal switch for output type, i warned you!") 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 choice1 = self.taskdevicepluginconfig[0] choice2 = self.taskdevicepluginconfig[1] choice3 = self.taskdevicepluginconfig[2] choice4 = self.taskdevicepluginconfig[3] options = ["None", "Uptime", "Free RAM", "Wifi RSSI", "CPU Temp"] optionvalues = [0, 1, 2, 3, 4] ws.addFormSelector("Indicator1", "plugin_026_ind0", len(options), options, optionvalues, None, choice1) ws.addFormSelector("Indicator2", "plugin_026_ind1", len(options), options, optionvalues, None, choice2) ws.addFormSelector("Indicator3", "plugin_026_ind2", len(options), options, optionvalues, None, choice3) ws.addFormSelector("Indicator4", "plugin_026_ind3", len(options), options, optionvalues, None, choice4) return True
def webform_load(self): # create html page for settings ws.addFormCheckBox("Use standard HTML head","p212_head",self.taskdevicepluginconfig[2]) try: sp = settings.AdvSettings["startpage"] except: sp = "/" ws.addFormCheckBox("Set as startpage","p212_start",(sp=="/dash")) ws.addHtml("<tr><td>Columns:<td>") ws.addSelector_Head("p212_cols",False) for o in range(7): ws.addSelector_Item(str(o),o,(str(o)==str(self.taskdevicepluginconfig[0])),False) ws.addSelector_Foot() ws.addHtml("<tr><td>Rows:<td>") ws.addSelector_Head("p212_rows",False) for o in range(16): ws.addSelector_Item(str(o),o,(str(o)==str(self.taskdevicepluginconfig[1])),False) ws.addSelector_Foot() if int(self.taskdevicepluginconfig[0])>0 and int(self.taskdevicepluginconfig[1])>0: if self.enabled: ws.addHtml("<tr><td>Dashboard address:</td><td><a href='dash'>/dash</a></td></tr>") options1 = ["None","Text","Binary input","Switch output","Meter","Gauge","Slider output","Select output"] optionvalues1 = [-1,0,1,2,3,4,5,6] options2 = ["None"] optionvalues2 = ["_"] try: for t in range(0,len(settings.Tasks)): if (settings.Tasks[t] and (type(settings.Tasks[t]) is not bool)): for v in range(0,settings.Tasks[t].valuecount): options2.append("T"+str(t+1)+"-"+str(v+1)+" / "+str(settings.Tasks[t].taskname)+"-"+str(settings.Tasks[t].valuenames[v])) optionvalues2.append(str(t)+"_"+str(v)) except Exception as e: print(e) for r in range(int(self.taskdevicepluginconfig[1])): try: for c in range(int(self.taskdevicepluginconfig[0])): offs = (r * int(self.taskdevicepluginconfig[0])) + c try: adata = self.celldata[offs] except: adata = {} dtype = -1 if "type" in adata: dtype = int(adata["type"]) ws.addHtml("<tr><td><b>Cell"+str(offs)+" (y"+str(r)+"x"+str(c)+")</b><td>") dname = "" if "name" in adata: dname = str(adata["name"]) ws.addFormTextBox("Name overwrite","p212_names_"+str(offs),dname,64) ws.addFormSelector("Type","p212_type_"+str(offs),len(options1),options1,optionvalues1,None,dtype) ws.addHtml("<tr><td>Data source:<td>") ddata = "_" if "data" in adata: ddata = str(adata["data"]) ws.addSelector_Head("p212_data_"+str(offs),False) for o in range(len(options2)): ws.addSelector_Item(options2[o],optionvalues2[o],(str(optionvalues2[o])==str(ddata)),False) ws.addSelector_Foot() if dtype in (0,4): try: udata = str(adata["unit"]) except: udata = "" ws.addFormTextBox("Unit","p212_unit_"+str(offs),udata,16) if dtype in (3,4,5): try: umin = float(adata["min"]) except: umin = 0 try: umax = float(adata["max"]) except: umax = 100 ws.addFormFloatNumberBox("Min value","p212_min_"+str(offs),umin,-65535.0,65535.0) ws.addFormFloatNumberBox("Max value","p212_max_"+str(offs),umax,-65535.0,65535.0) elif dtype == 6: try: uon = str(adata["optionnames"]) except: uon = "" try: uopt = str(adata["options"]) except: uopt = "" ws.addFormTextBox("Option name list","p212_optionnames_"+str(offs),uon,1024) ws.addFormTextBox("Option value list","p212_options_"+str(offs),uopt,1024) ws.addFormNote("Input comma separated values for selector boxes!") httpResponse._write(ws.TXBuffer,strEncoding='UTF-8') ws.TXBuffer = "" except: pass return True
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_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