Skip to content

Instantly share code, notes, and snippets.

@moccos
Created April 25, 2020 06:25
Show Gist options
  • Save moccos/bab8f086d594664e4934619784d3ad8d to your computer and use it in GitHub Desktop.
Save moccos/bab8f086d594664e4934619784d3ad8d to your computer and use it in GitHub Desktop.
Co2Mini -> mackerel format (TSV)
#python3
import time
import CO2Meter
sensor = CO2Meter.CO2Meter("/dev/hidraw0")
_LIMIT = 10
def get_sensor():
co2 = None
temp = None
for _i in range(_LIMIT):
data = sensor.get_data()
# print(data)
if 'co2' in data:
co2 = data['co2']
if 'temperature' in data:
temp = data['temperature']
if co2 is not None and temp is not None:
return f'co2mini.co2\t{co2}\t{int(time.time())}\n' + f'co2mini.temp\t{temp}\t{int(time.time())}\n'
time.sleep(1)
print(get_sensor())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment