def __init__(self, logger=None): self._rf = RF_Sender() self._logger = logger if self._logger == None: self._logger = Logger('Pump', Logger.INFO, "/home/pi/MVP/logs/obsv.log") self._persist = Persistence(self._logger)
class Template(object): def __init__(self, logger=None): """Initialize the object Args: logger: existing logger to use Returns: rh: calculated relative humidity Raises: None """ if logger == None: self._logger = Logger("Template", Logger.INFO, "/home/pi/MVP/logs/template.log") def doSomething(self): """Function to do something Args: none: Returns: thing: Raises: None """ self._logger.debug("In doSomething") thing = True self._logger.debug("{}: {}".format("thing", thing)) return thing
def __init__(self): self._logger = Logger("Thermostat", lvl=Logger.INFO, file="/home/pi/MVP/logs/state.log") self._logger.debug("initialize Thermostat object") self._temp = SI7021(self._logger) self._fan = Fan(self._logger)
def __init__(self, logger=None): self._pin = 0 # ADS1115 Channel to use self._logger = logger if logger == None: self._logger = Logger("EC", Logger.INFO) # Create an ADS1115 ADC (16-bit) instance. self._adc = ADS1115(logger)
class EC(object): GAIN = 1 def __init__(self, logger=None): self._pin = 0 # ADS1115 Channel to use self._logger = logger if logger == None: self._logger = Logger("EC", Logger.INFO) # Create an ADS1115 ADC (16-bit) instance. self._adc = ADS1115(logger) def getEC(self): """Read the sensor value Args: None Returns: EC value as number between 0 and 32,000 Raises: None """ ec = self._adc.read_adc(self._pin, gain=self.GAIN) self._logger.info("{} {} {}: {}".format("EC pin", self._pin, "value", ec)) return ec
class RF_Sender: def __init__(self, logger=None, pin=11): self._pin = pin self._protocol = 1 self._length = 444 self._logger = logger if self._logger == None: self._logger = Logger('RF_Send', Logger.INFO) self._logger.debug("Initialize RF Sender on channel {}".format(pin)) self._rfdevice = RFDevice(pin) self._rfdevice.enable_tx() def send(self, code, protocol, length): self._rfdevice.tx_code(code, protocol, length) print("TX Pin: {}, Code: {}, Protocol: {}, Length: {}".format( self._pin, code, protocol, length)) def set_on(self, pin): self.send(code[pin]['On'], protocol, length) def set_off(self, pin): self.send(code[pin]['Off'], protocol, length) def cleanup(self): self._rfdevice.cleanup()
class Thermostat(object): """Code associated with the thermostat controller""" def __init__(self): self._logger = Logger("Thermostat", lvl=Logger.INFO, file="/home/pi/MVP/logs/state.log") self._logger.debug("initialize Thermostat object") self._temp = SI7021(self._logger) self._fan = Fan(self._logger) def check(self, temp=None): """Adjust the fan depending upon the temperature Args: temp: optional test temperature Returns: None Raises: None """ if temp == None: temp = self._temp.get_tempC() # Get target temperature from file target_temp = env['thermostat']['targetTemp'] msg = "{} {} {} {}".format("Temp:", temp, " Target Temp:", target_temp) self._logger.debug(msg) if temp > target_temp: self._fan.set(Fan.ON) else: self._fan.set(Fan.OFF)
class Persistence(object): def __init__(self, logger=None): if logger == None: self._logger = Logger("Persistence", Logger.DETAIL) else: self._logger = logger self._activity_type = "Environment_Observation" self._couch = CouchUtil(self._logger) #self._sheet = AppendUtil(self._logger) self._test = False self._logger.detail("Initialized Persistence") def save(self, doc, test=False): ''' Args: doc: list of attributes, should be of format: [activity_name, trial, plot, subject, attribute, value, units, participant, status_qualifier, comment] participant may be a device string, or a list: ['person':'hmw'] Returns: None Throws: None ''' self._logger.detail("In saveRecord") # Add a line for each persistence service to be used # be sure to copy the record so formatting from one # does not impact another system self._couch.save(doc.copy())
class CO2_stat(object): """Code associated with the thermostat controller""" def __init__(self): self.logger = Logger("CO2_stat") self.logger.debug("initialize CO2 controller object") self._co2 = SCD30(self.logger) self._fan = Fan(self.logger) def check(self, co2=None, test=False): """Adjust the fan depending upon the CO2 Args: temp: optional test CO2 Returns: None Raises: None """ target_co2 = TARGET_CO2 if co2 == None: co2, temp, rh = self._co2.get_data() msg = "{} {} {} {}".format("CO2:", co2, " Target CO2:", target_co2) # Get target temperature from file self.logger.info(msg) if co2 > target_co2: self._fan.set(Fan.ON) else: self._fan.set(Fan.OFF)
def __init__(self): self._logger = Logger("Humidistat") self._logger.setLevel(Logger.INFO) self._logger.debug("initialize Humidistat object") self._co2 = SCD30() self._humidifier = Humidifier() self._target_rh = 80
class OneWireTemp(object): one_temp = {0: "Ambient", 1: "Reservoir", 2: "Box", 3: "Top"} def __init__(self, logger=None): """Create sensor object Args: None Returns: None Raises: None """ self._logger = logger if logger == None: self._logger = Logger("OneWireTemp", Logger.INFO) self._logger.debug("Initialize OneWireTemp") # flag for testing self._test = False def read_temp_raw(self, x): """Read sensor buffer Args: x: number of the sensor Returns: lines: lines read Raises: None """ device_folder = glob.glob(base_dir + '28*')[x] device_file = device_folder + '/w1_slave' self._logger.debug("{} {}, {} {}, {} {}".format( "In read temp raw-Device:", x, "Device Folder:", device_folder, "Device File:", device_file)) f = open(device_file, 'r') lines = f.readlines() f.close() return lines def getTempC(self, x): """Read sensor buffer Args: x: number of the sensor Returns: temp_c: temperature reading Raises: None """ lines = self.read_temp_raw(x) while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1: temp_string = lines[1][equals_pos + 2:] temp_c = float(temp_string) / 1000.0 # temp_f = temp_c * 9.0 / 5.0 + 32.0 # return temp_c, temp_f return temp_c
def __init__(self, logger=None): self._logger = logger if self._logger == None: self._logger = Logger('Light', Logger.INFO, "/home/pi/MVP/logs/obsv.log") self._logger.debug("Initialize RF Light") self._rf = RF_Sender(self._logger) self._persist = Persistence(self._logger)
def __init__(self, path, addr, logger=None): self._path = path self._addr = addr self._i2c = pI2C(self._path) self._logger = logger if logger == None: self._logger = Logger("SCD30", Logger.INFO) self._logger.debug("initialize I2C object")
def __init__(self, logger=None): self._addr = addr self._path = path self._logger = logger if logger == None: self._logger = Logger("SI7021", Logger.INFO, "/home/pi/MVP/logs/obsv.log") self._i2c = I2C(path, addr, self._logger)
def __init__(self): '''Get distances for determining reservoir levels''' self.res = {'full': full_ec, 'empty': empty_ec, 'timeout': timeout} self._activity_type = 'Agronomic_Activity' self._logger = Logger('LogReservoir', Logger.INFO) self._persist = Persistence(self._logger) self._logger.detail("Reservoir Initialized") # flag for testing self._test = False
def __init__(self, logger=None): self._logger = logger if logger == None: self._logger = Logger("Humidifier", Logger.INFO) self._logger.debug("initialize Fan object") self._relay = Relay(self._logger) self._pin = 29 self._couch = CouchUtil(self._logger) # flag for if in testing self._test = False
def __init__(self, logger=None): if logger == None: self._logger = Logger("Persistence", Logger.DETAIL) else: self._logger = logger self._activity_type = "Environment_Observation" self._couch = CouchUtil(self._logger) #self._sheet = AppendUtil(self._logger) self._test = False self._logger.detail("Initialized Persistence")
def __init__(self, logger=None, pin=11): self._pin = pin self._protocol = 1 self._length = 444 self._logger = logger if self._logger == None: self._logger = Logger('RF_Send', Logger.INFO) self._logger.debug("Initialize RF Sender on channel {}".format(pin)) self._rfdevice = RFDevice(pin) self._rfdevice.enable_tx()
def __init__(self, logger=None): if logger == None: self._logger = Logger("LogSensor", Logger.DETAIL) else: self._logger = logger self._activity_type = "Environment_Observation" self._logger.detail("CouchUtil") self._test = False self._server = Server() self._db = self._server[db_name]
def __init__(self, logger=None): self._logger = logger if logger == None: self._logger = Logger("Relay", Logger.INFO) self._logger.debug("initialize Fan object") self._relay = Relay(self._logger) self.fan_relay = FAN_PIN self._persist = Persistence(self._logger) # flag for testing self._test = False
def __init__(self, logger=None): self._logger = logger if logger == None: self._logger = Logger("V_CO2", Logger.INFO) self._gdx = gdx() self._gdx.open_usb() #self._headers = self._gdx.enabled_sensor_info(self._gdx) self._headers = self._gdx.enabled_sensor_info() self._info = self._gdx.sensor_info() self._logger.info("Initialized V_CO2")
def __init__(self, logger=None): """Initialize the object Args: logger: existing logger to use Returns: rh: calculated relative humidity Raises: None """ if logger == None: self._logger = Logger("Template", Logger.INFO, "/home/pi/MVP/logs/template.log")
def __init__(self, logger=None): '''Initialize the object''' self.solenoidPin = Relay4 if logger==None: self._logger = Logger('Solenoid', Logger.INFO) else: self._logger = logger self._relay=Relay(self._logger) self._couch=CouchUtil(self._logger) self._test = False self.activity_type = 'State_Change'
def __init__(self, sheet_name, scope, logger=None): if logger == None: self._logger = Logger("SheetUtil", Logger.DETAIL) else: self._logger = logger self._logger.debug("Initialize SheetUtil") self._sheet_name = sheet_name self._scope = scope # The ID and range of a sample spreadsheet. self._sheet = self.open_sheet() self._logger.debug("%s: %s" % ('Opened', sheet_name))
def __init__(self, logger=None): self._logger = logger if logger == None: self._logger = Logger("Relay", Logger.INFO) self._logger.debug("Initialize Relay") GPIO.setwarnings(False) if not GPIO.getmode() == GPIO.BOARD: GPIO.setmode(GPIO.BOARD) GPIO.setup(Relay1, GPIO.OUT) GPIO.setup(Relay2, GPIO.OUT) GPIO.setup(Relay3, GPIO.OUT) GPIO.setup(Relay4, GPIO.OUT)
def __init__(self, logger=None): """Create sensor object Args: None Returns: None Raises: None """ self._logger = logger if logger == None: self._logger = Logger("OneWireTemp", Logger.INFO) self._logger.debug("Initialize OneWireTemp") # flag for testing self._test = False
def __init__(self, lvl=Logger.INFO): """Record optional sensor data Args: lvl: Logging level Returns: None Raises: None """ self._logger = Logger("LogSensor-Extra", lvl, file="/home/pi/MVP/logs/obsv.log") self._activity_type = "Environment_Observation" self._test = False self._persist = Persistence(self._logger)
def __init__(self, logger=None): """Record optional sensor data Args: lvl: Logging level Returns: None Raises: None """ if logger == None: self._logger = Logger("AppendUtil", Logger.DETAIL) else: self._logger = logger self._sheet_name = '1Mtlr_-yqwdEwXFEcaLoEP01aDN7vvOosDOEerFpDkaI' self._scope = ['https://www.googleapis.com/auth/spreadsheets'] self._l_util = ListUtil(self._logger) self._s_util = SheetUtil(self._sheet_name, self._scope, self._logger) self._logger.debug("Initialized AppendUtil")
def __init__(self, logger=None): """Create sensor object Args: None Returns: None Raises: None """ self._logger = logger if logger == None: self._logger = Logger("LogShroom", Logger.INFO, file="/home/pi/MVP/logs/obsv.log") self._logger.debug("Initialize LogShroom") self._couch = CouchUtil(self._logger) # flag for testing self._test = False
def __init__(self, logger=None): """Create sensor object Args: None Returns: None Raises: None """ self._addr = addr self._path = path self._logger = logger if logger == None: self._logger = Logger("SCD30", Logger.INFO) self._i2c = I2C(path, addr, self._logger) self._logger.debug("initialize SCD30") self.start_periodic_measurement()