diff options
Diffstat (limited to 'scripts/mqtt_watch.py')
-rw-r--r-- | scripts/mqtt_watch.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/scripts/mqtt_watch.py b/scripts/mqtt_watch.py index a845d30..e2c4e21 100644 --- a/scripts/mqtt_watch.py +++ b/scripts/mqtt_watch.py @@ -1,44 +1,44 @@ #!/usr/bin/env python3 -''' Listen for mqtt-events, and trigger for some ''' +""" Listen for mqtt-events, and trigger for some """ import os from datetime import datetime import paho.mqtt.client as mqtt -mqtt_server = os.environ['el_mqtt_server'] -mqtt_port = int(os.environ['el_mqtt_port']) -keepalive = int(os.environ['el_mqtt_keepalive']) -mqtt_topic = os.environ['el_mqtt_topic'] -mqtt_user = os.environ['el_mqtt_user'] -mqtt_pass = os.environ['el_mqtt_pass'] +mqtt_server = os.environ["el_mqtt_server"] +mqtt_port = int(os.environ["el_mqtt_port"]) +keepalive = int(os.environ["el_mqtt_keepalive"]) +mqtt_topic = os.environ["el_mqtt_topic"] +mqtt_user = os.environ["el_mqtt_user"] +mqtt_pass = os.environ["el_mqtt_pass"] + # The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): - print("Connected with result code "+str(rc)) + print("Connected with result code " + str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. - client.subscribe('#') + client.subscribe("#") + # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): - print(msg.topic, datetime.utcnow(), msg.payload) - #if name.startswith('tmp') and 'temperature' in data and 'humidity' in data: + # if name.startswith('tmp') and 'temperature' in data and 'humidity' in data: # sql = "INSERT INTO mqtt_temps (name, temperature, humidity, battery, linkquality, voltage, time) VALUES(%s,%s,%s,%s,%s,%s,%s)" # values = (name, data['temperature'], data['humidity'], data['battery'], data['linkquality'], data['voltage'], datetime.utcnow()) - #elif name == 'HAN' and 'current' in data: + # elif name == 'HAN' and 'current' in data: # sql = "INSERT INTO mqtt_han (name, current, power, voltage, linkquality, time) VALUES(%s,%s,%s,%s,%s,%s)" # values = (name, data['current'], data['power'], data['voltage'], data['linkquality'], datetime.utcnow()) - #else: + # else: # return - #common.dbi(sql, values, verbose=True) - + # common.dbi(sql, values, verbose=True) # mqtt |