def setUpClass(self):
		logging.basicConfig(format = '%(asctime)s:%(module)s:%(levelname)s:%(message)s', level = logging.DEBUG)
		logging.info("Running DataIntegrationTest test cases...")
		
		encodeToUtf8 = False
		
		self.dataUtil = DataUtil(encodeToUtf8)

		self.cdaDataPath = ConfigUtil().getProperty(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.TEST_CDA_DATA_PATH_KEY)
		self.gdaDataPath = ConfigUtil().getProperty(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.TEST_GDA_DATA_PATH_KEY)
		
		if not os.path.exists(self.cdaDataPath):
			logging.info("================================================")
			logging.info("DataIntegrationTest - path needs to be created: " + self.cdaDataPath)
			os.makedirs(self.cdaDataPath, exist_ok = True)
    def __init__(self):
        configUtil = ConfigUtil()

        self.cpuUtilPct = None
        self.memUtilPct = None

        self.pollRate = configUtil.getInteger(
            section=ConfigConst.CONSTRAINED_DEVICE,
            key=ConfigConst.POLL_CYCLES_KEY,
            defaultVal=ConfigConst.DEFAULT_POLL_CYCLES)
        self.locationID = configUtil.getProperty(
            section=ConfigConst.CONSTRAINED_DEVICE,
            key=ConfigConst.DEVICE_LOCATION_ID_KEY,
            defaultVal=ConfigConst.NOT_SET)

        if self.pollRate <= 0:
            self.pollRate = ConfigConst.DEFAULT_POLL_CYCLES

        self.scheduler = BackgroundScheduler()
        self.scheduler.add_job(self.handleTelemetry(),
                               'interval',
                               seconds=self.pollRate)

        self.cpuUtilTask = SystemCpuUtilTask()
        self.memUtilTask = SystemMemUtilTask()

        self.dataMsgListener = None
        # self.memUtilPct = None
        # self.cpuUtilPct = None

        logging.info("Initializing SystemPerformance Manager...")
Exemplo n.º 3
0
    def __init__(self, enableMqtt: bool = True, enableCoap: bool = False):
        # set enable connection
        self.enableMqtt = enableMqtt
        self.enableCoap = enableCoap
        # load config
        self.configUtil = ConfigUtil()
        self.enableEmulator = self.configUtil.getBoolean(ConfigConst.CONSTRAINED_DEVICE,
                                                         ConfigConst.ENABLE_EMULATOR_KEY)
        self.stepmotor = StepMotorAdapterTask()
        # create system Perf manager
        self.sysPerfManager = SystemPerformanceManager()
        # set sensor config
        self.sam = SensorAdapterManager(useEmulator=self.enableEmulator)
        #set actuator config
        self.aam = ActuatorAdapterManager(useEmulator=self.enableEmulator)
        #set data generation config
        self.enableHandleTempChangeOnDevice = self.configUtil.getBoolean(ConfigConst.CONSTRAINED_DEVICE,
                                                                         ConfigConst.ENABLE_HANDLE_TEMP_CHANGE_ON_DEVICE_KEY)

        self.triggerHvacTempFloor = self.configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE,
                                                             ConfigConst.TRIGGER_HVAC_TEMP_FLOOR_KEY);

        self.triggerHvacTempCeiling = self.configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE,
                                                               ConfigConst.TRIGGER_HVAC_TEMP_CEILING_KEY);
        #self.stepmotor.moveTo(-40,-40,True)
        # set Mqtt client
        if enableMqtt is True:
            self.mqttClient = MqttClientConnector()
            #self.mqttClient.subscribeToTopic(ResourceNameEnum.CDA_ACTUATOR_RESPONSE_RESOURCE.value)
            #self.mqttClient.subscribeToTopic(ResourceNameEnum.CDA_ACTUATOR_CMD_RESOURCE.value)
            self.mqttClient.subscribeToTopic("ProgrammingIoT/StepMotor/Instruction")
            #self.mqttClient.mc.message_callback_add(callback=self.actuatorCallBack, sub=ResourceNameEnum.CDA_ACTUATOR_CMD_RESOURCE.value)
            self.mqttClient.mc.message_callback_add(callback=self.stepMotorCallBack, sub="ProgrammingIoT/StepMotor/Instruction")
Exemplo n.º 4
0
	def handleTelemetry(self):
		"""
		handle the Telemetry
		
		"""
		#humidityVal = self.humiditySensorSimTask.getTelemetryValue()
		#pressureVal = self.pressureSensorSimTask.getTelemetryValue()
		#tempVal = self.temperatureSensorSimTask .getTelemetryValue()
		configUtil = ConfigUtil()
		
		if self.useEmulator :
			if configUtil.getBoolean(section= ConfigConst.CONSTRAINED_DEVICE, key= ConfigConst.ENABLE_SENSE_HAT_KEY):
				humiditySd = self.humidityI2cSensorAdapterTask.generateTelemetry()
				pressureSd = self.pressureI2cSensorAdapterTask.generateTelemetry()
				tempSd = self.temperatureI2cSensorAdapterTask.generateTelemetry()
			else:
				humiditySd = self.humidityEmulator.generateTelemetry()
				pressureSd = self.pressureEmulator.generateTelemetry()
				tempSd = self.temperatureEmulator .generateTelemetry()
				soilHumiditySd = self.soilHumidityEmulator.generateTelemetry()
		else :
			
			humiditySd = self.humiditySensorSimTask.generateTelemetry()
			pressureSd = self.pressureSensorSimTask.generateTelemetry()
			tempSd = self.temperatureSensorSimTask .generateTelemetry()
		
		if self.dataMsgListener :
			self.dataMsgListener.handleSensorMessage(humiditySd)
			self.dataMsgListener.handleSensorMessage(pressureSd)
			self.dataMsgListener.handleSensorMessage(tempSd)
			self.dataMsgListener.handleSensorMessage(soilHumiditySd)
		
		
		logging.info(' >>>>>>>>> Humidity is < %s >,  SoilHumidity is <%s>,  Pressure is < %s >,  Temperature is < %s >.', str(humiditySd.getValue()), str(soilHumiditySd.getValue()), str(pressureSd.getValue()), str(tempSd.getValue()))
