Esempio n. 1
0
def get_gases():
       
    # variable = "oxidised"
    unit1 = "kO"
    data1 = gas.read_all()
    data1 = data1.oxidising / 1000
    data1_g = "{:.2f}".format(data1)
    #display_text(variables[mode], data1, unit1)


    # variable = "reduced"
    unit2 = "kO"
    data2 = gas.read_all()
    data2 = data2.reducing / 1000
    data2_g = "{:.2f}".format(data2)
    #display_text(variables[mode], data2, unit2)


    # variable = "nh3"
    unit3 = "kO"
    data3 = gas.read_all()
    data3 = data3.nh3 / 1000
    data3_g = "{:.2f}".format(data3)
    #display_text(variables[mode], data3, unit3)
    g = "Oxid: " + str(data1_g) + unit1 + ", Redu: " + str(data2_g) + unit2 + ", nh3: " + str(data3_g) + unit3
    return g
def presMessage():
    bme280: BME280 = BME280()
    ltr559: LTR559 = LTR559()

    cpu_temps = [get_cpu_temperature()] * 5


    while(1):	
        time.sleep(1)
        amps = noise.get_amplitudes_at_frequency_ranges([(20,20000)])

        cpu_temp = get_cpu_temperature()
        # Smooth out with some averaging to decrease jitter
        cpu_temps = cpu_temps[1:] + [cpu_temp]
        avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
        raw_temp = bme280.get_temperature()
        comp_temp = raw_temp - ((avg_cpu_temp - raw_temp) / factor)


        sio.emit('psiresponse', bme280.get_pressure())
        sio.emit('tempresponse', comp_temp)
        sio.emit('humresponse', bme280.get_humidity())
        sio.emit('lightresponse', ltr559.get_lux())
        sio.emit('noiseresponse', amps[0])
        co = gas.read_all()
        co = co/1000
        sio.emit('gasresponse', gas.read_all())
Esempio n. 3
0
 def gas(self):
     gas_data = gas.read_all()
     return {
         'oxidising': gas_data.oxidising / 1000,
         'reducing': gas_data.reducing / 1000,
         'nh3': gas_data.nh3 / 1000
     }
Esempio n. 4
0
def get_data():
    # get scd30 data
    data_raw_scd30 = sensor_scd30.readMeasurement()
    if (data_raw_scd30 == False):
        exit(1)

    [float_co2, float_T, float_rH] = data_raw_scd30
    scd30_data["co2"] = float_co2
    scd30_data["Temp"] = float_T
    scd30_data["Hum"] = float_rH

    # get enviro data

    enviro_data["proximity"] = ltr559.get_proximity()
    enviro_data["raw_temp"] = bme280.get_temperature()
    enviro_data["pressure"] = bme280.get_pressure()
    enviro_data["humidity"] = bme280.get_humidity()
    enviro_data["light"] = ltr559.get_lux()
    enviro_gas = gas.read_all()
    enviro_data["ox"] = enviro_gas.oxidising / 1000
    enviro_data["red"] = enviro_gas.reducing / 1000
    enviro_data["nh3"] = enviro_gas.nh3 / 1000

    # Outputs
    # print(scd30_data)
    # print(enviro_data)
    # time.sleep(10)
    data["enviro"] = enviro_data
    data["scd30"] = scd30_data
    return data
