Esempio n. 1
0
    def read(self):
        from sds011 import SDS011

        pm25_values = []
        pm10_values = []
        self.sensor.workstate = SDS011.WorkStates.Measuring
        try:
            for a in range(8):
                values = self.sensor.get_values()
                if values is not None:
                    pm10_values.append(values[0])
                    pm25_values.append(values[1])
        finally:
            self.sensor.workstate = SDS011.WorkStates.Sleeping

        pm25_value = mean(pm25_values)
        pm10_value = mean(pm10_values)

        data = [
            Reading(device='SDS011',
                    type='particles-pm25',
                    unit='unknown',
                    address=self.address,
                    value=pm25_value),
            Reading(device='SDS011',
                    type='particles-pm10',
                    unit='unknown',
                    address=self.address,
                    value=pm10_value),
        ]
        return data
Esempio n. 2
0
 def read(self):
     pressure, temperature = self.sensor.all()
     address = '{}/{}'.format(self.bus, self.address)
     data = [
         Reading(device='BMP180',
                 type='temperature',
                 unit='celsius',
                 address=address,
                 value=temperature.C),
         Reading(device='BMP180',
                 type='pressure',
                 unit='hPa',
                 address=address,
                 value=temperature.hPa),
     ]
     return data
Esempio n. 3
0
 def read(self):
     temperature = 42.42
     humidity = 84.84
     data = [
         Reading(device='Dummy',
                 type='temperature',
                 unit='celsius',
                 address=self.address,
                 value=temperature),
         Reading(device='Dummy',
                 type='humidity',
                 unit='%',
                 address=self.address,
                 value=humidity),
     ]
     return data
Esempio n. 4
0
 def read(self):
     value = self.sensorreader.read()
     data = [
         Reading(device='ABE-DeltaSigma-ADC',
                 type='weight',
                 unit='kg',
                 address=self.address,
                 value=value),
     ]
     return data
Esempio n. 5
0
 def read(self):
     temperature_value = self.sensor.temperature
     if temperature_value == 85:
         raise BadReading('DS18B20 power-on value 85')
     data = [
         Reading(device='DS18B20',
                 type='temperature',
                 unit='celsius',
                 address=self.address,
                 value=temperature_value),
     ]
     return data
Esempio n. 6
0
 def read(self):
     temperature = self.sensor.read_temperature()
     humidity = self.sensor.read_humidity()
     pressure = self.sensor.read_pressure() / 100
     data = [
         Reading(device='BME280',
                 type='temperature',
                 unit='celsius',
                 address=self.address,
                 value=temperature),
         Reading(device='BME280',
                 type='humidity',
                 unit='%',
                 address=self.address,
                 value=humidity),
         Reading(device='BME280',
                 type='pressure',
                 unit='hPa',
                 address=self.address,
                 value=pressure),
     ]
     return data
Esempio n. 7
0
 def read(self):
     """
     Note that sometimes you won't get a reading and
     the results will be null (because Linux can't
     guarantee the timing of calls to read the sensor).
     If this happens try again!
     """
     # Adafruit_DHT.DHT11, 17
     import Adafruit_DHT
     humidity, temperature = Adafruit_DHT.read(Adafruit_DHT.DHT11,
                                               self.address)
     data = [
         Reading(device='DHT11',
                 type='temperature',
                 unit='celsius',
                 address=self.address,
                 value=temperature),
         Reading(device='DHT11',
                 type='humidity',
                 unit='%',
                 address=self.address,
                 value=humidity),
     ]
     return data
Esempio n. 8
0
    def read(self):
        import RPi.GPIO as GPIO
        values = []
        try:
            # Before reading, reset the HX711 (not obligate).
            # FIXME: Really?
            self.sensor.reset()
            values = self.sensor.get_raw_data(num_measures=3)

        finally:
            # FIXME: Really?
            GPIO.cleanup()  # always do a GPIO cleanup in your scripts!

        value = mean(values)
        data = [
            Reading(device='HX711',
                    type='weight',
                    unit='kg',
                    address=self.address,
                    value=value),
        ]
        return data