Exemplo n.º 5
0
 def setUpClass(self):
     logging.basicConfig(
         format='%(asctime)s:%(module)s:%(levelname)s:%(message)s',
         level=logging.DEBUG)
     logging.info("Testing mccConnector class...")
     self.cfg = ConfigUtil()
     self.mcc = CoapClientConnector()
	def __init__(self, dataSet = None):
		super(PressureSensorEmulatorTask, self).__init__(SensorData.PRESSURE_SENSOR_TYPE, minVal = SensorDataGenerator.LOW_NORMAL_ENV_PRESSURE, maxVal = SensorDataGenerator.HI_NORMAL_ENV_PRESSURE)
		configUtil = ConfigUtil()
		#get ENABLE_SENSE_HAT_KEY value (bool)
		enableSenseHAT = configUtil.getBoolean(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_SENSE_HAT_KEY)
		if enableSenseHAT is False:
			enableEmulation = True
		else:
			enableEmulation = False
		# create senseHAT instance
		self.sh = SenseHAT(emulate=enableEmulation)
 def setUpClass(self):
     logging.basicConfig(
         format='%(asctime)s:%(module)s:%(levelname)s:%(message)s',
         level=logging.DEBUG)
     logging.info("Testing ActuatorAdapterManager class...")
     self.configUtil = ConfigUtil()
     self.enableEmulator = self.configUtil.getBoolean(
         ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_EMULATOR_KEY)
     self.defaultMsgListener = DefaultDataMessageListener()
     self.actuatorAdapterMgr = ActuatorAdapterManager(
         useEmulator=self.enableEmulator)
     self.actuatorAdapterMgr.setDataMessageListener(self.defaultMsgListener)
    def setUpClass(self):
        logging.basicConfig(
            format='%(asctime)s:%(module)s:%(levelname)s:%(message)s',
            level=logging.INFO)
        logging.info("Testing CoapClientConnector class...")

        self.dataMsgListener = DefaultDataMessageListener()

        self.pollRate = ConfigUtil().getInteger(
            ConfigConst.CONSTRAINED_DEVICE, ConfigConst.POLL_CYCLES_KEY,
            ConfigConst.DEFAULT_POLL_CYCLES)

        self.coapClient = CoapClientConnector()
 def __init__(self, enableMqtt: bool = True, enableCoap: bool = False):
     self.sysPerfManager = SystemPerformanceManager()
     self.sensorAdapterManager = SensorAdapterManager()
     self.actuatorAdapterManager = ActuatorAdapterManager()
     self.configUtil = ConfigUtil()
     self.enableHandleTempChangeOnDevice = self.configUtil.getBoolean(
         ConfigConst.CONSTRAINED_DEVICE,
         ConfigConst.ENABLE_HANDLE_TEMP_CHANGE_ON_DEVICE_KEY)
     self.triggerHvacTempFloor = self.configUtil.getFloat(
         ConfigConst.CONSTRAINED_DEVICE,
         ConfigConst.TRIGGER_HVAC_TEMP_FLOOR_KEY)
     self.triggerHvacTempCeiling = self.configUtil.getFloat(
         ConfigConst.CONSTRAINED_DEVICE,
         ConfigConst.TRIGGER_HVAC_TEMP_CEILING_KEY)
Exemplo n.º 10
0
	def __init__(self):
		super(HumidifierEmulatorTask, self).__init__(actuatorType = ActuatorData.HUMIDIFIER_ACTUATOR_TYPE, simpleName = "HUMIDIFIER")
		# Create an instance of SenseHAT and set the emulate flag to True if running the emulator, or False if using real hardware
		# This can be read from ConfigUtil using the ConfigConst.CONSTRAINED_DEVICE section and the ConfigConst.ENABLE_SENSE_HAT_KEY
		# If the ConfigConst.ENABLE_SENSE_HAT_KEY is False, set the emulate flag to True, otherwise set to False
		configUtil = ConfigUtil()
		#get ENABLE_SENSE_HAT_KEY value (bool)
		enableSenseHAT = configUtil.getBoolean(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_SENSE_HAT_KEY)
		if enableSenseHAT is False:
			enableEmulation = True
		else:
			enableEmulation = False
		# create senseHAT instance
		self.sh = SenseHAT(emulate=enableEmulation)
