Deploy a bunch of RPi Zero W’s equipped with SI7021’s around the house and get ready to monitor your air!
#!/usr/bin/python3 import smbus import time import requests import platform bus = smbus.SMBus(1) # SI7021 address, 0x40(64) # Read data, 2 bytes, Humidity MSB first rh = bus.read_i2c_block_data(0x40, 0xE5, 2) #what really happens here is that master sends a 0xE5 command (measure RH, hold master mode ) and read 2 bytes back #if you read 3 bytes the last one is the CRC! time.sleep(0.1) # Convert the data humidity = ((rh[0] * 256 + rh[1]) * 125 / 65536.0) - 2 # SI7021 address, 0x40(64) # Read data , 2 bytes, Temperature MSB first temp = bus.read_i2c_block_data(0x40, 0xE3,2) #what really happens here is that master sends a 0xE3 command (measure temperature, hold ma ster mode) and read 2 bytes back #if you read 3 bytes the last one is the CRC! time.sleep(0.1) # Convert the data cTemp = ((temp[0] * 256 + temp[1]) * 175.72 / 65536.0) - 46.85 fTemp = cTemp * 1.8 + 32 job_name='probe' instance_name=platform.node() team_name='air' provider='raspberry' payload_key='temperature' payload_value=(fTemp + 0.4) response = requests.post('http://localhost:9091/metrics/job/{j}/instance/{i}/team/{t}'.form at(j=job_name, i=instance_name, t=team_name), data='{k} {v}\n'.format(k=payload_key, v=payl oad_value)) print(response.status_code) payload_key='humidity' payload_value=(humidity - 7.5) response = requests.post('http://localhost:9091/metrics/job/{j}/instance/{i}/team/{t}'.form at(j=job_name, i=instance_name, t=team_name), data='{k} {v}\n'.format(k=payload_key, v=payl oad_value)) print(response.status_code)
crontab entry:
* * * * * /home/pushgateway/probepush.sh