-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
26 lines (22 loc) · 881 Bytes
/
server.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
import time
import prometheus_client
from prometheus_client import start_http_server, Summary
import board
import busio
import adafruit_scd30
# SCD-30 has tempremental I2C with clock stretching, datasheet recommends
# starting at 50KHz
i2c = busio.I2C(board.SCL, board.SDA,frequency=50000)
scd = adafruit_scd30.SCD30(i2c)
scd.temperature_offset = 2 #change if needed
CO2_GAUGE = prometheus_client.Gauge("co2_ppm", "CO2 in ppm")
TEMPERATURE_GAUGE = prometheus_client.Gauge("temperature_celcius", "Temperature in Celcius")
HUMIDITY_GAUGE = prometheus_client.Gauge("humidity_percent", "Humidity percentage")
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
while True:
CO2_GAUGE.set(scd.CO2)
TEMPERATURE_GAUGE.set(scd.temperature)
HUMIDITY_GAUGE.set(scd.relative_humidity)
time.sleep(840)