Exemplo n.º 11
0
 def __init__(self):
     """
     Initialization of class.
     Create an instance of HvacEmulatorTask
     """
     super(SprinklerMasterEmulatorTask, self).__init__(actuatorType = ActuatorData.SPRINKLER_MASTER_ACTUATOR_TYPE, simpleName = "SPRI_MASTER")
     # Create an instance of SenseHAT and set the emulate flag to True if running the emulator, or False if using real hardware
     # This can be read from ConfigUtil using the ConfigConst.CONSTRAINED_DEVICE section and the ConfigConst.ENABLE_SENSE_HAT_KEY
     # If the ConfigConst.ENABLE_SENSE_HAT_KEY is False, set the emulate flag to True, otherwise set to False
     configUtil = ConfigUtil()
     if configUtil.getBoolean(section= ConfigConst.CONSTRAINED_DEVICE, key= ConfigConst.ENABLE_SENSE_HAT_KEY):
         enableEmulation = False 
     else:
         enableEmulation = True
     
     self.sh = SenseHAT(emulate = enableEmulation)
Exemplo n.º 12
0
	def __init__(self, dataSet = None):
		"""
		Initialization of class.
		Create an instance of TemperatureSensorEmulatorTask
		"""
		# Create an instance of SenseHAT and set the emulate flag to True if running the emulator, or False if using real hardware
		# This can be read from ConfigUtil using the ConfigConst.CONSTRAINED_DEVICE section and the ConfigConst.ENABLE_SENSE_HAT_KEY
		# If the ConfigConst.ENABLE_SENSE_HAT_KEY is False, set the emulate flag to True, otherwise set to False
		super(TemperatureSensorEmulatorTask, self).__init__(SensorData.TEMP_SENSOR_TYPE, minVal = SensorDataGenerator.LOW_NORMAL_ENV_TEMP, maxVal = SensorDataGenerator.HI_NORMAL_ENV_TEMP)
		
		configUtil = ConfigUtil()
		if configUtil.getBoolean(section= ConfigConst.CONSTRAINED_DEVICE, key= ConfigConst.ENABLE_SENSE_HAT_KEY):
			enableEmulation = False 
		else:
			enableEmulation = True
			
		self.sh = SenseHAT(emulate = enableEmulation)
Exemplo n.º 13
0
 def __init__(self):
     """
     Constructor of HvacEmulatorTask.
     Init emulated or not SenseHAT instance according to config.
     """
     super(HvacEmulatorTask, self).__init__(actuatorType=ActuatorData.HVAC_ACTUATOR_TYPE,
                                            simpleName=ConfigConst.HVAC_ACTUATOR_NAME)
     self.enableEmulation = True
     configUtil = ConfigUtil()
     enableSenseHAT = configUtil.getBoolean(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_SENSE_HAT_KEY)
     if enableSenseHAT is True:
         self.enableEmulation = False
     else:
         self.enableEmulation = True
     self.sh = SenseHAT(emulate=self.enableEmulation)
     pass
     pass
 def __init__(self):
     self.dataUtil = DataUtil()
     self.configUtil = ConfigUtil()
     self.host = self.configUtil.getProperty(
         ConfigConst.DATA_GATEWAY_SERVICE, ConfigConst.HOST_KEY)
     self.port = self.configUtil.getInteger(
         ConfigConst.DATA_GATEWAY_SERVICE, ConfigConst.PORT_KEY)
     self.enableCrypt = self.configUtil.getBoolean(
         ConfigConst.DATA_GATEWAY_SERVICE, ConfigConst.ENABLE_CRYPT_KEY)
     if self.enableCrypt:
         self.credFilePath = self.configUtil.getProperty(
             ConfigConst.DATA_GATEWAY_SERVICE, ConfigConst.CRED_FILE_KEY)
         # TODO: init redis with encryption
     logging.info("Redis client setting: host = {0}, port = {1}.".format(
         self.host, self.port))
     # Init with no connection established
     self.curConnection: redis.client.Redis = None
    def setUpClass(self):
        logging.basicConfig(
            format='%(asctime)s:%(module)s:%(levelname)s:%(message)s',
            level=logging.INFO)
        logging.info(
            "Testing CoapServerAdapter and CoapClientConnector classes...")

        self.dataMsgListener = DefaultDataMessageListener()

        self.pollRate = ConfigUtil().getInteger(
            ConfigConst.CONSTRAINED_DEVICE, ConfigConst.POLL_CYCLES_KEY,
            ConfigConst.DEFAULT_POLL_CYCLES)

        self.coapClient = CoapClientConnector()
        self.coapServer = CoapServerAdapter(
            dataMsgListener=self.dataMsgListener)

        self.tempDataUpdateListener = GetTelemetryResourceHandler()
        self.sysPerfDataUpdateListener = GetSystemPerformanceResourceHandler()

        # add these CoAP resource handlers as listeners to the IDataMessageListener impl
        self.dataMsgListener.setTelemetryDataListener(
            ConfigConst.TEMP_SENSOR_NAME, self.tempDataUpdateListener)
        self.dataMsgListener.setSystemPerformanceDataListener(
            self.sysPerfDataUpdateListener)

        # add these CoAP resource handlers to the CoAP server
        self.coapServer.addResource( \
         ResourceNameEnum.CDA_SENSOR_MSG_RESOURCE, \
         ConfigConst.TEMP_SENSOR_NAME, \
         self.tempDataUpdateListener)

        self.coapServer.addResource( \
         ResourceNameEnum.CDA_SYSTEM_PERF_MSG_RESOURCE, \
         ConfigConst.SYSTEM_PERF_NAME, \
         self.sysPerfDataUpdateListener)

        # create a scheduler to update system perf data and temp sensor data at pollCycles
        self.scheduler = BackgroundScheduler()
        self.scheduler.add_job(self._updateTelemetry,
                               'interval',
                               seconds=self.pollRate)

        # start the server and the scheduled data updater
        self.coapServer.startServer()
        self.scheduler.start()
Exemplo n.º 16
0
 def __init__(self, dataSet=None):
     super(HumiditySensorEmulatorTask, self).__init__(
         SensorData.HUMIDITY_SENSOR_TYPE,
         minVal=SensorDataGenerator.LOW_NORMAL_ENV_HUMIDITY,
         maxVal=SensorDataGenerator.HI_NORMAL_ENV_HUMIDITY)
     # Create an instance of SenseHAT and set the emulate flag to True if running the emulator, or False if using real hardware
     # This can be read from ConfigUtil using the ConfigConst.CONSTRAINED_DEVICE section and the ConfigConst.ENABLE_SENSE_HAT_KEY
     # If the ConfigConst.ENABLE_SENSE_HAT_KEY is False, set the emulate flag to True, otherwise set to False
     configUtil = ConfigUtil()
     #get ENABLE_SENSE_HAT_KEY value (bool)
     enableSenseHAT = configUtil.getBoolean(
         ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_SENSE_HAT_KEY)
     if enableSenseHAT is False:
         enableEmulation = True
     else:
         enableEmulation = False
     #create senseHAT instance
     self.sh = SenseHAT(emulate=enableEmulation)
Exemplo n.º 17
0
    def __init__(self,
                 name=ConfigConst.NOT_SET,
                 typeID=ConfigConst.DEFAULT_TYPE_ID,
                 d=None):
        """
		Constructor.
		
		@param d Defaults to None. The data (dict) to use for setting all parameters.
		It's provided here as a convenience - mostly for testing purposes. The utility
		in DataUtil should be used instead.
		"""

        self.updateTimeStamp()
        self.hasError = False

        useDefaults = True

        if d:
            try:
                self.name = d[ConfigConst.NAME_PROP]
                self.typeID = d[ConfigConst.TYPE_ID_PROP]
                self.statusCode = d[ConfigConst.STATUS_CODE_PROP]
                self.latitude = d[ConfigConst.LATITUDE_PROP]
                self.longitude = d[ConfigConst.LONGITUDE_PROP]
                self.elevation = d[ConfigConst.ELEVATION_PROP]

                useDefaults = False
            except:
                pass

        if useDefaults:
            self.name = name
            self.typeID = typeID
            self.statusCode = ConfigConst.DEFAULT_STATUS
            self.latitude = ConfigConst.DEFAULT_LAT
            self.longitude = ConfigConst.DEFAULT_LON
            self.elevation = ConfigConst.DEFAULT_ELEVATION

        if not self.name:
            self.name = ConfigConst.NOT_SET

        # always pull location ID from configuration file
        self.locationID = ConfigUtil().getProperty(
            ConfigConst.CONSTRAINED_DEVICE, ConfigConst.DEVICE_LOCATION_ID_KEY)
 def __init__(self, dataSet=None):
     """
     Constructor of PressureSensorEmulatorTask
     Using super class constructor to init
     :param dataSet: Dict for construct object with given data
     """
     super(PressureSensorEmulatorTask, self).__init__(
         sensorType=SensorData.PRESSURE_SENSOR_TYPE,
         dataSet=dataSet,
         minVal=SensorDataGenerator.LOW_NORMAL_ENV_PRESSURE,
         maxVal=SensorDataGenerator.HI_NORMAL_ENV_PRESSURE)
     self.enableEmulation = True
     configUtil = ConfigUtil()
     enableSenseHAT = configUtil.getBoolean(
         ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_SENSE_HAT_KEY)
     if enableSenseHAT is True:
         self.enableEmulation = False
     else:
         self.enableEmulation = True
     self.sh = SenseHAT(emulate=self.enableEmulation)
     pass
Exemplo n.º 19
0
    def __init__(self):
        """
		Use the ConfigUtil configuration information for the CoAP Gateway to retrieve the host and port information.
		"""
        self.config = ConfigUtil()
        self.dataMsgListener = None
        self.coapClient = None

        self.host = self.config.getProperty(ConfigConst.COAP_GATEWAY_SERVICE,
                                            ConfigConst.HOST_KEY,
                                            ConfigConst.DEFAULT_HOST)
        self.port = self.config.getInteger(ConfigConst.COAP_GATEWAY_SERVICE,
                                           ConfigConst.PORT_KEY,
                                           ConfigConst.DEFAULT_COAP_PORT)

        logging.info('\tCoAP Server Host: ' + self.host)
        logging.info('\tCoAP Server Port: ' + str(self.port))
        """
		Validate the url information
		"""
        self.url = "coap://" + self.host + ":" + str(self.port) + "/"

        try:
            logging.info("Parsing URL: " + self.url)

            self.host, self.port, self.path = parse_uri(self.url)
            tmpHost = socket.gethostbyname(self.host)

            if tmpHost:
                self.host = tmpHost
                self._initClient()
            else:
                logging.error("Can't resolve host: " + self.host)

        except socket.gaierror:
            logging.info("Failed to resolve host: " + self.host)

        self._initClient()
Exemplo n.º 20
0
    def __init__(self, enableMqtt: bool = True, enableCoap: bool = False):
        """
		Initialization of class.
		Create an instance of DeviceDataManager
		"""

        self.configUtil = ConfigUtil()

        self.enableEmulator = self.configUtil.getBoolean(
            ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_EMULATOR_KEY)

        self.enableRedis = False

        self.sysPerfManager = SystemPerformanceManager()
        self.sysPerfManager.setDataMessageListener(self)
        self.sensorAdapterManager = SensorAdapterManager(
            useEmulator=self.enableEmulator)
        self.sensorAdapterManager.setDataMessageListener(self)
        self.actuatorAdapterManager = ActuatorAdapterManager(
            useEmulator=self.enableEmulator)
        self.actuatorAdapterManager.setDataMessageListener(self)
        ##add by miaoyao @10/30/2020
        if self.enableRedis:
            self.redisClient = RedisPersistenceAdapter()

        self.enableHandleTempChangeOnDevice = self.configUtil.getBoolean(
            ConfigConst.CONSTRAINED_DEVICE,
            ConfigConst.ENABLE_HANDLE_TEMP_CHANGE_ON_DEVICE_KEY)

        self.triggerHvacTempFloor = self.configUtil.getFloat(
            ConfigConst.CONSTRAINED_DEVICE,
            ConfigConst.TRIGGER_HVAC_TEMP_FLOOR_KEY)

        self.triggerHvacTempCeiling = self.configUtil.getFloat(
            ConfigConst.CONSTRAINED_DEVICE,
            ConfigConst.TRIGGER_HVAC_TEMP_CEILING_KEY)
        ##add by miaoyao for final project

        self.enableHandleSoilHumidityChangeOnDevice = self.configUtil.getBoolean(
            ConfigConst.CONSTRAINED_DEVICE,
            ConfigConst.ENABLE_HANDLE_SOIL_HUMIDITY_CHANGE_ON_DEVICE_KEY)

        self.triggerWaterDeviceHumiFloor = self.configUtil.getFloat(
            ConfigConst.CONSTRAINED_DEVICE,
            ConfigConst.TRIGGER_WATER_SOIL_HUMI_FLOOR_KEY)

        self.triggerWaterDeviceHumiCeiling = self.configUtil.getFloat(
            ConfigConst.CONSTRAINED_DEVICE,
            ConfigConst.TRIGGER_WATER_SOIL_HUMI_CEILING_KEY)

        ##add by miaoyao @11/02/2020
        ##self.enableMqtt = self.configUtil.getBoolean(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.ENABLE_MQTT_KEY)
        self.enableMqtt = enableMqtt
        self.enableCoap = enableCoap

        if self.enableMqtt:
            self.mqttClient = MqttClientConnector()
            self.mqttClient.setDataMessageListener(self)
        if self.enableCoap:
            self.coapClient = CoapClientConnector()
            self.coapClient.setDataMessageListener(self)
Exemplo n.º 21
0
 def setUpClass(self):
     logging.basicConfig(
         format='%(asctime)s:%(module)s:%(levelname)s:%(message)s',
         level=logging.DEBUG)
     logging.info("Testing ConfigUtil class...")
     self.configUtil = ConfigUtil(configFile=self.configFile)
    def setUpClass(self):
        logging.info("Testing MqttClientConnector class...")

        self.cfg = ConfigUtil()
        self.mcc = MqttClientConnector(clientID = 'CDAMqttClientConnectorTest001')
Exemplo n.º 23
0
    def __init__(self,
                 useEmulator: bool = False,
                 pollRate: int = 5,
                 allowConfigOverride: bool = True):
        self.useEmulator = useEmulator
        self.pollRate = pollRate

        self.dataMsgListener = 0
        self.allowConfigOverride = allowConfigOverride

        self.scheduler = BackgroundScheduler()
        self.scheduler.add_job(self.handleTelemetry,
                               'interval',
                               seconds=self.pollRate)

        if (self.useEmulator == True):
            logging.info("Emulators are being used")
            humidityModule = __import__(
                'programmingtheiot.cda.emulated.HumiditySensorEmulatorTask',
                fromlist=['HumiditySensorEmulatorTask'])
            heClazz = getattr(humidityModule, 'HumiditySensorEmulatorTask')
            self.humidityEmulator = heClazz()

            pressureModule = __import__(
                'programmingtheiot.cda.emulated.PressureSensorEmulatorTask',
                fromlist=['PressureSensorEmulatorTask'])
            heClazz = getattr(pressureModule, 'PressureSensorEmulatorTask')
            self.pressureEmulator = heClazz()

            tempModule = __import__(
                'programmingtheiot.cda.emulated.TemperatureSensorEmulatorTask',
                fromlist=['TemperatureSensorEmulatorTask'])
            heClazz = getattr(tempModule, 'TemperatureSensorEmulatorTask')
            self.tempEmulator = heClazz()

        else:
            logging.info("Simulators are being used")
            self.dataGenerator = SensorDataGenerator()
            configUtil = ConfigUtil()

            humidity_floor = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.HUMIDITY_SIM_FLOOR_KEY,
                SensorDataGenerator.LOW_NORMAL_ENV_HUMIDITY)
            humidity_ceiling = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.HUMIDITY_SIM_CEILING_KEY,
                SensorDataGenerator.HI_NORMAL_ENV_HUMIDITY)

            pressure_Floor = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.PRESSURE_SIM_FLOOR_KEY,
                SensorDataGenerator.LOW_NORMAL_ENV_PRESSURE)
            pressure_ceiling = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.PRESSURE_SIM_CEILING_KEY,
                SensorDataGenerator.HI_NORMAL_ENV_PRESSURE)

            temp_floor = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE, ConfigConst.TEMP_SIM_FLOOR_KEY,
                SensorDataGenerator.LOW_NORMAL_INDOOR_TEMP)
            temp_ceiling = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.TEMP_SIM_CEILING_KEY,
                SensorDataGenerator.HI_NORMAL_INDOOR_TEMP)

            self.humidityData = self.dataGenerator.generateDailyEnvironmentHumidityDataSet(
                minValue=humidity_floor,
                maxValue=humidity_ceiling,
                useSeconds=False)

            self.pressureData = self.dataGenerator.generateDailyEnvironmentPressureDataSet(
                minValue=pressure_Floor,
                maxValue=pressure_ceiling,
                useSeconds=False)

            self.tempData = self.dataGenerator.generateDailyIndoorTemperatureDataSet(
                minValue=temp_floor, maxValue=temp_ceiling, useSeconds=False)

            self.humiditySensorSimTask = HumiditySensorSimTask(
                self.humidityData)
            self.pressureSensorSimTask = PressureSensorSimTask(
                self.pressureData)
            self.temperatureSensorSimTask = TemperatureSensorSimTask(
                self.tempData)

            logging.info("Simulated Humidity Sensor Sim Task Value is: %s ",
                         self.humiditySensorSimTask.LatestSensorData)
            logging.info("Simulated Pressure Sensor Sim Task Value is : %s ",
                         self.pressureSensorSimTask.LatestSensorData)
            logging.info("Simulated Temperature Sensor Sim Task Value is: %s ",
                         self.temperatureSensorSimTask.LatestSensorData)
            self.handleTelemetry()
        pass
