50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
import time
|
||
|
import requests
|
||
|
from datetime import date
|
||
|
|
||
|
from smbus2 import SMBus
|
||
|
|
||
|
from bme280 import BME280
|
||
|
|
||
|
print(
|
||
|
"""all-values.py - Read temperature, pressure, and humidity
|
||
|
|
||
|
Press Ctrl+C to exit!
|
||
|
|
||
|
"""
|
||
|
)
|
||
|
|
||
|
def send_data(results):
|
||
|
output = requests.post('http://192.168.1.221:8086/write?db=garagedb', data = results, timeout=30)
|
||
|
print(output)
|
||
|
|
||
|
# Initialise the BME280
|
||
|
bus = SMBus(0)
|
||
|
bme280 = BME280(i2c_dev=bus)
|
||
|
|
||
|
diff_count = 0
|
||
|
old_last_work_time = 0
|
||
|
old_count_live = 0
|
||
|
old_count_precache = 0
|
||
|
|
||
|
while True:
|
||
|
temperature = bme280.get_temperature()
|
||
|
pressure = bme280.get_pressure()
|
||
|
humidity = bme280.get_humidity()
|
||
|
print(f"{temperature:05.2f}°C {pressure:05.2f}hPa {humidity:05.2f}%")
|
||
|
|
||
|
results = 'temperature,host=nanopi_bme280 value={}'.format(temperature)
|
||
|
print(results)
|
||
|
send_data(results)
|
||
|
|
||
|
results = 'pressure,host=nanopi_bme280 value={}'.format(pressure * 100)
|
||
|
print(results)
|
||
|
send_data(results)
|
||
|
|
||
|
results = 'humidity,host=nanopi_bme280 value={}'.format(humidity)
|
||
|
print(results)
|
||
|
send_data(results)
|
||
|
|
||
|
time.sleep(20)
|