def main(): config = Utils.getconfig("plugwise", None) stick = config["stick"] pairing = config["pairing"] device = "/dev/ttyUSB0" print print "**************************************************************" print "* Menu : *" print "* *" print "* m : Pair your Circle+ (Master) devices with USB stick *" print "* s : Pair your Circle (Slave) devices with Circle+ *" print "* q : Exit *" print "* *" print "**************************************************************" print print "Enter a letter from the menu above :" arg = raw_input() print opts, args = getopt.getopt(sys.argv[1:], "m:s:q:", ['master', 'slave', 'quit']) if arg == "m": for circle_plus in pairing.keys(): PairCirclePlus(device, stick, circle_plus) elif arg == "s": for master,slaves in pairing.iteritems(): pair_circles(slaves, device) elif arg == "q": sys.exit(0) else: print "Command Error ! Select only one letter below !"
def start(): """Starts a thread which reads from RFM69Pi and publishes using MQTT.""" global logger logger = LoggerClient.open("OpenEnergyMonitor") logger.info("Opening connection") global client client = Utils.getpahoclient(logger) global iface iface = __try_open(logger) # config is a dictionary with: # devices : [ { id, desc, name } ] # keys : [ { nodeId, key, desc, name } ] config = Utils.getconfig("open_energy_monitor", logger) nodes = config["nodes"] node2keys = config["node2keys"] for n in nodes: # We add data field to check relative difference between two consecutive # readings, if the difference is not enough the message is not published, # reducing this way the overhead and database size. for conf in node2keys[str(n["id"])]: conf["data"] = -10000.0 conf["when"] = 0.0 global is_running is_running = True thread = threading.Thread(target=__process, args=(logger, client, iface, nodes, node2keys)) thread.setDaemon(True) thread.start()
def start(): """Opens connections with logger, InfluxDB and MQTT broker.""" global logger global mqtt_client global house_data global config global influx_client logger = LoggerClient.open("InfluxDBHub") mqtt_client = Utils.getpahoclient(logger, __configure_mqtt) config = Utils.getconfig("influxdb", logger) influx_client = InfluxDBClient(config["host"], config["port"], config["user"], config["password"], config["database"]) if not {"name": config["database"]} in influx_client.get_list_database(): influx_client.create_database(config["database"]) if not any([ x["name"] == "raspimon_policy" for x in influx_client.get_list_retention_policies() ]): influx_client.create_retention_policy('raspimon_policy', config["retention_policy"], 1, default=True) else: influx_client.alter_retention_policy( 'raspimon_policy', duration=config["retention_policy"], replication=1, default=True)
def start(): """Starts a thread which reads from RFM69Pi and publishes using MQTT.""" global logger logger = LoggerClient.open("OpenEnergyMonitor") logger.info("Opening connection") global client client = Utils.getpahoclient(logger) global iface iface = __try_open(logger) # config is a dictionary with: # devices : [ { id, desc, name } ] # keys : [ { nodeId, key, desc, name } ] config = Utils.getconfig("open_energy_monitor", logger) nodes = config["nodes"] node2keys = config["node2keys"] for n in nodes: # We add data field to check relative difference between two consecutive # readings, if the difference is not enough the message is not published, # reducing this way the overhead and database size. for conf in node2keys[str(n["id"])]: conf["data"] = -10000.0 conf["when"] = 0.0 global is_running is_running = True thread = threading.Thread(target=__process, args=(logger, client, iface, nodes, node2keys)) thread.setDaemon(True) thread.start()
def start(): """Opens logger connection and loads its configuration from MongoDB and sends first message.""" global logger global config global location_id global current_weather_url logger = LoggerClient.open("AEMETMonitor") config = Utils.getconfig("aemet", logger) location_id = config["location_id"] current_weather_url = config["current_weather_url"] publish()
def start(): """Opens logger connection and loads its configuration from MongoDB and sends first message.""" global logger global config global location_id global current_weather_url logger = LoggerClient.open("AEMETMonitor") config = Utils.getconfig("aemet", logger) location_id = config["location_id"] current_weather_url = config["current_weather_url"] publish()
def start(): """Connects with logging server, loads plugwise network configuration and connects with MQTT broker.""" global logger global client global config global device global circles_config global circles global mac2circle logger = LoggerClient.open("PlugwiseMonitor") if not verbose: logger.config(logger.levels.WARNING, logger.schedules.DAILY) config = Utils.getconfig("plugwise", logger) assert config is not None device = plugwise_api.Stick(logger, DEFAULT_SERIAL_PORT) # circles_config is a list of dictionaries: name, mac, desc. state field is # added in next loop to track its value so it can be used to only send # messages in state transitions. power1s and power8s field is used to check # the relative difference in power in order to reduce the network overhead. circles_config = config["circles"] circles = [] mac2circle = {} for circle_data in circles_config: mac = circle_data["mac"] circles.append( plugwise_api.Circle( logger, mac, device, { "name": circle_data["name"], "location": circle_data["desc"], "always_on": "False", "production": "True" })) mac2circle[mac] = circles[-1] circle_data["state"] = "NA" for v in OUTPUT_LIST: circle_data["power" + v["suffix"]] = -10000.0 circle_data["when" + v["suffix"]] = 0.0 client = Utils.getpahoclient(logger, __configure) client.loop_start()
def start(): """Opens connections with logger, InfluxDB and MQTT broker.""" global logger global mqtt_client global house_data global config global influx_client logger = LoggerClient.open("InfluxDBHub") mqtt_client = Utils.getpahoclient(logger, __configure_mqtt) config = Utils.getconfig("influxdb", logger) influx_client = InfluxDBClient(config["host"], config["port"], config["user"], config["password"], config["database"]) if not {"name":config["database"]} in influx_client.get_list_database(): influx_client.create_database(config["database"]) if not any([ x["name"]=="raspimon_policy" for x in influx_client.get_list_retention_policies()]): influx_client.create_retention_policy('raspimon_policy', config["retention_policy"], 1, default=True) else: influx_client.alter_retention_policy('raspimon_policy', duration=config["retention_policy"], replication=1, default=True)
started_modules = [] def try_start(module_info): logger.info("Starting module %s", module_info["import"]) module = importlib.import_module(module_info["import"]) if __try_call(logger, module.start): started_modules.append(module) if "schedules" in module_info: for sched in module_info["schedules"]: method = getattr(Scheduler, sched["method"]) args = [ __replace_vars(x,module) for x in sched["args"] ] method(*args) return True return False config = Utils.getconfig("main", logger) for module_info in config["modules"]: try_start(module_info) logger.info("Scheduler configured") logger.info("Starting infinite loop") # Inifite loop. try: while True: time.sleep(60) # Utils.ntpcheck(logger) We rely in NTP daemon except: logger.info("Stopping scheduler") Scheduler.stop() logger.info("Stopping modules") for m in started_modules: __try_call(logger, m.stop)