Exemplo n.º 24
0
 def __init__(self,
              useEmulator: bool = False,
              pollRate: int = 5,
              allowConfigOverride: bool = True):
     self.useEmulator = useEmulator
     self.pollRate = pollRate
     self.allowConfigOverride = allowConfigOverride
     self.dataMsgListener = IDataMessageListener()
     self.scheduler = BackgroundScheduler()
     self.scheduler.add_job(self.handleTelemetry,
                            'interval',
                            seconds=self.pollRate)
     # whether use Emulator
     if self.useEmulator is True:
         logging.info("Use Emulator")
         # load the Humidity emulator
         humidityModule = __import__(
             'programmingtheiot.cda.emulated.HumiditySensorEmulatorTask',
             fromlist=['HumiditySensorEmulatorTask'])
         heClazz = getattr(humidityModule, 'HumiditySensorEmulatorTask')
         self.humidityEmulator = heClazz()
         # load the Pressure emulator
         pressureModule = __import__(
             'programmingtheiot.cda.emulated.PressureSensorEmulatorTask',
             fromlist=['PressureSensorEmulatorTask'])
         heClazz = getattr(pressureModule, 'PressureSensorEmulatorTask')
         self.pressureEmulator = heClazz()
         # load the Temp emulator
         tempModule = __import__(
             'programmingtheiot.cda.emulated.TemperatureSensorEmulatorTask',
             fromlist=['TemperatureSensorEmulatorTask'])
         heClazz = getattr(tempModule, 'TemperatureSensorEmulatorTask')
         self.tempEmulator = heClazz()
     else:
         logging.info("Use Simulator")
         self.dataGenerator = SensorDataGenerator()
         configUtil = ConfigUtil()
         #define data range
         humidityFloor = configUtil.getFloat(
             ConfigConst.CONSTRAINED_DEVICE,
             ConfigConst.HUMIDITY_SIM_FLOOR_KEY,
             SensorDataGenerator.LOW_NORMAL_ENV_HUMIDITY)
         humidityCeiling = configUtil.getFloat(
             ConfigConst.CONSTRAINED_DEVICE,
             ConfigConst.HUMIDITY_SIM_CEILING_KEY,
             SensorDataGenerator.HI_NORMAL_ENV_HUMIDITY)
         pressureFloor = configUtil.getFloat(
             ConfigConst.CONSTRAINED_DEVICE,
             ConfigConst.PRESSURE_SIM_FLOOR_KEY,
             SensorDataGenerator.LOW_NORMAL_ENV_PRESSURE)
         pressureCeiling = configUtil.getFloat(
             ConfigConst.CONSTRAINED_DEVICE,
             ConfigConst.PRESSURE_SIM_CEILING_KEY,
             SensorDataGenerator.HI_NORMAL_ENV_PRESSURE)
         tempFloor = configUtil.getFloat(
             ConfigConst.CONSTRAINED_DEVICE, ConfigConst.TEMP_SIM_FLOOR_KEY,
             SensorDataGenerator.LOW_NORMAL_INDOOR_TEMP)
         tempCeiling = configUtil.getFloat(
             ConfigConst.CONSTRAINED_DEVICE,
             ConfigConst.TEMP_SIM_CEILING_KEY,
             SensorDataGenerator.HI_NORMAL_INDOOR_TEMP)
         #generate dataset
         self.humidityData = self.dataGenerator.generateDailyEnvironmentHumidityDataSet(
             minValue=humidityFloor,
             maxValue=humidityCeiling,
             useSeconds=False)
         self.pressureData = self.dataGenerator.generateDailyEnvironmentPressureDataSet(
             minValue=pressureFloor,
             maxValue=pressureCeiling,
             useSeconds=False)
         self.tempData = self.dataGenerator.generateDailyIndoorTemperatureDataSet(
             minValue=tempFloor, maxValue=tempCeiling, useSeconds=False)
         #create task with data
         self.htask = HumiditySensorSimTask(dataSet=self.humidityData)
         self.ptask = PressureSensorSimTask(dataSet=self.pressureData)
         self.ttask = TemperatureSensorSimTask(dataSet=self.tempData)
    def __init__(self,
                 useEmulator: bool = False,
                 enableSenseHAT: bool = False,
                 pollRate: int = 5,
                 allowConfigOverride: bool = True):
        """
        Init the SensorAdapterManager, if using simulator, setup data sets and sim tasks for simulation

        :param useEmulator: Whether use Emulator
        :param pollRate: Interval seconds for polling sensor data
        :param allowConfigOverride: If allow to override config
        """
        logging.info("SensorAdapterManager is initializing...")
        # Init basic config variables
        self.useEmulator = useEmulator
        self.pollRate = pollRate
        self.allowConfigOverride = allowConfigOverride
        # Init data message listener
        self.dataMsgListener: IDataMessageListener = None
        # Init scheduler
        self.scheduler = BackgroundScheduler()
        self.scheduler.add_job(self.handleTelemetry,
                               'interval',
                               seconds=self.pollRate)

        configUtil = ConfigUtil()
        self.enableSenseHAT = enableSenseHAT

        if self.enableSenseHAT is True:
            logging.info("SensorAdapterManager is using SenseHAT.")
            self.humiditySensorI2cTask = HumidityI2cSensorAdapterTask()
            self.pressureSensorI2cTask = PressureI2cSensorAdapterTask()
            self.temperatureSensorI2cTask = TemperatureI2cSensorAdapterTask()
            pass
        elif self.useEmulator is True:
            logging.info("SensorAdapterManager is using emulator.")

            humidityModule = __import__(
                'programmingtheiot.cda.emulated.HumiditySensorEmulatorTask',
                fromlist=['HumiditySensorEmulatorTask'])
            huClass = getattr(humidityModule, 'HumiditySensorEmulatorTask')
            self.humidityEmulator = huClass()

            pressureModule = __import__(
                'programmingtheiot.cda.emulated.PressureSensorEmulatorTask',
                fromlist=['PressureSensorEmulatorTask'])
            prClass = getattr(pressureModule, 'PressureSensorEmulatorTask')
            self.pressureEmulator = prClass()

            tempModule = __import__(
                'programmingtheiot.cda.emulated.TemperatureSensorEmulatorTask',
                fromlist=['TemperatureSensorEmulatorTask'])
            teClass = getattr(tempModule, 'TemperatureSensorEmulatorTask')
            self.tempEmulator = teClass()
        else:
            logging.info("SensorAdapterManager is using simulators.")
            self.dataGenerator = SensorDataGenerator()

            humidityFloor = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.HUMIDITY_SIM_FLOOR_KEY,
                SensorDataGenerator.LOW_NORMAL_ENV_HUMIDITY)
            humidityCeiling = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.HUMIDITY_SIM_CEILING_KEY,
                SensorDataGenerator.HI_NORMAL_ENV_HUMIDITY)
            pressureFloor = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.PRESSURE_SIM_FLOOR_KEY,
                SensorDataGenerator.LOW_NORMAL_ENV_PRESSURE)
            pressureCeiling = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.PRESSURE_SIM_CEILING_KEY,
                SensorDataGenerator.HI_NORMAL_ENV_PRESSURE)
            tempFloor = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE, ConfigConst.TEMP_SIM_FLOOR_KEY,
                SensorDataGenerator.LOW_NORMAL_INDOOR_TEMP)
            tempCeiling = configUtil.getFloat(
                ConfigConst.CONSTRAINED_DEVICE,
                ConfigConst.TEMP_SIM_CEILING_KEY,
                SensorDataGenerator.HI_NORMAL_INDOOR_TEMP)
            humidityData = self.dataGenerator.generateDailyEnvironmentHumidityDataSet(
                minValue=humidityFloor,
                maxValue=humidityCeiling,
                useSeconds=False)
            pressureData = self.dataGenerator.generateDailyEnvironmentPressureDataSet(
                minValue=pressureFloor,
                maxValue=pressureCeiling,
                useSeconds=False)
            tempData = self.dataGenerator.generateDailyIndoorTemperatureDataSet(
                minValue=tempFloor, maxValue=tempCeiling, useSeconds=False)
            self.humiditySensorSimTask = HumiditySensorSimTask(
                dataSet=humidityData,
                minVal=humidityFloor,
                maxVal=humidityCeiling)
            self.pressureSensorSimTask = PressureSensorSimTask(
                dataSet=pressureData,
                minVal=pressureFloor,
                maxVal=pressureCeiling)
            self.temperatureSensorSimTask = TemperatureSensorSimTask(
                dataSet=tempData, minVal=tempFloor, maxVal=tempCeiling)
        pass
