Compare commits
4 Commits
755b70475a
...
72336a3f4a
| Author | SHA1 | Date |
|---|---|---|
|
|
72336a3f4a | |
|
|
172f3d769a | |
|
|
0eb7a30e4a | |
|
|
ffc7ac2794 |
|
|
@ -1,18 +1,22 @@
|
|||
version: "2"
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
import:
|
||||
build: importer
|
||||
image: docker.clkl.de/weather/import:0.2
|
||||
image: docker.clkl.de/weather/import:0.3
|
||||
environment:
|
||||
- PYTHONUNBUFFERED=1
|
||||
- TF_HOST=192.168.2.160
|
||||
- TF_PORT=4223
|
||||
- TF_ID=DYC
|
||||
- INFLUXDB_DB=mydb
|
||||
influxdb:
|
||||
image: influxdb:1.5-alpine
|
||||
image: influxdb:1.7-alpine
|
||||
command: influxd -config /etc/influxdb/influxdb.conf
|
||||
ports:
|
||||
- "8086:8086"
|
||||
volumes:
|
||||
- "./influxdb/:/var/lib/influxdb"
|
||||
environment:
|
||||
- INFLUXDB_DB=mydb
|
||||
- INFLUXDB_DB=mydb # Y U NO WORK?!
|
||||
#- INFLUXDB_USER=user
|
||||
#- INLFUXDB_USER_PASSWORD=<secret>
|
||||
grafana:
|
||||
|
|
@ -20,5 +24,7 @@ services:
|
|||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
# - "./grafana_etc/:/etc/grafana/"
|
||||
- "./grafana_lib/:/var/lib/grafana/"
|
||||
|
||||
|
||||
# docker-compose exec influxdb influx_inspect export -database mydb -out /var/lib/influxdb/backup-text-dump -datadir /var/lib/influxdb/data -waldir /var/lib/influxdb/wal
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
FROM python:3.7-rc-alpine
|
||||
FROM python:3.7-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
HOST = "192.168.2.110"
|
||||
PORT = 4223
|
||||
UID = "DYC"
|
||||
URL = "http://192.168.2.30:8086/write?db=mydb"
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
||||
from os import getenv
|
||||
|
||||
import requests
|
||||
|
||||
from tinkerforge.ip_connection import IPConnection
|
||||
|
|
@ -13,22 +10,32 @@ from tinkerforge.bricklet_outdoor_weather import BrickletOutdoorWeather
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def asdf(type, identifier, **kwargs):
|
||||
log.info(type, identifier, kwargs)
|
||||
|
||||
HOST = getenv("TF_HOST", "192.168.2.160")
|
||||
PORT = int(getenv("TF_PORT", 4223))
|
||||
UID = getenv("TF_ID", "DYC")
|
||||
URL = getenv("INFLUX_URL", "http://influxdb:8086)
|
||||
DB = getenv("INFLUXDB_DB", "mydb")
|
||||
|
||||
|
||||
|
||||
def influx(type, identifier, **kwargs):
|
||||
log.info(f"{type}, {identifier}, {kwargs}")
|
||||
time_ns = time.time_ns()
|
||||
data = []
|
||||
for unit in kwargs:
|
||||
data.append(f"{unit},type={type},identifier={identifier} value={kwargs[unit]} {time_ns}")
|
||||
try:
|
||||
r = requests.post(URL, data="\n".join(data))
|
||||
log.info(r, r.text)
|
||||
url = f"{URL}/write?db={DB}"
|
||||
r = requests.post(url, data="\n".join(data))
|
||||
log.info(f"{r}, {r.text}")
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
|
||||
def cb_station(identifier, temperature, humidity, wind_speed, gust_speed, rain, wind_direction, battery_low):
|
||||
asdf(type="station", identifier=identifier, temperature=temperature, humidity=humidity, wind_speed=wind_speed, gust_speed=gust_speed, rain=rain, wind_direction=wind_direction, battery_low=battery_low)
|
||||
influx(type="station", identifier=identifier, temperature=temperature, humidity=humidity, wind_speed=wind_speed, gust_speed=gust_speed, rain=rain, wind_direction=wind_direction, battery_low=battery_low)
|
||||
def cb_sensor(identifier, temperature, humidity):
|
||||
asdf(type="sensor", identifier=identifier, temperature=temperature, humidity=humidity)
|
||||
influx(type="sensor", identifier=identifier, temperature=temperature, humidity=humidity)
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||
|
|
@ -40,6 +47,8 @@ if __name__ == "__main__":
|
|||
ow.set_sensor_callback_configuration(True)
|
||||
ow.register_callback(ow.CALLBACK_STATION_DATA, cb_station)
|
||||
ow.register_callback(ow.CALLBACK_SENSOR_DATA, cb_sensor)
|
||||
log.info("try to create influx db…")
|
||||
requests.post(f"{URL}/query?q=CREATE DATABASE {DB}")
|
||||
log.info("now we play the waiting game…")
|
||||
while True:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ def update(start, end):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
start = dt(2018, 8 , 1)
|
||||
end = dt(2018, 8 , 1)
|
||||
start = dt(2018, 8 , 3)
|
||||
end = dt(2018, 8 , 3)
|
||||
update(start, end)
|
||||
|
|
@ -54,12 +54,17 @@ def auth_from_env():
|
|||
def ssh_from_env():
|
||||
return SSHConfig(user=os.getenv("SSH_USER"), password=os.getenv("SSH_PASSWORD"), host=os.getenv("SSH_HOST"), port=os.getenv("SSH_PORT", 22), dir=os.getenv("SSH_DIR", "/"))
|
||||
|
||||
def update():
|
||||
def update(save=False):
|
||||
log.info("run update")
|
||||
try:
|
||||
auth = auth_from_env()
|
||||
config = ssh_from_env()
|
||||
_update(auth, config)
|
||||
|
||||
except Exception as e:
|
||||
if save:
|
||||
log.e(e)
|
||||
else:
|
||||
raise e
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
|
||||
|
|
|
|||
Loading…
Reference in New Issue