Esempio n. 5
0
    def read_values(self):
        values = {}
        cpu_temp = self.get_cpu_temperature()
        raw_temp = self.bme280.get_temperature()
        comp_temp = raw_temp - ((cpu_temp - raw_temp) / self.comp_factor)
        values['temperature'] = round(comp_temp, 2)
        values['pressure'] = round(self.bme280.get_pressure(), 2)
        values['humidity'] = round(self.bme280.get_humidity(), 2)
        data = gas.read_all()
        values['oxidising'] = round(data.oxidising / 1000, 4)
        values['reducing'] = round(data.reducing / 1000, 4)
        values['nh3'] = round(data.nh3 / 1000, 4)
        values['lux'] = round(ltr559.get_lux(), 2)
        try:
            pm_values = self.pms5003.read()
            values['P2.5'] = pm_values.pm_ug_per_m3(2.5)
            values['P10'] = pm_values.pm_ug_per_m3(10)
            values['P1.0'] = pm_values.pm_ug_per_m3(1.0)
        except ReadTimeoutError:
            self.pms5003.reset()
            pm_values = self.pms5003.read()
            values['P2.5'] = pm_values.pm_ug_per_m3(2.5)
            values['P10'] = pm_values.pm_ug_per_m3(10)
            values['P1.0'] = pm_values.pm_ug_per_m3(1.0)

        values['ts'] = time.time_ns()
        return values
Esempio n. 6
0
def data_read():  # function to take sensor inputs and store in list
    print("Reading data from sensors...")

    # begins by assigning the information for A and B to variables

    # for A, read data from sensors
    # for SGP30 a simple read
    eco2_A = sgp30.eCO2
    tvoc_A = (sgp30.TVOC) + 1
    # enviroplus, gas readings taken to intermediary variable
    enviro_readings = gas.read_all()
    # specific reading taken from intermediary variable and assigned to specific variable
    redu_A = enviro_readings.reducing
    oxi_A = enviro_readings.oxidising

    print("Reading data from API...")
    # for B, information taken from API
    eco2_B = float(aio.receive('eco2-b').value)
    tvoc_B = (float(aio.receive('tvoc-b').value)) + 1
    redu_B = float(aio.receive('redu-b').value)
    oxi_B = float(aio.receive('oxi-b').value)

    # once data retrieved, values added to lists for use at end of function
    eco2_data_A.append(eco2_A)
    tvoc_data_A.append(tvoc_A)
    redu_data_A.append(redu_A)
    oxi_data_A.append(oxi_A)
    eco2_data_B.append(eco2_B)
    tvoc_data_B.append(tvoc_B)
    redu_data_B.append(redu_B)
    oxi_data_B.append(oxi_B)
Esempio n. 7
0
def test_gas_read_adc_str(GPIO, smbus):
    from enviroplus import gas
    gas._is_setup = False

    gas.enable_adc(True)
    gas.set_adc_gain(2.048)
    assert 'ADC' in str(gas.read_all())
Esempio n. 8
0
def get_gas_measurements():

    now = datetime.utcnow()
    line1 = now.strftime("%H%M%S")
    size_x, size_y = draw.textsize(line1, font)

    # text position
    x = 0
    y = 0

    # Draw background rectangle and write text.
    draw.rectangle((0, 0, 160, 80), back_colour)
    draw.text((x, y), line1, font=font, fill=text_colour)

    line2 = "gas"
    size_x, size_y = draw.textsize(line2, font)
    y += size_y
    draw.text((x, y), line2, font=font, fill=text_colour)

    disp.display(img)

    # retrieve gas readings
    gas_readings = gas.read_all()

    return '{ "instant":"' + now.isoformat() + '"' + \
           ', "adc":' + str(gas_readings.adc) + \
           ', "nh3":' + str(gas_readings.nh3) + \
           ', "oxidised":' + str(gas_readings.oxidising) + \
           ', "reduced":' + str(gas_readings.reducing) + \
           '}'
Esempio n. 9
0
def output():

    # Get Temperature, pressure and humidity
    bus = SMBus(1)
    bme280 = BME280(i2c_dev=bus)

    cpu_temps = [get_cpu_temperature()] * 5
    factor = 0.8

    raw_temp = bme280.get_temperature()
    cpu_temp = get_cpu_temperature()
    cpu_temps = cpu_temps[1:] + [cpu_temp]
    avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
    compTemp = raw_temp - ((avg_cpu_temp - raw_temp) / factor)

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

    # Get gases
    gases = gas.read_all()
    nh3 = gases.nh3
    no2 = gases.oxidising

    # Get light and proximity
    light = ltr559.get_lux()
    proxim = ltr559.get_proximity()

    # Calculate current time as string
    curTime = time.strftime("%d/%m/%y,%H:%M", time.localtime())

    return compTemp, humidity, nh3, no2, light, proxim, pressure, curTime
