Beispiel #1
0
    def doLoop(self):
        nextLoopCheck = time.time()
        while True:
            loopStartTime = time.time()
            if loopStartTime >= nextLoopCheck:
                print "running loop"
                checkInterval, boiler_enabled, useNeoPixel = Variables().readVariables(['Interval', 'BoilerEnabled', 'UseNeoPixel'])
                
                if boiler_enabled != 1:
                    checkInterval = checkInterval * 2
                if _platform == "linux" or _platform == "linux2":
                    if not useNeoPixel:
                        self.logger.info("checking heat levels")
                        buttonCheckHeat("main")
                        self.logger.info("starting heartbeat")
                        hBeat(checkInterval)
                        self.logger.info("Memory free this loop %s MB" % hardware.getRAM())
                        self.logger.info("CPU Usage this loop %s" % hardware.getCPUUse())
                        self.logger.debug( "loop interval : %s" %(checkInterval))
                        self.doLoop()
                    else:
                        self.logger.info("checking heat levels")
                        MaxInterface().checkHeat(input_queue)
                        self.logger.info('Running NeoPixel timer')
                        self.logger.info("Memory free this loop %s MB" % hardware.getRAM())
                        self.logger.info("CPU Usage this loop %s" % hardware.getCPUUse())
                        self.logger.debug( "loop interval : %s" %(checkInterval))
                else:
                    MaxInterface().checkHeat(input_queue)
                    self.logger.info('Running Windows timer')
                    
                
                    
                nextLoopCheck = loopStartTime + checkInterval
                
            if not output_queue.empty():
                serialData = output_queue.get().rstrip()
                self.processSerial(serialData)

            time.sleep(.2)
