-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempestas-bme280.py
executable file
·42 lines (33 loc) · 1.24 KB
/
tempestas-bme280.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
from datetime import datetime
from dateutil.tz import tzlocal
import json
from Adafruit_BME280 import *
from elasticsearch import Elasticsearch
with open('/etc/tempestas.json') as json_data_file:
config = json.load(json_data_file)
es = Elasticsearch([{'host': config["elasticsearch"]["host"], 'port': config["elasticsearch"]["port"]}])
sensor = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8)
while True:
degrees = sensor.read_temperature()
pascals = sensor.read_pressure()
hectopascals = pascals / 100
humidity = sensor.read_humidity()
print 'Temp = {0:0.3f} deg C'.format(degrees)
print 'Pressure = {0:0.2f} hPa'.format(hectopascals)
print 'Humidity = {0:0.2f} %'.format(humidity)
e1={
"@timestamp" : datetime.now(tzlocal()).isoformat(),
"sensor" : config['name'],
"sensor-type" : "BME_280",
"device-type" : "rPi",
"temperature" : degrees,
"pressure" : hectopascals,
"humidity" : humidity,
"version" : "0.0.3",
}
print e1
res = es.index(index=config["elasticsearch"]["index"],body=e1)
time.sleep(int(config['frequency']))