Esempio n. 10
0
def read_values(bme280, pms5003):
    # Compensation factor for temperature
    comp_factor = 2.25

    values = {}
    cpu_temp = get_cpu_temperature()
    raw_temp = bme280.get_temperature()  # float
    comp_temp = raw_temp - ((cpu_temp - raw_temp) / comp_factor)
    values["temperature"] = int(comp_temp)
    values["pressure"] = round(
        int(bme280.get_pressure() * 100), -1
    )  # round to nearest 10
    values["humidity"] = int(bme280.get_humidity())
    try:
        pm_values = pms5003.read()  # int
        values["pm1"] = pm_values.pm_ug_per_m3(1)
        values["pm25"] = pm_values.pm_ug_per_m3(2.5)
        values["pm10"] = pm_values.pm_ug_per_m3(10)
    except ReadTimeoutError:
        pms5003.reset()
        pm_values = pms5003.read()
        values["pm1"] = pm_values.pm_ug_per_m3(1)
        values["pm25"] = pm_values.pm_ug_per_m3(2.5)
        values["pm10"] = pm_values.pm_ug_per_m3(10)
    data = gas.read_all()
    values["oxidised"] = int(data.oxidising / 1000)
    values["reduced"] = int(data.reducing / 1000)
    values["nh3"] = int(data.nh3 / 1000)
    values["lux"] = int(ltr559.get_lux())
    return values
Esempio n. 11
0
def get_gases():
    gases = {}
    data = gas.read_all()
    gases['oxidising'] = TWO_DEC.format(data.oxidising / 1000)
    gases['reducing'] = TWO_DEC.format(data.reducing / 1000)
    gases['nh3'] = TWO_DEC.format(data.nh3 / 1000)
    return gases
Esempio n. 12
0
def read_values():
    values = {}
    cpu_temp = get_cpu_temperature()
    raw_temp = bme280.get_temperature()
    raw_gas = gas.read_all()
    comp_temp = raw_temp - ((cpu_temp - raw_temp) / comp_factor)
    values["temperature"] = "{:.2f}".format(comp_temp)
    values["pressure"] = "{:.2f}".format(bme280.get_pressure() * 100)
    values["humidity"] = "{:.2f}".format(bme280.get_humidity())
    values["reducing"] = "{:.2f}".format(raw_gas.reducing)
    values["oxidising"] = "{:.2f}".format(raw_gas.oxidising)
    values["nh3"] = "{:.2f}".format(raw_gas.nh3)
    try:
        pm_values = pms5003.read()
    except ReadTimeoutError:
        pms5003.reset()
        pm_values = pms5003.read()
    
    values["P0.3_air"] = str(pm_values.pm_per_1l_air(0.3))
    values["P0.5_air"] = str(pm_values.pm_per_1l_air(0.5))
    values["P1_air"] = str(pm_values.pm_per_1l_air(1))
    values["P2.5_m3"] = str(pm_values.pm_ug_per_m3(2.5))
    values["P10_m3"] = str(pm_values.pm_ug_per_m3(10))
    values["time"] = time.time()
    return values
Esempio n. 13
0
def get_gases():
    gas_data = gas.read_all()
    data = {}
    data["gas"] = {}
    data["gas"]["ammonia"] = gas_data.nh3 / 1000
    data["gas"]["carbon_monoxide"] = gas_data.reducing / 1000
    data["gas"]["nitrogen_dioxide"] = gas_data.oxidising / 1000
    return data
Esempio n. 14
0
def CO():
    co = 0.00
    red = 0
    gas_readings = gas.read_all()
    red = gas_readings.reducing
    red_ratio = (red / 74)
    co = (((red_ratio)**-1.177) * 4.4638)
    return co
