Example #1
0
class DHTAdapter(object):

    CMD_READ_TEMPERATURE = 0x01  # float value (Celsius)
    CMD_READ_HUMIDITY = 0x02  # float value (Percentage)

    def __init__(self, bus=1, i2c_addr=0x04):
        self._adapter = Adapter(bus=bus, i2c_addr=i2c_addr)

    @property
    def temperature(self):
        return self._adapter.read_float(self.CMD_READ_TEMPERATURE)

    @property
    def humidity(self):
        return self._adapter.read_float(self.CMD_READ_HUMIDITY)
Example #2
0
class WaterDispenserAdapter(object):

    CMD_OPEN_SOLENOID_VALVE = 0x01
    CMD_CLOSE_SOLENOID_VALVE = 0x02

    CMD_READ_SOIL_MOISTURE = 0x09  # float value (Percentage)
    CMD_READ_SOLENOID_VALVE_STATE = 0x0A  # byte value

    def __init__(self, bus=1, i2c_addr=0x04):
        self._adapter = Adapter(bus=bus, i2c_addr=i2c_addr)

    @property
    def soil_moisture(self):
        return self._adapter.read_float(self.CMD_READ_SOIL_MOISTURE)

    @property
    def solenoid_valve_state(self):
        state = self._adapter.read_byte(self.CMD_READ_SOLENOID_VALVE_STATE)
        if state == 1:
            return "opened"
        elif state == 0:
            return "closed"
        else:
            return None

    def open_solenoid_valve(self):
        self._adapter.write_byte(self.CMD_OPEN_SOLENOID_VALVE)

    def close_solenoid_valve(self):
        self._adapter.write_byte(self.CMD_CLOSE_SOLENOID_VALVE)
Example #3
0
class WeatherstationAdapter(object):

    CMD_READ_TEMPERATURE_1 = 0x01  # float value (Celsius)
    CMD_READ_TEMPERATURE_2 = 0x02  # float value (Celsius)
    CMD_READ_PRESSURE = 0x03  # long value (Pascal)
    CMD_READ_HUMIDITY = 0x04  # float value (Percentage)
    CMD_READ_ALTITUDE = 0x05  # long value (Meters)
    CMD_READ_ILLUMINANCE = 0x06  # long value (Lux)
    CMD_READ_COLOR_TEMPERATURE = 0x07  # long value (Kelvin)
    CMD_READ_COLOR_ILLUMINANCE = 0x08  # long value (Lux)

    def __init__(self, bus=1, i2c_addr=0x05):
        self._adapter = Adapter(bus=bus, i2c_addr=i2c_addr)

    @property
    def pressure(self):
        return self._adapter.read_int32(self.CMD_READ_PRESSURE)

    @property
    def altitude(self):
        return self._adapter.read_int32(self.CMD_READ_ALTITUDE)

    @property
    def illuminance(self):
        return self._adapter.read_int32(self.CMD_READ_ILLUMINANCE)

    @property
    def humidity(self):
        return self._adapter.read_float(self.CMD_READ_HUMIDITY)

    @property
    def temperature_1(self):
        return self._adapter.read_float(self.CMD_READ_TEMPERATURE_1)

    @property
    def temperature_2(self):
        return self._adapter.read_float(self.CMD_READ_TEMPERATURE_2)

    @property
    def color_temperature(self):
        return self._adapter.read_int32(self.CMD_READ_COLOR_TEMPERATURE)

    @property
    def color_illuminance(self):
        return self._adapter.read_int32(self.CMD_READ_COLOR_ILLUMINANCE)
Example #4
0
class GPSAdapter(object):

    CMD_READ_GPS_STATE = 0x01  # byte value
    CMD_READ_LONGITUDE = 0x02  # float value
    CMD_READ_LATITUDE = 0x03  # float value
    CMD_READ_ELEVATION = 0x04  # float value

    BUFFER_LENGTH = 10

    def __init__(self, bus=1, i2c_addr=0x05):
        self._adapter = Adapter(bus=bus, i2c_addr=i2c_addr)
        self._buffer = {
        'lat': [0] * self.BUFFER_LENGTH,
        'lng': [0] * self.BUFFER_LENGTH,
        'alt': [0] * self.BUFFER_LENGTH
        }
        self._lat_index = 0
        self._lng_index = 0
        self._alt_index = 0
        self._found = False

    def _add_lat(self, value):
        if value is not None and value != -1:
            self._lat_index = (self._lat_index + 1) % self.BUFFER_LENGTH
            self._buffer['lat'][self._lat_index] = value

    def _add_lng(self, value):
        if value is not None and value != -1:
            self._lng_index = (self._lng_index + 1) % self.BUFFER_LENGTH
            self._buffer['lng'][self._lng_index] = value

    def _add_alt(self, value):
        if value is not None:
            self._alt_index = (self._alt_index + 1) % self.BUFFER_LENGTH
            self._buffer['alt'][self._alt_index] = value

    @property
    def state(self):
        return self._found_gps()

    def _found_gps(self):
        _state = self._adapter.read_byte(self.CMD_READ_GPS_STATE)
        if _state:
            return True
        else:
            return False

    @property
    def found(self):
        return self._found_gps()

    @property
    def longitude(self):
        value = self._adapter.read_float(self.CMD_READ_LONGITUDE)
        self._add_lng(value)
        return self._buffer['lng'][self._lng_index]

    @property
    def latitude(self):
        value = self._adapter.read_float(self.CMD_READ_LATITUDE)
        self._add_lat(value)
        return self._buffer['lat'][self._lat_index]

    @property
    def elevation(self):
        value = self._adapter.read_float(self.CMD_READ_ELEVATION)
        self._add_alt(value)
        return self._buffer['alt'][self._alt_index]