Exemple #1
0
 def webform_load(self): # create html page for settings
  ws.addFormTextBox("Teams channel Webhook URL","fullurl",self.fullurl,512)
  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
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
 def webform_load(self):  # create html page for settings
     ws.addFormTextBox("Device Address", "plugin_517_addr",
                       str(self.taskdevicepluginconfig[0]), 20)
     ws.addFormNote(
         "Enable blueetooth then <a href='blescanner'>scan LYWSD03 address</a> first."
     )
     ws.addFormCheckBox("Add Battery value for non-Domoticz system",
                        "plugin_517_bat", self.taskdevicepluginconfig[1])
     return True
Exemple #5
0
    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
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #8
0
 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
Exemple #9
0
 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
Exemple #10
0
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 = ""
Exemple #11
0
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 = ""
Exemple #12
0
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 = ""
Exemple #13
0
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("&deg;")
    ws.addFormFloatNumberBox("Longitude", "longitude", lon, -180.0, 180.0)
    ws.addUnit("&deg;")

    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 = ""
Exemple #14
0
    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