def configLogging(arg): log.setLevel(WARN) if arg['-i'] or arg['-r'] or arg['-o']: log.handlers[0].setFormatter(ColoredFormatter("%(log_color)s%(levelname)-8s %(name)-6s %(filename)-12s:%(lineno)-3s %(funcName)-20s%(reset)s %(white)s%(message)s", datefmt=None, reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white', }, secondary_log_colors={}, style='%' )) if arg['-i']: import twisted.python.log twisted.python.log.startLogging(sys.stdout) getLogger('fetch').setLevel(DEBUG if arg['-i'] else WARN) log.setLevel(DEBUG if arg['-r'] else WARN) getLogger('output').setLevel(DEBUG if arg['-o'] else WARN)
def main(): arg = docopt(""" Usage: environment.py [options] -v Verbose """) log.setLevel(logging.INFO) if arg['-v']: enableTwistedLog() log.setLevel(logging.DEBUG) defer.setDebugging(True) masterGraph = PatchableGraph() class Application(cyclone.web.Application): def __init__(self): handlers = [ (r"/()", cyclone.web.StaticFileHandler, {"path": ".", "default_filename": "index.html"}), (r'/graph', CycloneGraphHandler, {'masterGraph': masterGraph}), (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}), (r'/doc', Doc), # to be shared (r'/stats/(.*)', StatsHandler, {'serverName': 'environment'}), ] cyclone.web.Application.__init__(self, handlers, masterGraph=masterGraph) task.LoopingCall(update, masterGraph).start(1) reactor.listenTCP(9075, Application()) reactor.run()
</LocalCommand>'''.format(macId=macId)) ret = json.loads(resp.body) if ret['demand_units'] != 'kW': raise ValueError if ret['summation_units'] != 'kWh': raise ValueError influx.write_points([ dict(measurement='housePowerW', fields=dict(value=float(ret['demand']) * 1000), tags=dict(house='berkeley'), time=int(startTime)), dict(measurement='housePowerSumDeliveredKwh', fields=dict(value=float(ret['summation_delivered'])), tags=dict(house='berkeley'), time=int(startTime)), ], time_precision='s') except Exception as e: log.error("failed: %r", e) log.error(repr(ret)) now = time.time() goal = startTime + periodSec - .2 reactor.callLater(max(1, goal - now), self.poll) log.setLevel(logging.INFO) influx = InfluxDBClient('bang', 9060, 'root', 'root', 'main') p = Poller(influx) reactor.run()
getPage('http://bang.bigasterisk.com:9069/inputChange', method="POST", postdata=msg, headers={'Content-Type' : 'application/json'} ).addErrback(self.reportError, msg) def reportError(self, msg, *args): print "post error", msg, args if __name__ == '__main__': config = { # to be read from a file 'arduinoPort': '/dev/serial/by-id/usb-Arduino__www.arduino.cc__Arduino_Uno_6493534323335161A2F1-if00', 'servePort' : 9050, 'pollFrequency' : 5, 'boardName' : 'garage', # gets sent with updates } #from twisted.python import log as twlog #twlog.startLogging(sys.stdout) log.setLevel(logging.DEBUG) ard = ArduinoGarage(port=config['arduinoPort']) period = 1/config['pollFrequency'] p = Poller(ard, period) task.LoopingCall(p.poll).start(period) reactor.listenTCP(config['servePort'], Application(ard, p)) reactor.run()
def err(e): log.info('oneshot post to %r failed: %s', url, e.getErrorMessage()) d.addErrback(err) if __name__ == '__main__': arg = docopt(""" Usage: rfid.py [options] -v Verbose --overwrite_any_tag Rewrite any unknown tag with a new random body -n Fake reader """) log.setLevel(logging.INFO) if arg['-v']: enableTwistedLog() log.setLevel(logging.DEBUG) log.info(f'cyclone {cyclone.__version__}') 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',