Esempio n. 15
0
def get_nh3(log=False):
    # variable = "nh3"
    unit = "kO"
    data = gas.read_all()
    data = data.nh3 / 1000
    if log == True:
        logging.info("nh3 {} {}".format(data, unit))
    # display_text("nh3", data, unit)
    return (data, unit)
Esempio n. 16
0
def get_reduced(log=False):
    # variable = "reduced"
    unit = "kO"
    data = gas.read_all()
    data = data.reducing / 1000
    if log == True:
        logging.info("reduced {} {}".format(data, unit))
    # display_text("reduced", data, unit)
    return (data, unit)
Esempio n. 17
0
def readGas():
    sensor_values = gas.read_all()

    output = {
        "adc": sensor_values.adc,
        "nh3": sensor_values.nh3,
        "oxidising": sensor_values.oxidising,
        "reducing": sensor_values.reducing
    }
    return jsonify(output)
Esempio n. 18
0
def get_gas():
    """Get all gas readings"""
    readings = gas.read_all()

    OXIDISING.set(readings.oxidising)
    OXIDISING_HIST.observe(readings.oxidising)

    REDUCING.set(readings.reducing)
    REDUCING_HIST.observe(readings.reducing)

    NH3.set(readings.nh3)
    NH3_HIST.observe(readings.nh3)
Esempio n. 19
0
def get_measurement():
    try:
        data = gas.read_all()
        oxidising = data.oxidising / 1000
        reducing = data.reducing / 1000
        nh3 = data.nh3 / 1000
        local_data_gateway.post_metrics_update('gas', 'ok')
        return oxidising, reducing, nh3
    except Exception as exception:
        logger.error(f'Unable to read from gas sensor due to {exception}')
        local_data_gateway.post_metrics_update('gas', 'errors')
        return 0, 0, 0
Esempio n. 20
0
def read_data(time):
    temperature = bme280.get_temperature()
    pressure = bme280.get_pressure()
    humidity = bme280.get_humidity()
    lux = ltr559.get_lux()

    if gas_sensor:
        gases = gas.read_all()
        oxi = round(gases.oxidising / 1000, 1)
        red = round(gases.reducing / 1000)
        nh3 = round(gases.nh3 / 1000)
    else:
        oxi = red = nh3 = 0

    if particle_sensor:
        while True:
            try:
                particles = pms5003.read()
                break
            except RuntimeError as e:
                print("Particle read failed:", e.__class__.__name__)
                if not run_flag:
                    raise e
                pms5003.reset()
                sleep(30)

        pm100 = particles.pm_per_1l_air(10.0)
        pm50 = particles.pm_per_1l_air(5.0) - pm100
        pm25 = particles.pm_per_1l_air(2.5) - pm100 - pm50
        pm10 = particles.pm_per_1l_air(1.0) - pm100 - pm50 - pm25
        pm5 = particles.pm_per_1l_air(0.5) - pm100 - pm50 - pm25 - pm10
        pm3 = particles.pm_per_1l_air(0.3) - pm100 - pm50 - pm25 - pm10 - pm5
    else:
        pm100 = pm50 = pm25 = pm10 = pm5 = pm3 = 0

    record = {
        'time': asctime(localtime(time)),
        'temp': round(temperature, 1),
        'humi': round(humidity, 1),
        'pres': round(pressure, 1),
        'lux': round(lux),
        'oxi': oxi,
        'red': red,
        'nh3': nh3,
        'pm03': pm3,
        'pm05': pm5,
        'pm10': pm10,
        'pm25': pm25,
        'pm50': pm50,
        'pm100': pm100,
    }
    return record
Esempio n. 21
0
def sensor_readings():
    """Get readings from each gas sensor on the MICS6814

    Returns:
        dict:
    """
    all = gas.read_all()
    readings = {
        "oxidising": (all.oxidising / 1000.0) * unitregistryhandler.ureg.ppm,
        "reducing": (all.reducing / 1000.0) * unitregistryhandler.ureg.ppm,
        "nh3": (all.nh3 / 1000.0) * unitregistryhandler.ureg.ppm,
    }
    return readings
