Exemple #1
0
def test_gas_read_each(GPIO, smbus):
    from enviroplus import gas
    gas._is_setup = False

    assert int(gas.read_oxidising()) == 16641
    assert int(gas.read_reducing()) == 16727
    assert int(gas.read_nh3()) == 16813
Exemple #2
0
def get_gas_data():
    return {
        'adc': gas.read_adc(),
        'nh3': gas.read_nh3(),
        'oxidising': gas.read_oxidising(),
        'reducing': gas.read_reducing()
    }
def test_gas_read_each():
    sys.modules['RPi'] = mock.Mock()
    sys.modules['RPi.GPIO'] = mock.Mock()
    smbus = mock.Mock()
    smbus.SMBus = SMBusFakeDevice
    sys.modules['smbus'] = smbus
    from enviroplus import gas

    assert int(gas.read_oxidising()) == 16641
    assert int(gas.read_reducing()) == 16727
    assert int(gas.read_nh3()) == 16813
 def build_metrics_dict(cls):
     pms_data = cls.PMS5003_INSTANCE.read()
     return {
         "temperature": cls.calibrated_temp(),
         "pressure": cls.BME280_INSTANCE.get_pressure(),
         "humidity": cls.BME280_INSTANCE.get_humidity(),
         "light": cls.LTR559_INSTANCE.get_lux(),
         "gas_oxidizing": gas.read_oxidising(),
         "gas_reducing": gas.read_reducing(),
         "gas_nh3": gas.read_nh3(),
         "pm_ug_per_m3_1_0": pms_data.pm_ug_per_m3(1.0),
         "pm_ug_per_m3_2_5": pms_data.pm_ug_per_m3(2.5),
         "pm_ug_per_m3_10": pms_data.pm_ug_per_m3(10),
         "pm_per_dl_0_3": pms_data.pm_per_1l_air(0.3),
         "pm_per_dl_0_5": pms_data.pm_per_1l_air(0.5),
         "pm_per_dl_1_0": pms_data.pm_per_1l_air(1.0),
         "pm_per_dl_2_5": pms_data.pm_per_1l_air(2.5),
         "pm_per_dl_5_0": pms_data.pm_per_1l_air(5.0),
         "pm_per_dl_10_0": pms_data.pm_per_1l_air(10.0)
     }
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)

temperature = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()

lux = ltr559.get_lux()
prox = ltr559.get_proximity()

gas_readings = gas.read_all()

oxidising = gas.read_oxidising()
reducing = gas.read_reducing()
nh3 = gas.read_nh3()
adc = gas.read_adc()

pms5003 = PMS5003()
try:
    particulates = pms5003.read()
except ReadTimeoutError:
    pms5003 = PMS5003()

data_dict = {
    "temperature": temperature,
    "pressure": pressure,
    "humidity": humidity,
    "lux": lux,
    "prox": prox,
    "oxidising": oxidising,
Exemple #6
0
data['cpu_factor'] = 0.95

try:
    while True:
        now = datetime.now() 
        data['datetime'] = now.strftime("%d/%m/%Y %H:%M:%S")
        data['temperature'] = bme280.get_temperature()
        cpu_temp = get_cpu_temperature()
        # Smooth out with some averaging to decrease jitter
        cpu_temps = cpu_temps[1:] + [cpu_temp]
        data['avg_cpu_temp'] = sum(cpu_temps) / float(len(cpu_temps))
        raw_temp = data['temperature']
        data['comp_temp'] = raw_temp - ((data['avg_cpu_temp'] - data['temperature']) / data['cpu_factor'])
        data['pressure'] = bme280.get_pressure()
        data['humidity'] = bme280.get_humidity()        
        data['gas_nh3'] = gas.read_nh3()
        data['gas_oxidising'] = gas.read_oxidising()
        data['gas_reducing'] = gas.read_reducing()
        data['lux'] = ltr559.get_lux()
        data['prox'] = ltr559.get_proximity()            
        try:
            pms = pms5003.read()
            data['pms1_0'] = pms.data[0]
            data['pms2_5'] = pms.data[1]
            data['pms10'] = pms.data[2]
            data['pms1_0_atmenv'] = pms.data[3]
            data['pms2_5_atmenv'] = pms.data[4]
            data['pms10_atmenv'] = pms.data[5]
            data['pms_03_in_01'] = pms.data[6]
            data['pms_05_in_01'] = pms.data[7]
            data['pms_1_in_01'] = pms.data[8]
def r_float_value_nh3():
    nh3 = gas.read_nh3()
    if isinstance(nh3, float):
        return nh3
    return float(0)