diff options
| author | Yuval Adam <_@yuv.al> | 2019-08-11 09:35:18 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2019-08-11 09:35:18 +0300 |
| commit | fac8f54cd87771912dee8556597bee1d1269ea62 (patch) | |
| tree | bbe4237114ad12681fbc0cd2d5a30ef64b1549f2 /influx.py | |
Initial files
Diffstat (limited to 'influx.py')
| -rw-r--r-- | influx.py | 38 |
1 files changed, 38 insertions, 0 deletions
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) + |
