aboutsummaryrefslogtreecommitdiffstats
path: root/mqtt2queue.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mqtt2queue.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/mqtt2queue.py b/mqtt2queue.py
index 102b1eb..24ee207 100644
--- a/mqtt2queue.py
+++ b/mqtt2queue.py
@@ -2,18 +2,16 @@
import os
import json
-import pickle
from datetime import datetime
-from litequeue import SQLQueue
import paho.mqtt.client as mqtt
+from common import dbi
+
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']
-q = SQLQueue("litequeue.db", maxsize=None)
-
# 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))
@@ -30,12 +28,15 @@ def on_message(client, userdata, msg):
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())
- q.put(pickle.dumps([sql, values]))
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())
- q.put(pickle.dumps([sql, values]))
+
+ else:
+ return
+
+ dbi(sql, values, verbose=True)