Пример #1
0
            except socket.error:
                log.error("socket.error will try a reconnection in 10 s")
            sleep(10)
        return
    cid = config["mqtt"]["client_id"] +"_"+socket.gethostname()
    client = mqtt.Client(client_id=cid)
    clientMQTT = mqtt.Client()
    clientMQTT.on_connect = on_connect
    clientMQTT.on_message = on_message
    mqtt_connect_retries(clientMQTT)
    clientMQTT.loop_start()
    return clientMQTT




# -------------------- main -------------------- 
config = cfg.get_local_json()

cfg.configure_log(config["log"])

log.info("ruler started @ :"+str(datetime.datetime.utcnow()))

#will start a separate thread for looping
clientMQTT = mqtt_start()

#loop forever
ruler_loop_forever()


Пример #2
0

def mqtt_connect_retries():
    connected = False
    while (not connected):
        try:
            clientMQTT.connect(config["mqtt"]["host"], config["mqtt"]["port"],
                               config["mqtt"]["keepalive"])
            connected = True
        except socket.error:
            log.error("socket.error will try a reconnection in 10 s")
        sleep(10)
    return


config = cfg.get_local_json("config.json")

# -------------------- logging --------------------
log.basicConfig(filename=config["influxdb"]["logfile"],
                level=log.INFO,
                format='%(asctime)s %(levelname)-8s %(message)s',
                datefmt='%d %H:%M:%S')
log.getLogger('').addHandler(log.StreamHandler())

log.info("influx client started")

# -------------------- influxDB client --------------------
clientDB = InfluxDBClient(config["influxdb"]["host"],
                          config["influxdb"]["port"], 'root', 'root',
                          config["influxdb"]["db"])
Пример #3
0
        except socket.error:
            log.error("socket.error will try a reconnection in 10 s")
        sleep(10)
    return


def mqtt_start():
    cid = config["mqtt"]["client_id"] + "_" + socket.gethostname()
    clientMQTT = mqtt.Client(client_id=cid)
    clientMQTT.on_connect = on_connect
    clientMQTT.on_message = on_message
    mqtt_connect_retries(clientMQTT)
    clientMQTT.loop_start()
    return clientMQTT


# -------------------- main --------------------
config = cfg.get_local_json("config_wemo.json")

cfg.configure_log(config["log"])

log.info("wemo client started")

#will start a separate thread for looping
clientMQTT = mqtt_start()

devices = wemo_start()

#loop forever
wemo_loop_forever()
Пример #4
0
    connected = False
    while (not connected):
        try:
            client.connect(config["mqtt"]["host"], config["mqtt"]["port"],
                           config["mqtt"]["keepalive"])
            connected = True
            log.info("mqtt connected to " + config["mqtt"]["host"] + ":" +
                     str(config["mqtt"]["port"]) + " with id: " + cid)
        except socket.error:
            log.error("socket.error will try a reconnection in 10 s")
        sleep(10)
    return


# -------------------- main --------------------
config = cfg.get_local_json("config_milight.json")

cfg.configure_log(config["log"])

log.info("milight client started")

# -------------------- Milight Client --------------------
milight_controllers = {}
for device_name, device in config["devices"].items():
    milight_controllers[device_name] = milight.MiLight(device)

#light = milight.LightBulb(['rgbw','white','rgb'])
light = milight.LightBulb(['rgbw'])
night_mode = [0xC1, 0xC6, 0xC8, 0xCA, 0xCC]
# -------------------- Mqtt Client --------------------
cid = config["mqtt"]["client_id"] + "_" + socket.gethostname()