Esempio n. 22
0
 def generate_output(self):
     self.output_dict['timestamp'] = time.time()
     if self.__variables['temp']: 
         self.output_dict['temp_value'] = self.bme280.get_temperature()
         self.output_dict['temp_unit'] = 'C'
     if self.__variables['pressure']:
         self.output_dict['pressure_value'] = self.bme280.get_pressure()
         self.output_dict['pressure_unit'] = 'hPa'
     if self.__variables['humidity']:
         self.output_dict['humidity_value'] = self.bme280.get_humidity()
         self.output_dict['humidity_unit'] = '%'
     if self.__variables['light']:
         proximity = ltr559.get_proximity()
         if proximity < 10:
             light_value = self.ltr559.get_lux()
         else:
             light_value = 1
         self.output_dict['light_value'] = light_value
         self.output_dict['light_unit'] = 'Lux'
     if self.__variables['oxidised']:
         self.output_dict['oxidised_value'] = gas.read_all().oxidising / 1000
         self.output_dict['oxidised_unit'] = 'kO'
     if self.__variables['reduced']:
         self.output_dict['reduced_value'] = gas.read_all().reducing / 1000
         self.output_dict['reduced_unit'] = 'kO'
     if self.__variables['nh3']:
         self.output_dict['nh3_value'] = gas.read_all().nh3 / 1000
         self.output_dict['nh3_unit'] = 'kO'
     if self.__variables['pm1']:
         self.output_dict['pm1_value'] = float(self.pms5003.read().pm_ug_per_m3(1.0))
         self.output_dict['pm1_unit'] = 'ug/m3'
     if self.__variables['pm25']:
         self.output_dict['pm25_value'] = float(self.pms5003.read().pm_ug_per_m3(2.5))
         self.output_dict['pm25_unit'] = 'ug/m3'
     if self.__variables['pm10']:
         self.output_dict['pm10_value'] = float(self.pms5003.read().pm_ug_per_m3(10))
         self.output_dict['pm10_unit'] = 'ug/m3'
     return self.output_dict
Esempio n. 23
0
def update_graph_gases(input_data):
    try:
        gases = gas.read_all()
        value_red = gases.reducing / 1000
        value_nh3 = gases.nh3 / 1000
        value_oxi = gases.oxidising / 1000
    except:
        value_red = None
        value_nh3 = None
        value_oxi = None
    Y_gas_red_nh3['values']['RED'].append(value_red)
    Y_gas_red_nh3['values']['NH3'].append(value_nh3)
    Y_gas_oxi['values']['OX'].append(value_oxi)
    return (update_graph(X, Y_gas_red_nh3), update_graph(X, Y_gas_oxi))
Esempio n. 24
0
def test_gas_read_all(GPIO, smbus):
    from enviroplus import gas
    gas._is_setup = False
    result = gas.read_all()

    assert type(result.oxidising) == float
    assert int(result.oxidising) == 16641

    assert type(result.reducing) == float
    assert int(result.reducing) == 16727

    assert type(result.nh3) == float
    assert int(result.nh3) == 16813

    assert "Oxidising" in str(result)