Beispiel #2
0
    def doLoop(self):
        nextLoopCheck = time.time()
        while True:
            loopStartTime = time.time()
            if loopStartTime >= nextLoopCheck:
                print "running loop"
                checkInterval, boiler_enabled, useNeoPixel = Variables().readVariables(
                    ["Interval", "BoilerEnabled", "UseNeoPixel"]
                )

                if boiler_enabled != 1:
                    checkInterval = checkInterval * 2
                if _platform == "linux" or _platform == "linux2":
                    if not useNeoPixel:
                        self.logger.info("checking heat levels")
                        buttonCheckHeat("main")
                        self.logger.info("starting heartbeat")
                        hBeat(checkInterval)
                        self.logger.info("Memory free this loop %s MB" % hardware.getRAM())
                        self.logger.info("CPU Usage this loop %s" % hardware.getCPUUse())
                        self.logger.debug("loop interval : %s" % (checkInterval))
                        self.doLoop()
                    else:
                        self.logger.info("checking heat levels")
                        MaxInterface().checkHeat(input_queue)
                        self.logger.info("Running NeoPixel timer")
                        self.logger.info("Memory free this loop %s MB" % hardware.getRAM())
                        self.logger.info("CPU Usage this loop %s" % hardware.getCPUUse())
                        self.logger.debug("loop interval : %s" % (checkInterval))
                else:
                    MaxInterface().checkHeat(input_queue)
                    self.logger.info("Running Windows timer")

                nextLoopCheck = loopStartTime + checkInterval

            if not output_queue.empty():
                serialData = output_queue.get().rstrip()
                self.processSerial(serialData)

            time.sleep(0.2)
    def do_GET(self):
        useNeoPixel = VAR.readVariables(['UseNeoPixel'])
        module_logger.debug("GET %s" % self.path)
        if self.path == "/":
            roomTemps = CUI.createRooms()
            self.path = "/index.html"
            self.updateUIPages(roomTemps)

        elif self.path[0:8] == '/ecomode':
            roomData = self.path
            SendMessage().updateRoom(roomData)
            self.path = "/index.html"
            time.sleep(1)
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.ecomode")

        elif self.path[0:9] == '/automode':
            roomData = self.path
            SendMessage().updateRoom(roomData)
            self.path = "/index.html"
            time.sleep(1)
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.automode")

        elif self.path[0:11] == '/rangegraph':
            print 'going to create rangeGraph page'
            CUI.rangeGraphUI()
            time.sleep(1)

        elif self.path[0:10] == '/heatcheck':
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.heatcheck")
            self.path = "/index.html"

        elif self.path[0:5] == '/mode':
            roomData = self.path
            SendMessage().updateRoom(roomData)
            if _platform == "linux" or _platform == "linux2":
                flashCube()
            self.path = "/index.html"
            time.sleep(1)
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.mode")

        elif self.path[0:6] == '/graph':
            roomName = self.path
            GRAPH.createGraph(roomName)
            self.path = "/graph.html"

        elif self.path == "/?confirm=1&boilerswitch=Boiler+Enabled":
            VAR.writeVariable([['BoilerEnabled', 0]])
            self.path = "/index.html"
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.Boiler-disable")

        elif self.path == '/?confirm=1&boilerswitch=Boiler+Disabled':
            VAR.writeVariable([['BoilerEnabled', 1]])
            self.path = "/index.html"
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.boiler-enable")

        elif self.path == "/admin":
            roomTemps = CUI.createRooms()
            self.path = "/admin.html"
            self.updateUIPages(roomTemps)

        elif self.path == "/shutdown":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so shutting down'
                self.path = "/shutdown.html"
                system("sudo shutdown -h now")
            elif _platform == "win32":
                print 'In Windows, Not shutting down'
                self.path = "/admin.html"

        elif self.path == "/reboot":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so rebooting'
                self.path = "/shutdown.html"
                system("sudo reboot")
            elif _platform == "win32":
                print 'In Windows, Not rebooting'
                self.path = "/admin.html"

        elif self.path == "/killpython":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so killing Python'
                self.path = "/shutdown.html"
                system("sudo pkill python")
            elif _platform == "win32":
                print 'In Windows, Not stopping python'
                self.path = "/admin.html"

        elif self.path == "/Restartpython":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so killing Python'
                self.path = "/admin.html"
                #system("sudo pkill python")
                self.restart_program()
            elif _platform == "win32":
                print 'In Windows, Not stopping python'
                self.path = "/admin.html"

        try:
            #Check the file extension required and
            #set the right mime type

            sendReply = False
            if self.path.endswith(".html"):
                mimetype = 'text/html'
                sendReply = True
            if self.path.endswith(".jpg"):
                mimetype = 'image/jpg'
                sendReply = True
            if self.path.endswith(".gif"):
                mimetype = 'image/gif'
                sendReply = True
            if self.path.endswith(".js"):
                mimetype = 'application/javascript'
                sendReply = True
            if self.path.endswith(".css"):
                mimetype = 'text/css'
                sendReply = True

            if sendReply == True:
                #Open the static file requested and send it
                f = open(curdir + sep + self.path)
                self.send_response(200)
                self.send_header('Content-type', mimetype)
                self.end_headers()
                self.wfile.write(f.read())
                f.close()
            return

        except IOError:
            self.send_error(404, 'File Not Found: %s' % self.path)
    def do_GET(self):
        useNeoPixel = VAR.readVariables(['UseNeoPixel'])
        module_logger.debug("GET %s" % self.path)
        if self.path=="/":
            roomTemps = CUI.createRooms()
            self.path="/index.html"
            self.updateUIPages(roomTemps)
            
        elif self.path[0:8] == '/ecomode':
            roomData = self.path
            SendMessage().updateRoom(roomData)
            self.path="/index.html"
            time.sleep(1)
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.ecomode")
            
        elif self.path[0:9] == '/automode':
            roomData = self.path
            SendMessage().updateRoom(roomData)
            self.path="/index.html"
            time.sleep(1)
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.automode")

        elif self.path[0:11] == '/rangegraph':
            print 'going to create rangeGraph page'
            CUI.rangeGraphUI()
            time.sleep(1)
            
        elif self.path[0:10] == '/heatcheck':
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.heatcheck")
            self.path="/index.html"
            
        elif self.path[0:5] == '/mode':
            roomData = self.path
            SendMessage().updateRoom(roomData)
            if _platform == "linux" or _platform == "linux2":
                flashCube()
            self.path="/index.html"
            time.sleep(1)
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.mode")
            
        elif self.path[0:6] == '/graph':
            roomName = self.path
            GRAPH.createGraph(roomName)
            self.path="/graph.html"
            
        elif self.path =="/?confirm=1&boilerswitch=Boiler+Enabled":
            VAR.writeVariable([['BoilerEnabled', 0]])
            self.path = "/index.html"
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.Boiler-disable")
            
        elif self.path == '/?confirm=1&boilerswitch=Boiler+Disabled':
            VAR.writeVariable([['BoilerEnabled', 1]])
            self.path = "/index.html"
            if useNeoPixel:
                MaxInterface().checkHeat(self.input_queue)
            else:
                buttonCheckHeat("requesthandler.boiler-enable")
            
        elif self.path =="/admin":
            roomTemps = CUI.createRooms()
            self.path = "/admin.html"
            self.updateUIPages(roomTemps)
            
        elif self.path == "/shutdown":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so shutting down'
                self.path = "/shutdown.html"
                system("sudo shutdown -h now")
            elif _platform == "win32":
                print 'In Windows, Not shutting down'
                self.path = "/admin.html"
                
        elif self.path == "/reboot":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so rebooting'
                self.path = "/shutdown.html"
                system("sudo reboot")
            elif _platform == "win32":
                print 'In Windows, Not rebooting'
                self.path = "/admin.html"
                
        elif self.path == "/killpython":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so killing Python'
                self.path = "/shutdown.html"
                system("sudo pkill python")
            elif _platform == "win32":
                print 'In Windows, Not stopping python'
                self.path = "/admin.html"
                
        elif self.path == "/Restartpython":
            if _platform == "linux" or _platform == "linux2":
                print 'In Linux so killing Python'
                self.path = "/admin.html"
                #system("sudo pkill python")
                self.restart_program()
            elif _platform == "win32":
                print 'In Windows, Not stopping python'
                self.path = "/admin.html"
        

        try:
            #Check the file extension required and
            #set the right mime type

            sendReply = False
            if self.path.endswith(".html"):
                mimetype='text/html'
                sendReply = True
            if self.path.endswith(".jpg"):
                mimetype='image/jpg'
                sendReply = True
            if self.path.endswith(".gif"):
                mimetype='image/gif'
                sendReply = True
            if self.path.endswith(".js"):
                mimetype='application/javascript'
                sendReply = True
            if self.path.endswith(".css"):
                mimetype='text/css'
                sendReply = True

            if sendReply == True:
                #Open the static file requested and send it
                f = open(curdir + sep + self.path) 
                self.send_response(200)
                self.send_header('Content-type',mimetype)
                self.end_headers()
                self.wfile.write(f.read())
                f.close()
            return
        
        except IOError:
            self.send_error(404,'File Not Found: %s' % self.path)