def __init__(self): ''' Constructor ''' self.config = ConfigUtil.ConfigUtil( ) #creating a configUtil object to retrieve config data from self.config.loadConfigData() #load the config data
def __init__(self): super(I2CSenseHatAdaptor, self).__init__() self.config = ConfigUtil.ConfigUtil( '../../../data/ConnectedDevicesConfig.props') self.config.loadConfig() print('Configuration data...\n' + str(self.config)) self.initI2CBus()
def __init__(self): ''' Constructor ''' self.configUtil = ConfigUtil.ConfigUtil() self.configUtil.loadConfig()
def __init__(self): #reading the config from file self.config = ConfigUtil.ConfigUtil('/home/pi/workspace/iot-device/data/ConnectedDevicesConfig.props') self.config.loadConfig() print('Configuration data...\n' + str(self.config))
def __init__(self, configFile): self.smtpConfigReader = ConfigUtil.ConfigUtil(configFile, "smtp.cloud") self.host = self.smtpConfigReader.getProperty("host") self.port = self.smtpConfigReader.getProperty("port") self.fromAddr = self.smtpConfigReader.getProperty("fromAddr") self.toAddr = self.smtpConfigReader.getProperty("toAddr") self.authToken = self.smtpConfigReader.getProperty("authToken")
def __init__(self): #self.config = ConfigUtil.ConfigUtil(ConfigConst.DEFAULT_CONFIG_FILE_NAME) #self.config.loadConfig() self.config = ConfigUtil.ConfigUtil( '../../../data/ConnectedDevicesConfig.props') self.config.loadConfig() print('Configuration data...\n' + str(self.config)) print('============= Setting Done! =============') self.host = self.config.getProperty(ConfigConst.COAP_GATEWAY_SECTION, ConfigConst.COAP_HOST) self.port = int( self.config.getProperty(ConfigConst.COAP_GATEWAY_SECTION, ConfigConst.COAP_PORT)) print('\tHost: ' + self.host) print('\tPort: ' + str(self.port)) if not self.host or self.host.isspace(): print("Using default host: " + self.host) if self.port < 1024 or self.port > 65535: print("Using default port: " + self.port) self.serverAddr = (self.host, self.port) print('dddddddddddddddd' + str(self.serverAddr)) self.url = "coap://" + self.host + ":" + str(self.port) + "/temp"
def __init__(self): ''' Constructor ''' self.config = ConfigUtil.ConfigUtil( ConfigConst.DEFAULT_CONFIG_FILE_NAME) self.config.loadConfig()
class SmtpClientConnector(): config = ConfigUtil.ConfigUtil('/home/pi/workspace/iot-device/Lab1/iot-device/data/ConnectedDevicesConfig.props') enableEmulator = config.getProperty(ConfigConst.DEVICE, ConfigConst.ENABLE_EMULATOR_KEY) pollCycleSecs = int(config.getProperty(ConfigConst.DEVICE, ConfigConst.POLL_CYCLES_KEY)) nominalTemp = int(config.getProperty(ConfigConst.DEVICE, ConfigConst.NOMINAL_TEMP_KEY)) def __init__(self): self.config.loadConfig() print('Configuration data...\n' + str(self.config)) def publishMessage(self, topic, data): host = self.config.getProperty(ConfigConst.SMTP_CLOUD_SECTION, ConfigConst.HOST_KEY) port = self.config.getProperty(ConfigConst.SMTP_CLOUD_SECTION, ConfigConst.PORT_KEY) fromAddr = self.config.getProperty(ConfigConst.SMTP_CLOUD_SECTION, ConfigConst.FROM_ADDRESS_KEY) toAddr = self.config.getProperty(ConfigConst.SMTP_CLOUD_SECTION, ConfigConst.TO_ADDRESS_KEY) authToken = self.config.getProperty(ConfigConst.SMTP_CLOUD_SECTION, ConfigConst.USER_AUTH_TOKEN_KEY) msg = MIMEMultipart() msg['From'] = fromAddr msg['To'] = toAddr msg['Subject'] = topic msgBody = str(data) msg.attach(MIMEText(msgBody)) msgText = msg.as_string() # send e-mail notification smtpServer = smtplib.SMTP_SSL(host, port) smtpServer.ehlo() smtpServer.login(fromAddr, authToken) smtpServer.sendmail(fromAddr, toAddr, msgText) smtpServer.close()
def __init__(self): self.config = ConfigUtil.ConfigUtil( '../../../data/ConnectedDevicesConfig.props') print('Configuration data...\n' + str(self.config)) senseHat.daemon = True senseHat.start()
def __init__(self): super(I2CSenseHatAdaptor, self).__init__() self.config = ConfigUtil.ConfigUtil( ConfigConst.DEFAULT_CONFIG_FILE_NAME) self.config.loadConfig() print('Configuration data...\n' + str(self.config)) self.initI2CBus()
def __init__(self): Thread.__init__(self) self.enableEmulator = True # Turn the emulator ON self.sensor = SensorData.SensorData() # Obtain sensor data self.actuator = ActuatorData.ActuatorData() # Obtain actuator data self.alertDiff = 5 # Set time for obtaining values from sensor self.rateInSec = 5 # Import configurations self.config = ConfigUtil.ConfigUtil('../../../config/ConnectedDevicesConfig.props')
def __init__(self): self.config = ConfigUtil.ConfigUtil('') self.config.loadConfig() print('Configuration data...\n' + str(self.config)) print('============= Setting Done! =============') shla.daemon = True shla.start()
def __init__(self, name): Thread.__init__(self) self.enableAdaptor = True self.sensor = SensorData.SensorData(name, 0, 30) self.temp = ConfigUtil.ConfigUtil( '../../../config/ConnectedDevicesConfig.props') self.tempEmulator = TempActuatorEmulator.TempActuatorEmulator()
def testIsConfigDataLoaded(self): #checking if the config file has been loaded, when the path is correct self.assertEqual(True, self.configUtilTests.loadConfigData()) #checking if the config file has been loaded, when the path is wrong self.configUtilTests = ConfigUtil.ConfigUtil( "/path/to/somewhere/else.props") self.assertEqual(False, self.configUtilTests.loadConfigData()) pass
def __init__(self): ''' Constructor ''' super(TempActuatorEmulator, self).__init__() self.config = ConfigUtil.ConfigUtil( '../../../data/ConnectedDevicesConfig.props') self.config.loadConfig()
def __init__(self): self.config = ConfigUtil.ConfigUtil('../../../data/ConnectedDevicesConfig.props') self.config.loadConfig() #Read the config and get the data of nominalTemp self.nomalTemp = self.config.getProperty(ConfigConst.DEVICE_SECTION, ConfigConst.nominalTemp) print("The nomalTemp is = " + str(self.nomalTemp)) SensHat.daemon = True SensHat.start()
def __init__(self): super(TempSensorAdaptor, self).__init__() self.config = ConfigUtil.ConfigUtil('') self.config.loadConfig() self.actuatorData = ActuatorData() self.tempActuatorEmulator = TempActuatorEmulator() self.senseHat = SenseHat() self.coapConnector = CoapSimpleClientConnector.CoapSimpleClientConnector( )
class HumiditySensorAdaptorTask(threading.Thread): ''' creating the required instances ''' rateInSec = DEFAULT_RATE_IN_SEC config = ConfigUtil.ConfigUtil() sensorData = SensorData.SensorData() sensorDataMgr = SensorDataManager.SensorDataManager() def __init__(self): ''' Initializing my constructor and SenseHAT API consequently ''' threading.Thread.__init__(self) self.enableEmulator = False self.senseHat = SenseHat() self.initHumidity() self.humidityData = self.senseHat.get_humidity() def initHumidity(self): logging.info("Fetching data from SenseHat API...") ''' enabling the Emulator ''' def setEmulator(self, boolean): self.enableEmulator = boolean ''' method to display my humidity data ''' def displayHumidityData(self): print('Relative Humidity through SenseHat data: ' + str(self.humidityData)) ''' method to update my humidity data through the SensorData instance ''' def updateHumidityValueSH(self): self.sensorData.addHumidityValueSH(self.humidityData) ''' Thread starts here ''' def run(self): while True: if self.enableEmulator: self.updateHumidityValueSH() self.displayHumidityData() self.sensorDataMgr.handleSensorData( self.sensorData.getHumidityValueSH(), 'humidSH') sleep(self.rateInSec)
class TempSensorEmulatorTask(threading.Thread): configUtil = ConfigUtil.ConfigUtil() ''' @param enableEmulator:boolean state of the emulator, initialized to False @param timeInterval:time in seconds between each data generation/collection @param alertDifference: difference value required for the alert generation @param lowValue:lowest value of the temperature achieved/expected @param highValue: highest value of the temperature expected/achieved @param curTemp: current value of the temperature ''' def __init__(self, alertdiff): ''' Constructor ''' threading.Thread.__init__(self) logging.basicConfig(level=logging.INFO , format=' %(asctime)s %(levelname)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S' ) self.enableEmulator = False self.sensorData = SensorData.SensorData() self.connector = SMTPClientConnector.SMTPClientConnector() self.timeInterval = int(self.configUtil.getProperty(self.configUtil.configConst.CONSTRAINED_DEVICE, self.configUtil.configConst.POLL_CYCLES_KEY)) self.alertDiff = alertdiff self.lowValue = 0 self.highValue = 30 self.curTemp = 0 def setEmulator(self, boolean): ''' method to set the emulator in order to start ''' self.enableEmulator = boolean def run(self): ''' Thread.run default function called when thread 'starts' when running, it will generate the random numbers and will update the sensor data registers accordingly. further whenever the threshold is achieved, it will push an email along with logging it to the console ''' threading.Thread.run(self) while True: if(self.enableEmulator): self.curTemp = random.uniform(float(self.lowValue), float(self.highValue)) self.sensorData.addValue(self.curTemp) print('_______________________________________________') print(str(self.sensorData.getSensorData())) if(abs(self.curTemp - self.sensorData.getAvgValue()) >= self.alertDiff): logging.info('/n Excessive Temperature with a difference > ' + str(self.alertDiff) + '/nTriggering Alert') self.connector.publishMessage('Temperature Alert:', self.sensorData.getSensorData()) logging.info('/nEmail Sent') sleep(self.timeInterval)
def __init__(self, name): ''' This Constructor is initialized in __init__; and setting enableEmulator flag to true. Assigning the sensor minimum temperature value = 0 and maximum value = 30. ''' Thread.__init__(self) self.enableEmulator = True self.sensor = SensorData.SensorData(name, 0, 30) self.temp_delay = ConfigUtil.ConfigUtil( '../../../config/ConnectedDevicesConfig.props')
def __init__(self): self.mqttClient = mqttClient.Client() #instance of the Client class of paho self.config = ConfigUtil.ConfigUtil('../../../config/data/ConnectedDevicesConfig.props') self.config.loadConfig() self.brokerAddr = self.config.getProperty(ConfigConst.MQTT_CLOUD_SECTION, ConfigConst.CLOUD_MQTT_BROKER) self.port = int(self.config.getProperty(ConfigConst.MQTT_CLOUD_SECTION,ConfigConst.CLOUD_MQTT_PORT)) self.brockerKeepAlive = int(self.config.getProperty(ConfigConst.MQTT_CLOUD_SECTION,ConfigConst.KEEP_ALIVE_KEY)) self.dataUtil = DataUtil.DataUtil() self.sensoData = SensorData.SensorData() #instance of SensorData class print(self.port)
def __init__(self, name): ''' _init_() is called during object initialization. ''' Thread.__init__(self) self.enableEmulator = True self.sensor = SensorData.SensorData(name, 0, 30) self.temp_delay = ConfigUtil.ConfigUtil( '../../../config/ConnectedDevicesConfig.props') '''
def __init__(self, max_temp, min_temp, max_updateTime, min_updateTime, configDir): Thread.__init__(self) self.max_value = max_temp self.min_value = min_temp self.maxUpdateTime = max_updateTime self.minUpdatetime = min_updateTime # get the data of device like: enableEmulator,nominalTemp... self.deviceConfigReader = ConfigUtil.ConfigUtil(configDir, "device") self.enableTempEmulator = self.deviceConfigReader.getProperty("enableEmulator") self.nominalTemp = self.deviceConfigReader.getProperty("nominalTemp") # if we chose sensehat, we should connect to sensehat part, dont add temperature by uniform function self.sh = sense_hat.SenseHat()
def __init__(self, ipAddr = "0.0.0.0", port = 5683, multicast = False): self.config = ConfigUtil.ConfigUtil(ConfigConst.DEFAULT_CONFIG_FILE_NAME) self.config.loadConfig() print('Configuration data...\n' + str(self.config)) CoAP.__init__(self, (ipAddr, port), multicast) if port >= 1024: self.port = port else: self.port = 5683 self.ipAddr = ipAddr self.useMulticast = multicast self.initResources()
def __init__(self, enableEmulator, lowVal, highVal, curTemp, isPrevTempSet): super(TempSensorAdaptor, self).__init__() self.enableEmulator = enableEmulator self.curTemp = curTemp self.lowVal = lowVal self.highVal = highVal self.isPrevTempSet = isPrevTempSet self.config = ConfigUtil.ConfigUtil('') self.config.loadConfig() self.actuatorData = ActuatorData() self.tempActuatorEmulator = TempActuatorEmulator()
def setUp(self): ''' Setting up required resources ''' self.configUtilTests = ConfigUtil.ConfigUtil() self.configUtilTests.loadConfigData() #The following case is for the github/gitbucket pipeline where the real config file is not pushed hence the tests are performed using a SAMPLE if self.configUtilTests.configFileLoaded == False: #loading the sample config file self.configUtilTests.__init__( "sample/ConnectedDevicesConfig_NO_EDIT_TEMPLATE_ONLY.props") self.configUtilTests.loadConfigData() pass
def setUp(self): #instantiate configUtil self.configUtil = ConfigUtil.ConfigUtil() #if the default config file is not loaded: while testing the pipeline on the cloud if self.configUtil.configFileLoaded == False: #load the sample config directory self.configUtil.__init__( '../sample/ConnectedDevicesConfig_NO_EDIT_TEMPLATE_ONLY.props') pass
def __init__(self, name): ''' _init_() is called during object initialization. ''' Thread.__init__(self) self.enableEmulator = True # flag to enable emulator function self.sensor = SensorData.SensorData(name, 0, 30) # creating a sensor data object self.temp = ConfigUtil.ConfigUtil( '../../../config/ConnectedDevicesConfig.props') self.temp_emul = TempActuatorEmulator.TempActuatorEmulator() '''
def __init__(self, name): ''' This thread generates a random float variable(Current Value). If the current value is greater than given threshold notification is generated. Creating a sensor data object. This Constructor is initialized in __init__; and setting enableEmulator flag to true. Assigning the sensor minimum temperature value = 0 and maximum value = 30. ''' Thread.__init__(self) self.enableAdaptor = True self.sensor = SensorData.SensorData(name, 0, 30) self.temp = ConfigUtil.ConfigUtil( '../../../config/ConnectedDevicesConfig.props') self.tempEmulator = TempActuatorEmulator.TempActuatorEmulator()
def __init__(self): super(I2CSenseHatAdaptor, self).__init__() self.config = ConfigUtil.ConfigUtil( ConfigConst.DEFAULT_CONFIG_FILE_NAME) self.config.loadConfig() flag = self.config.getProperty(ConfigConst.DEVICE, ConfigConst.ENABLE_EMULATOR_KEY) self.enableEmulator = flag self.rateInSec = DEFAULT_RATE_IN_SEC print('Configuration data...\n' + str(self.config)) self.initI2CBus()