示例#1
0
class DatasHandler(tornado.web.RequestHandler):
    
    @asynchronous
    def get(self):
        
        self.set_header("Access-Control-Allow-Origin", "*")
        
        self.ser=SerialConnector()
        self.ser.retrieveAllDatas()
        
        self.write('{"Power":"%d",' % self.ser.get(Util.POWER_TAG))
        self.write('"Iinst":"%d",' % self.ser.get(Util.IINST_TAG))
        self.write('"HP":"%d",' % self.ser.get(Util.HP_TAG))
        self.write('"HC":"%d",' % self.ser.get(Util.HC_TAG))
        self.write('"Period":"%s"}' % self.ser.get(Util.CURRENTH_TAG))
        
        self.finish()
示例#2
0
class LiveModule(tornado.web.UIModule):

    def render(self):
        return ''
    
    def javascript_files(self):
        return "/static/libs/power.js"
    
    def embedded_javascript(self):
        
        self.ser=SerialConnector()
        self.ser.retrieve(Util.POWER_TAG)
       
        
        n=Network()
        
        if n.isWAN(self.request.remote_ip):
            namespace="smartdomus.redirectme.net:9090"
        else:
            namespace=Util.MY_IP+":"+str(9090)
        return "power="+str(self.ser.get(Util.POWER_TAG))+";var namespace=\""+namespace+"\";"
示例#3
0
class LoggerThread(threading.Thread):
    
    def __init__(self):
        
        threading.Thread.__init__(self)
        self._stopevent = threading.Event()
        self.db=DatabaseConnector()
      
        
    def run(self):
        
        while not self._stopevent.isSet():
            self.ser=SerialConnector()
            self.ser.retrieve(Util.POWER_TAG)
            self.db.connect()
            self.db.update('actual_power',self.ser.get(Util.POWER_TAG))
            self.db.close()
            self._stopevent.wait(1.0)
      
    def stop(self):
        
        self._stopevent.set()