#!/usr/local/bin/python3

import adafruit_dht
import mh_z19
from sys import stderr
from board import D4
from datetime import datetime

try:
    dhtDevice = adafruit_dht.DHT22(D4)
    temp = dhtDevice.temperature
    humidity = dhtDevice.humidity
    co2 = mh_z19.read()
    if co2 is not None:
        co2 = co2['co2']
    else:
        raise RuntimeError()
    print(
        'Time:', str(datetime.now()),
        'Temp:', temp,
        'Humidity:', humidity,
        'CO2:', co2,
        sep='\n',
    )
except Exception as error:
    print('err:', error, file=sys.stderr)

dhtDevice.exit()