From 008a3dfe234a0207f7c558559cebae993083099f Mon Sep 17 00:00:00 2001 From: Blaise Thompson Date: Fri, 30 Oct 2020 15:14:38 -0500 Subject: hardcoded influx passwords --- docker-compose.yml | 2 +- influxdb/dockerfile | 6 ++++++ web/index.html | 5 +++++ write-influx/write_influx.py | 25 ++++++++++++++++++++----- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d5b0812..9201a9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: web: build: ./web ports: - - 80:80 + - 8080:80 depends_on: - broker - db diff --git a/influxdb/dockerfile b/influxdb/dockerfile index d3f86a2..0a36f75 100644 --- a/influxdb/dockerfile +++ b/influxdb/dockerfile @@ -3,4 +3,10 @@ FROM influxdb:1.8 ENV TZ=America/Chicago RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +ENV INFLUXDB_DB="homie" +ENV INFLUXDB_ADMIN_USER="admin" +ENV INFLUXDB_ADMIN_PASSWORD="mypassword" +ENV INFLUXDB_READ_USER="millikan" +ENV INFLUXDB_READ_USER_PASSWORD="1.602e-19" + RUN ./init-influxdb.sh diff --git a/web/index.html b/web/index.html index 78d52a6..fbbbf1c 100644 --- a/web/index.html +++ b/web/index.html @@ -80,6 +80,11 @@ You are responsible for saving data that you care about in a more permanent way. Device history older than two years will automatically be deleted.

+

+Homie data is written to the database with each [node] as one [field]. +All of the additional information that is represented within the homie hierarchy is stored as tags. +

+

EXAMPLE CURL

diff --git a/write-influx/write_influx.py b/write-influx/write_influx.py index 78e4da5..7337c9d 100644 --- a/write-influx/write_influx.py +++ b/write-influx/write_influx.py @@ -9,7 +9,6 @@ from typing import List, Dict class Topic(dict): - def __init__(self): super().__init__() self["__value__"] = None @@ -43,7 +42,14 @@ def on_message(client, userdata, msg): tags = {} tags["device_id"] = topics[1] # case of device attribute - device_attributes = ["$homie", "$name", "$state", "$nodes", "$extensions", "$implementation"] + device_attributes = [ + "$homie", + "$name", + "$state", + "$nodes", + "$extensions", + "$implementation", + ] if len(topics) == 3 and topics[2] in device_attributes: measurement = topics[2] fields = {"value": payload} @@ -60,11 +66,21 @@ def on_message(client, userdata, msg): write_point(measurement, tags, fields) -influx_client = InfluxDBClient("db", 8086, 'root', 'root', "homie") +influx_client = InfluxDBClient(host="db", + port=8086, + username="admin", + password="mypassword", + database="homie") influx_client.create_database("homie") try: - influx_client.create_retention_policy(name="two-years", database="homie", duration="18000h", default=True, replication=1) + influx_client.create_retention_policy( + name="two-years", + database="homie", + duration="18000h", + default=True, + replication=1, + ) except: pass @@ -81,7 +97,6 @@ def write_point(measurement, tags, fields): print(json) - client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message -- cgit v1.2.3