Initialer Commit
commit
a9697f7c03
|
|
@ -0,0 +1,9 @@
|
||||||
|
FROM python:3.7-rc-alpine
|
||||||
|
|
||||||
|
RUN pip install tinkerforge requests
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD ["python3.7", "/app/import.py"]
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
version: "2"
|
||||||
|
services:
|
||||||
|
import:
|
||||||
|
build: .
|
||||||
|
image: docker.clkl.de/weather/import:0.1
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
HOST = "192.168.2.110"
|
||||||
|
PORT = 4223
|
||||||
|
UID = "DYC"
|
||||||
|
URL = "http://192.168.2.30:8086/write?db=mydb"
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from tinkerforge.ip_connection import IPConnection
|
||||||
|
from tinkerforge.bricklet_outdoor_weather import BrickletOutdoorWeather
|
||||||
|
|
||||||
|
def asdf(type, identifier, **kwargs):
|
||||||
|
print(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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
def cb_sensor(identifier, temperature, humidity):
|
||||||
|
asdf(type="sensor", identifier=identifier, temperature=temperature, humidity=humidity)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("starting…")
|
||||||
|
ipcon = IPConnection()
|
||||||
|
ow = BrickletOutdoorWeather(UID, ipcon)
|
||||||
|
ipcon.connect(HOST, PORT)
|
||||||
|
ow.set_station_callback_configuration(True)
|
||||||
|
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…")
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
time.sleep(60*60)
|
||||||
|
except Exception:
|
||||||
|
print("…")
|
||||||
|
ipcon.disconnect()
|
||||||
Loading…
Reference in New Issue