* complete docker-compose with influxdb + grafana (TODO: port-mappings+hosts, preconfiguring grafana)
* importer ** logging ** one request per callbackmaster
parent
a9697f7c03
commit
98c0c75e4e
|
|
@ -1,5 +1,24 @@
|
|||
version: "2"
|
||||
|
||||
services:
|
||||
import:
|
||||
build: .
|
||||
image: docker.clkl.de/weather/import:0.1
|
||||
build: importer
|
||||
image: docker.clkl.de/weather/import:0.2
|
||||
influxdb:
|
||||
image: influxdb:1.5-alpine
|
||||
command: influxd -config /etc/influxdb/influxdb.conf
|
||||
ports:
|
||||
- "8086:8086"
|
||||
volumes:
|
||||
- "./influxdb/:/var/lib/influxdb"
|
||||
environment:
|
||||
- INFLUXDB_DB=mydb
|
||||
#- INFLUXDB_USER=user
|
||||
#- INLFUXDB_USER_PASSWORD=<secret>
|
||||
grafana:
|
||||
image: grafana/grafana
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
# - "./grafana_etc/:/etc/grafana/"
|
||||
- "./grafana_lib/:/var/lib/grafana/"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
FROM python:3.7-rc-alpine
|
||||
|
||||
RUN pip install tinkerforge requests
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
CMD ["python3.7", "/app/import.py"]
|
||||
|
|
@ -3,6 +3,7 @@ PORT = 4223
|
|||
UID = "DYC"
|
||||
URL = "http://192.168.2.30:8086/write?db=mydb"
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
|
@ -10,12 +11,19 @@ import requests
|
|||
from tinkerforge.ip_connection import IPConnection
|
||||
from tinkerforge.bricklet_outdoor_weather import BrickletOutdoorWeather
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def asdf(type, identifier, **kwargs):
|
||||
print(type, identifier, kwargs)
|
||||
log.info(type, identifier, kwargs)
|
||||
time_ns = time.time_ns()
|
||||
for key in kwargs:
|
||||
data = "{unit},type={type},identifier={id} value={value} {time_ns}".format(unit=key, type=type, id=identifier, value=kwargs[key], time_ns=time_ns)
|
||||
r = requests.post(URL, data=data)
|
||||
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)
|
||||
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)
|
||||
|
|
@ -23,7 +31,8 @@ def cb_sensor(identifier, temperature, humidity):
|
|||
asdf(type="sensor", identifier=identifier, temperature=temperature, humidity=humidity)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("starting…")
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||
log.info("starting…")
|
||||
ipcon = IPConnection()
|
||||
ow = BrickletOutdoorWeather(UID, ipcon)
|
||||
ipcon.connect(HOST, PORT)
|
||||
|
|
@ -31,10 +40,10 @@ 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)
|
||||
print("now we play the waiting game…")
|
||||
log.info("now we play the waiting game…")
|
||||
while True:
|
||||
try:
|
||||
time.sleep(60*60)
|
||||
except Exception:
|
||||
print("…")
|
||||
log.warning("…")
|
||||
ipcon.disconnect()
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
tinkerforge==2.1.16
|
||||
requests==2.18.4
|
||||
Loading…
Reference in New Issue