예제 #1
0
    def addBLE(self, BLE_GATEWAY):
        self.ble_gateway = BLE_GATEWAY

    def handleNotification(self, client, uerdata, msg):
        logger.info(msg.topic + " " + str(msg.payload))

        if (msg.topic == "lifx/power"):
            light.set_power(int(msg.payload), 0, True)
        elif (msg.topic == "lifx/hsbk"):
            hsbk = msg.payload.split(",")
            hsbk = map(int, hsbk)
            print hsbk, type(hsbk), len(hsbk)
            light.set_color(hsbk)


if (__name__ == "__main__"):
    try:
        mqtt_delegate = MQTT_delegate()
        mqtt_gateway = gateway.MQTT_GATEWAY(MQTT_SERVER,
                                            MQTT_SUBSCRIBING_TOPIC,
                                            mqtt_delegate.handleNotification)
        threading.Thread(target=mqtt_gateway.client.loop_forever).start()
        while True:
            pass

    except KeyboardInterrupt:
        mqtt_gateway.client.disconnect()
        sys.exit()

    except:
        raise
예제 #2
0
    def addBLE(self, BLE_GATEWAY):
        self.ble_gateway = BLE_GATEWAY

    def handleNotification(self, client, uerdata, msg):
        logger.info(msg.topic + " " + str(msg.payload))

        if (msg.topic == MQTT_SUBSCRIBING_TOPIC[0]):
            self.ble_gateway.set_polling_rate(HANDLE[4], msg.payload)


if (__name__ == "__main__"):
    try:
        mqtt_delegate = MQTT_delegate()
        mqtt_gateway = gateway.MQTT_GATEWAY(MQTT_SERVER,
                                            MQTT_SUBSCRIBING_TOPIC,
                                            mqtt_delegate.handleNotification)
        ble_delegate = BLE_delegate(mqtt_gateway.client)
        ble_gateway = gateway.BLE_GATEWAY(
            DEVICE_NAME,
            MAC_ADDRESS,
            DEVICE_TYPE,
        )
        mqtt_gateway.add_diagnostic(ble_gateway)
        event_stop = threading.Event()
        t1 = threading.Thread(target=ble_gateway.data_logger_thread,
                              args=(ble_delegate, BLE_DELEGATE_HANDLE,
                                    event_stop))
        t1.start()
        mqtt_delegate.addBLE(ble_gateway)
        threading.Thread(target=mqtt_gateway.client.loop_forever).start()