Exemplo n.º 26
0
	def __init__(self, useEmulator: bool = False, pollRate: int = 15, allowConfigOverride: bool = True):
		"""
		Initialization of class.
		Create an instance of SensorAdapterManager
		"""
		self.useEmulator = useEmulator
		self.pollRate = pollRate
		self.allowConfigOverride = allowConfigOverride
		self.dataMsgListener = None
		self.scheduler = BackgroundScheduler()
		self.scheduler.add_job(self.handleTelemetry, 'interval', seconds = self.pollRate)
		
		configUtil = ConfigUtil()
		
		"""
		If self.useEmulator is true, we will use Emulator to generate sensor data
		Else we will use SensorDataGenerator
		"""
		if self.useEmulator :
			logging.info("---> Emulators will be used ")
			
			
			
			if configUtil.getBoolean(section= ConfigConst.CONSTRAINED_DEVICE, key= ConfigConst.ENABLE_SENSE_HAT_KEY):
				logging.info("---> SMbus will be used ")
				self.humidityI2cSensorAdapterTask = HumidityI2cSensorAdapterTask()
				self.pressureI2cSensorAdapterTask = PressureI2cSensorAdapterTask()
				self.temperatureI2cSensorAdapterTask = TemperatureI2cSensorAdapterTask()
			else:
				# load the Humidity emulator
				humidityModule = __import__('programmingtheiot.cda.emulated.HumiditySensorEmulatorTask', fromlist = ['HumiditySensorEmulatorTask'])
				heClazz = getattr(humidityModule, 'HumiditySensorEmulatorTask')
				self.humidityEmulator = heClazz()
			
				pressureModule = __import__('programmingtheiot.cda.emulated.PressureSensorEmulatorTask', fromlist = ['PressureSensorEmulatorTask'])
				peClazz = getattr(pressureModule, 'PressureSensorEmulatorTask')
				self.pressureEmulator = peClazz()
			
				temperatureModule = __import__('programmingtheiot.cda.emulated.TemperatureSensorEmulatorTask', fromlist = ['TemperatureSensorEmulatorTask'])
				teClazz = getattr(temperatureModule, 'TemperatureSensorEmulatorTask')
				self.temperatureEmulator =teClazz()
				
				##add by miaoyao for final project
				soilHumidityModule = __import__('programmingtheiot.cda.emulated.SoilHumiditySensorEmulatorTask', fromlist = ['SoilHumiditySensorEmulatorTask'])
				shClazz = getattr(soilHumidityModule, 'SoilHumiditySensorEmulatorTask')
				self.soilHumidityEmulator = shClazz()
				

			
		else:
			logging.info("---> Simulators will be used ")
			self.dataGenerator = SensorDataGenerator()

			

			humidityFloor = configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.HUMIDITY_SIM_FLOOR_KEY, SensorDataGenerator.LOW_NORMAL_ENV_HUMIDITY)
			humidityCeiling = configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.HUMIDITY_SIM_CEILING_KEY, SensorDataGenerator.HI_NORMAL_ENV_HUMIDITY)
			
			pressureFloor = configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.PRESSURE_SIM_FLOOR_KEY, SensorDataGenerator.LOW_NORMAL_ENV_PRESSURE)
			pressureCeiling = configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.PRESSURE_SIM_CEILING_KEY, SensorDataGenerator.HI_NORMAL_ENV_PRESSURE)
			
			tempFloor = configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.TEMP_SIM_FLOOR_KEY, SensorDataGenerator.LOW_NORMAL_INDOOR_TEMP)
			tempCeiling = configUtil.getFloat(ConfigConst.CONSTRAINED_DEVICE, ConfigConst.TEMP_SIM_CEILING_KEY, SensorDataGenerator.HI_NORMAL_INDOOR_TEMP)
			
			humidityData = self.dataGenerator.generateDailyEnvironmentHumidityDataSet(minValue = humidityFloor, maxValue = humidityCeiling, useSeconds = False)
			pressureData = self.dataGenerator.generateDailyEnvironmentPressureDataSet(minValue = pressureFloor, maxValue = pressureCeiling, useSeconds = False)
			tempData = self.dataGenerator.generateDailyIndoorTemperatureDataSet(minValue = tempFloor, maxValue = tempCeiling, useSeconds = False)
			
			
			
			
			self.humiditySensorSimTask = HumiditySensorSimTask(dataSet= humidityData)
			self.pressureSensorSimTask = PressureSensorSimTask(dataSet= pressureData)
			self.temperatureSensorSimTask = TemperatureSensorSimTask(dataSet= tempData)