Commit bd2f4173 authored by Robert Ricci's avatar Robert Ricci

Python script to feed rtl433 output to influxdb

parent 2d751cf3
#!/usr/bin/env python3.5
from influxdb import InfluxDBClient
import sys
import os
import json
import datetime
import urllib3
with open(os.path.dirname(sys.argv[0]) + '/config.json') as json_data_file:
config = json.load(json_data_file)
devices = config["devices"]
print("Connecting to InfluxDB")
client = InfluxDBClient(host=config["host"],port=config["port"],database=config["database"],ssl=True,verify_ssl=False,username=config["username"],password=config["password"])
print("Connected to InfluxDB")
for line in sys.stdin:
j = json.loads(line)
except ValueError:
print("Bad JSON")
if str(j["id"]) in devices:
print("Inserting for device {}".format(j["id"]))
e = devices[str(j["id"])]
point = [{ "measurement": "temperature", "tags" : { "model" : j["model"], "id": j["id"], "name" : e["name"], "room" : e["room"], "floor" : e["floor"], "side" : e["side"] }, "time": datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), "fields": { "temerature_F": j["temperature_F"], "battery": j["battery"], "humidity" : j["humidity"] } }]
client.write_points(point, time_precision="s")
print("Unknown device {}".format(j["id"]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment