From fac8f54cd87771912dee8556597bee1d1269ea62 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sun, 11 Aug 2019 09:35:18 +0300 Subject: Initial files --- influx.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 influx.py (limited to 'influx.py') diff --git a/influx.py b/influx.py new file mode 100644 index 0000000..7b61d5d --- /dev/null +++ b/influx.py @@ -0,0 +1,38 @@ +import SI1132 +import BME280 +import time +import pytz + +from datetime import datetime +from influxdb import InfluxDBClient + +client = InfluxDBClient(host='127.0.0.1', port=8086, database='tempsdb') + +I2C = '/dev/i2c-1' +TZ = pytz.timezone('UTC') + +si1132 = SI1132.SI1132(I2C) +bme280 = BME280.BME280(I2C, 0x03, 0x02, 0x02, 0x02) + + +while True: + data = { + 'uv_index': si1132.readUV() / 100.0, + 'visibile': si1132.readVisible(), + 'ir': si1132.readIR(), + 'temperature': bme280.read_temperature(), + 'humidity': bme280.read_humidity(), + 'pressure': bme280.read_pressure() / 100.0 + } + body = [{ + 'measurement': 'weather', + 'tags': { 'station': 'office' }, + 'time': TZ.localize(datetime.now()).isoformat(), + 'fields': data + }] + + print(body) + print('---------') + client.write_points(body) + time.sleep(10) + -- cgit v1.3.1