aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/mqtt_listener.py32
-rw-r--r--scripts/neohub.py11
2 files changed, 8 insertions, 35 deletions
diff --git a/scripts/mqtt_listener.py b/scripts/mqtt_listener.py
index 6c617a5..48dfc6f 100644
--- a/scripts/mqtt_listener.py
+++ b/scripts/mqtt_listener.py
@@ -57,33 +57,15 @@ def on_message(client, userdata, msg):
data['voltage'],
data['linkquality'],
datetime.utcnow())
+ common.dbi(sql, values, verbose=True)
- elif name in tempsensors and 'temperature' in data:
- data['humidity'] = data['humidity'] if 'humidity' in data else None
- data['voltage'] = data['voltage'] if 'voltage' in data else None
- sql = """INSERT INTO mqtt_temps
- (sensor_id,
- temperature,
- humidity,
- battery,
- linkquality,
- voltage,
- time)
- SELECT sensors.id, %s, %s, %s, %s, %s, %s
- FROM sensors
- WHERE sensors.name = %s"""
- values = (data['temperature'],
- data['humidity'],
- data['battery'],
- data['linkquality'],
- data['voltage'],
- datetime.utcnow(),
- name)
-
- else:
- return
+ if name in tempsensors:
+ if 'temperature' in data:
+ common.statein(name, data['temperature'], 'temperature', '°C', verbose=True)
+ if 'humidity' in data:
+ common.statein(name, data['humidity'], 'humidity', '%', verbose=True)
+
- common.dbi(sql, values, verbose=True)
# mqtt
diff --git a/scripts/neohub.py b/scripts/neohub.py
index 7ef8b77..f2c0ed8 100644
--- a/scripts/neohub.py
+++ b/scripts/neohub.py
@@ -47,17 +47,8 @@ async def call_neohub():
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)"""
common.dbi(sql, values, verbose=True)
+ common.statein('neohub', device.temperature, 'temperature', '°C', verbose=True)
- sql = """INSERT INTO mqtt_temps
- (sensor_id,
- temperature,
- time)
- SELECT sensors.id, %s, %s
- FROM sensors
- WHERE sensors.name = 'neohub'"""
- values = (device.temperature, datetime.utcnow())
-
- common.dbi(sql, values, verbose=True)
# Loop it forever
while True: