Exemplo n.º 1
0
 def getTemps(self, sensors):
     ret = {}
     try:
         for sens in sensors:
             if self.firstSensorLoop:
                 log.debug("found sensor address %r, type=%r" %
                           (sens.address, sens.type))
             if sens.type != 'DS18S20':
                 continue
             try:
                 t = sens.temperature.strip()
                 if t == '85':
                     log.debug(
                         "  sensor %s says 85 (C), power-on reset value" %
                         sens.address)
                     continue
                 tFar = float(t) * 9/5 + 32
                 log.debug("  %s reports temp %r F" % (sens.address, tFar))
             except ow.exUnknownSensor, e:
                 log.warn(e)
                 continue
             ret[sens] = tFar
     except KeyboardInterrupt: raise
     except Exception, e:
         traceback.print_exc()
Exemplo n.º 2
0
def getOk(url, timeout=1):
    """can we get a successful status from this url in a short time?"""
    log.debug("testing %s" % url)
    try:
        resp = yield getPage(url, timeout=timeout)
    except Exception, e:
        log.warn("getPage %s", e)
        returnValue(False)
Exemplo n.º 3
0
def supervisorRestart(cmds, supervisor="http://localhost:9001"):
    serv = xmlrpclib.ServerProxy(supervisor)
    for c in cmds:
        log.info("restarting %s", c)
        try:
            serv.supervisor.stopProcessGroup(c)
        except xmlrpclib.ResponseError, e:
            log.warn("supervisor.stopProcessGroup error %r, ignoring", e)
        serv.supervisor.startProcess(c)
Exemplo n.º 4
0
 def updateLcd(self):
     whole = "%-147s%-21s" % (self.message, self.lastLine)
     try:
         restkit.request(url=self.putUrl,
                         method="PUT",
                         body=whole,
                         headers={"content-type":"text/plain"})
     except socket.error, e:
         log.warn("update lcd failed, %s" % e)
Exemplo n.º 5
0
    def put(self):
        """
        request an immediate load of the remote graphs; the thing we
        do in the background anyway. No payload.

        Using PUT because this is idempotent and retryable and
        everything.

        todo: this should do the right thing when many requests come
        in very quickly
        """
        log.warn("immediateUpdate from %s %s - ignored",
                 self.request.headers.get('User-Agent', '?'),
                 self.request.headers['Host'])
        self.set_status(202)
Exemplo n.º 6
0
 def getHttpTemps(self):
     ret = {}
     
     for url, name in [("http://star:9014/", "ariroom"),
                       ("http://slash:9080/", "frontDoor"),
                       ]:
         for tries in range(3):
             try:
                 res = restkit.Resource(url, timeout=5)
                 temp = json.loads(res.get("temperature").body_string(), 
                                   )['temp']
                 log.debug("got http temp %s = %r", name, temp)
                 ret[name] = temp
                 break
             except Exception, e:
                 log.warn(e)
Exemplo n.º 7
0
def barcodeWatch(arduino, postBarcode):
    arduino.ser.write("\xff\xfb")
    ret = arduino.readJson()
    if not ret['barcode']:
        return
    if ret['barcode'] == "27 80 48 13 ":
        return # scanner's beep response

    arduino.ser.write("\xff\xfc")
    arduino.readJson() # my beep response
    s = ''.join(chr(int(x)) for x in ret['barcode'].split())
    for code in s.split('\x02'):
        if not code:
            continue
        if not code.endswith('\x03'):
            log.warn("couldn't read %r", code)
            return
        codeType = {'A':'UPC-A',
                    'B':'JAN-8',
                    'E':'UPC-E',
                    'N':'NW-7',
                    'C':'CODE39',
                    'I':'ITF',
                    'K':'CODE128',
                    }[code[0]]
        code = code[1:-1]
        body = "%s %s %s ." % (
                           ROOM['barcodeScan'].n3(),
                           ROOM['read'].n3(),
                           ROOM['barcode/%s/%s' % (codeType, code)].n3())
        body = body.encode('utf8')
        print "body: %r" % body
        fetch("http://bang:9071/oneShot",
              method='POST',
              timeout=1,
              postdata=body,
              headers={"content-type" : ["text/n3"]},
        ).addErrback(log.error)
Exemplo n.º 8
0
 def _onStatements(self, stmts):
     # write rfid to new key, etc.
     if len(stmts) > 0 and stmts[0][1] == ROOM['keyContents']:
         return
     log.warn("ignoring %s", stmts)
Exemplo n.º 9
0
    loop = ReadLoop(reader,
                    masterGraph,
                    overwrite_any_tag=arg['--overwrite_any_tag'])

    port = 10012
    reactor.listenTCP(port,
                      cyclone.web.Application([
                          (r"/(|.+\.html)", cyclone.web.StaticFileHandler, {
                              "path": ".",
                              "default_filename": "index.html"
                          }),
                          (r"/graph/rfid", CycloneGraphHandler, {
                              'masterGraph': masterGraph
                          }),
                          (r"/graph/rfid/events", CycloneGraphEventsHandler, {
                              'masterGraph': masterGraph
                          }),
                          (r'/output', OutputPage),
                          (r'/rewrite', Rewrite),
                          (r'/stats/(.*)', StatsHandler, {
                              'serverName': 'rfid'
                          }),
                      ],
                                              masterGraph=masterGraph,
                                              debug=arg['-v']),
                      interface='::')
    log.warn('serving on %s', port)

    reactor.run()
Exemplo n.º 10
0
 def _onStatements(self, stmts):
     # write rfid to new key, etc.
     if len(stmts) > 0 and stmts[0][1] == ROOM['keyContents']:
         return
     log.warn("ignoring %s", stmts)
Exemplo n.º 11
0
        defer.setDebugging(True)
        
    masterGraph = PatchableGraph()
    reader = NfcDevice() if not arg['-n'] else FakeNfc()

    ie=InfluxExporter(Graph())
    ie.exportStats(STATS, ['root.cardReadPoll.count',
                           'root.cardReadPoll.95percentile',
                           'root.newCardReads',
                       ],
                    period_secs=10,
                    retain_days=7,
    )

    loop = ReadLoop(reader, masterGraph, overwrite_any_tag=arg['--overwrite_any_tag'])

    port = 10012
    reactor.listenTCP(port, cyclone.web.Application([
        (r"/(|.+\.html)", cyclone.web.StaticFileHandler,
         {"path": ".", "default_filename": "index.html"}),
        (r"/graph", CycloneGraphHandler, {'masterGraph': masterGraph}),
        (r"/graph/events", CycloneGraphEventsHandler,
         {'masterGraph': masterGraph}),
        (r'/output', OutputPage),
        (r'/rewrite', Rewrite),
        (r'/stats/(.*)', StatsHandler, {'serverName': 'rfid'}),
        ], masterGraph=masterGraph, debug=arg['-v']), interface='::')
    log.warn('serving on %s', port)

    reactor.run()
Exemplo n.º 12
0
 def step():
     try:
         t.step()
     except Exception, e:
         log.warn(e)