def initMQTT(app): server = app.get_config_parameter("MQTT_SERVER", None) if server is None: server = "localhost" cbpi.add_config_parameter( "MQTT_SERVER", "localhost", "text", "MQTT Server") port = app.get_config_parameter("MQTT_PORT", None) if port is None: port = "1883" cbpi.add_config_parameter( "MQTT_PORT", "1883", "text", "MQTT Sever Port") tls = app.get_config_parameter("MQTT_TLS", None) if tls is None: tls = "false" cbpi.add_config_parameter("MQTT_TLS", "false", "text", "MQTT TLS") app.cache["mqtt"] = MQTTThread(server, port, tls) app.cache["mqtt"].daemon = True app.cache["mqtt"].start() def mqtt_reader(api): while True: try: m = q.get(timeout=0.1) api.cache.get("sensors")[m.get( "id")].instance.last_value = m.get("value") api.receive_sensor_value(m.get("id"), m.get("value")) except: pass cbpi.socketio.start_background_task(target=mqtt_reader, api=app)
def initMQTT(app): server = app.get_config_parameter("MQTT_SERVER",None) if server is None: server = "localhost" cbpi.add_config_parameter("MQTT_SERVER", "localhost", "text", "MQTT Server") port = app.get_config_parameter("MQTT_PORT", None) if port is None: port = "1883" cbpi.add_config_parameter("MQTT_PORT", "1883", "text", "MQTT Sever Port") username = app.get_config_parameter("MQTT_USERNAME", None) if username is None: username = "******" cbpi.add_config_parameter("MQTT_USERNAME", "username", "text", "MQTT username") password = app.get_config_parameter("MQTT_PASSWORD", None) if password is None: password = "******" cbpi.add_config_parameter("MQTT_PASSWORD", "password", "text", "MQTT password") app.cache["mqtt"] = MQTTThread(server,port,username, password) app.cache["mqtt"].daemon = True app.cache["mqtt"].start() def mqtt_reader(api): while True: try: m = q.get(timeout=0.1) api.cache.get("sensors")[m.get("id")].instance.last_value = m.get("value") api.receive_sensor_value(m.get("id"), m.get("value")) except: pass cbpi.socketio.start_background_task(target=mqtt_reader, api=app)
def init_mqtt(app): # pylint: disable=redefined-outer-name """ init MQTT """ server = app.get_config_parameter("MQTT_SERVER", None) if server is None: server = "localhost" cbpi.add_config_parameter("MQTT_SERVER", "localhost", "text", "MQTT Server") port = app.get_config_parameter("MQTT_PORT", None) if port is None: port = "1883" cbpi.add_config_parameter("MQTT_PORT", "1883", "text", "MQTT Sever Port") username = app.get_config_parameter("MQTT_USERNAME", None) if username is None: username = "******" cbpi.add_config_parameter("MQTT_USERNAME", "username", "text", "MQTT username") password = app.get_config_parameter("MQTT_PASSWORD", None) if password is None: password = "******" cbpi.add_config_parameter("MQTT_PASSWORD", "password", "text", "MQTT password") tls = app.get_config_parameter("MQTT_TLS", None) if tls is None: tls = "false" cbpi.add_config_parameter("MQTT_TLS", "false", "text", "MQTT TLS") app.cache["mqtt"] = MQTTThread(server, port, username, password, tls) app.cache["mqtt"].daemon = True app.cache["mqtt"].start() def mqtt_reader(api): while True: try: message = q.get(timeout=0.1) api.cache.get("sensors")[message.get( "id")].instance.last_value = message.get("value") api.receive_sensor_value(message.get("id"), message.get("value")) except AttributeError: pass cbpi.socketio.start_background_task(target=mqtt_reader, api=app)