Esempio n. 25
0
def read_values():
    values = {}
    # Weather
    try:
        cpu_temp = get_cpu_temperature()
        values["cpu_temp"] = "{:.2f}".format(cpu_temp)
        raw_temp = bme280.get_temperature()
        values["raw_temp"] = "{:.2f}".format(raw_temp)
        comp_temp = raw_temp - ((cpu_temp - raw_temp) / comp_factor)
        values["comp_temp"] = "{:.2f}".format(comp_temp)
        values["pressure"] = "{:.2f}".format(bme280.get_pressure() * 100)
        values["humidity"] = "{:.2f}".format(bme280.get_humidity())
    except:
        pass
    # Light
    try:
        values["light"] = "{:.2f}".format(bme280.get_lux())
    except:
        pass
    # Gas
    try:
        gas_data = gas.read_all()
        values["gas.oxidised"] = "{:.2f}".format(gas_data.oxidising / 1000)
        values["gas.reducing"] = "{:.2f}".format(gas_data.reducing / 1000)
        values["gas.nh3"] = "{:.2f}".format(gas_data.nh3 / 1000)
    except:
        pass

    # Particles
    try:
        pm_values = pms5003.read()
        values["pm.P1"] = str(pm_values.pm_ug_per_m3(1))
        values["pm.P25"] = str(pm_values.pm_ug_per_m3(2.5))
        values["pm.P10"] = str(pm_values.pm_ug_per_m3(10))

        values["pm.per_1l_air_.3"] = str(pm_values.pm_per_1l_air(.3))
        values["pm.per_1l_air_.5"] = str(pm_values.pm_per_1l_air(.5))
        values["pm.per_1l_air_1"] = str(pm_values.pm_per_1l_air(1))
        values["pm.per_1l_air_2.5"] = str(pm_values.pm_per_1l_air(2.5))
        values["pm.per_1l_air_5"] = str(pm_values.pm_per_1l_air(5))
        values["pm.per_1l_air_10"] = str(pm_values.pm_per_1l_air(10))
    except ReadTimeoutError:
        pms5003.reset()
        pm_values = pms5003.read()
        values["pm.P1"] = str(pm_values.pm_ug_per_m3(1))
        values["pm.P25"] = str(pm_values.pm_ug_per_m3(2.5))
        values["pm.P10"] = str(pm_values.pm_ug_per_m3(10))
    return values
Esempio n. 26
0
    def take_readings(self):
        gas_data = gas.read_all()
        readings = {
            "proximity": ltr559.get_proximity(),
            "lux": ltr559.get_lux(),
            "temperature": self.bme280.get_temperature(),
            "pressure": self.bme280.get_pressure(),
            "humidity": self.bme280.get_humidity(),
            "gas/oxidising": gas_data.oxidising,
            "gas/reducing": gas_data.reducing,
            "gas/nh3": gas_data.nh3,
        }

        readings.update(self.latest_pms_readings)
        
        return readings
Esempio n. 27
0
def get_gas():
    """Get all gas readings"""
    try:
        readings = gas.read_all()
    except (OSError, ValueError) as exception:
        logging.warning(
            "Failed to read gas sensor with error: {}".format(exception))
    else:
        OXIDISING.set(readings.oxidising)
        OXIDISING_HIST.observe(readings.oxidising)

        REDUCING.set(readings.reducing)
        REDUCING_HIST.observe(readings.reducing)

        NH3.set(readings.nh3)
        NH3_HIST.observe(readings.nh3)
def get_gas():
    """Get all gas readings"""
    try:
        readings = gas.read_all()

        OXIDISING.set(readings.oxidising)
        OXIDISING_HIST.observe(readings.oxidising)

        REDUCING.set(readings.reducing)
        REDUCING_HIST.observe(readings.reducing)

        NH3.set(readings.nh3)
        NH3_HIST.observe(readings.nh3)
    except IOError:
        logging.error("Could not get gas readings. Resetting i2c.")
        reset_i2c()
Esempio n. 29
0
def get_gas():
    unit = "kO"
    data = gas.read_all()
    try:
        return {
            "status": 200,
            "unit": unit,
            "oxidising": data.oxidising / 1000,
            "reducing": data.reducing / 1000,
            "nh3": data.nh3 / 1000,
        }
    except Exception as e:
        return {
            "status": 500,
            "message": e,
        }
Esempio n. 30
0
    def read_gas(self):
        print("read_gas() started")
        try:
            while True:
                measurements = gas.read_all()
                if self.values.full():
                    self.values.get()
                self.values.put(
                    GasMeasure(measurements.oxidising, measurements.reducing,
                               measurements.nh3, measurements.adc))

                #print(f"Elementi in coda: {self.values.qsize()}")
                #print(self.values.queue)
                time.sleep(self.seconds_interval)
        except:
            print("Exception in read_gas()!")
            raise