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+"\";"
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()