Open labbenchstudios opened 4 years ago
Hey,
I found a typo in DeviceDataManagerSimpleCdaActuationTest
float lowVal = cfgUtil.getFloat(ConfigConst.GATEWAY_DEVICE, "triggerHumidiferFloor");
Should be triggerHumidifierFloor
Same typo also in DeviceDataManager
this.triggerHumidiferFloor = configUtil.getFloat(ConfigConst.GATEWAY_DEVICE, "triggerHumidifierFloor");
Now corrected; fixed throughout code samples.
Description
DeviceDataManager
to handle incoming CDA messages: SensorData, SystemPerformanceData, and ActuatorData (response messages).Review the README
Estimated effort may vary greatly
Actions
DeviceDataManager
in PIOT-GDA-05-005 provided guidance on creating two methods:handleSensorMessage(ResourceNameEnum resourceName, SensorData data)
andhandleSystemPerformanceMessage(ResourceNameEnum resourceName, SystemPerformanceData data)
. Each currently logs a message, so let's add some real functionality.MqttClientConnector
callback, you'll first have to modifyhandleIncomingMessage(ResourceNameEnum resourceName, String msg)
to determine the content ofmsg
and then convert it into the appropriate data object usingDataUtil
. From there, you can invoke one of thesehandle...()
methods. Option 2 will invoke these directly, which is the suggested approach.handleSensorMessage()
implementation is flexible - and up to you to implement MOSTLY as you wish. Here are some guidelines, with an example implementation included at the end of this card:handleIncomingDataAnalysis(ResourceNameEnum resource, SensorData data)
private method.handleIncomingDataAnalysis(ResourceNameEnum resource, SensorData data)
, consider the following guidelines (for students of Connected Devices, these are required):SensorData
crosses these threshold values. Since the CDA already handles this for temperature, the GDA can process this for humidity instead.ActuatorData
message with the command set to turn the humidifier on or off - respectively (e.g., ON if humidity is too low, and OFF if humidity is too high (or already at nominal)).ActuatorData
message and publish it to the CDA'sResourceNameEnum.CDA_ACTUATOR_CMD_RESOURCE
topic if using MQTT, or resource if using CoAP. For your own testing / validation, I recommend including a message withActuatorData
(as the state data entry) - this should be rendered in the Sense HAT LED when running with the emulator enabled.handleUpstreamTransmission()
, passing it theResourceNameEnum
, newly generated JSON data, and - if preferable - a QoS value. The signature for this method is already in place, and the implementation can - for now - simply remain as a log message only.handleIncomingDataAnalysis(ResourceNameEnum resourceName, ActuatorData data)
, do the following:handleIncomingDataAnalysis(ResourceNameEnum resourceName, SystemStateData data)
, do the following:handleIncomingDataAnalysis(ResourceNameEnum resourceName, SensorData data)
, do the following:PiotConfig.props
configuration file, and load them withinDeviceDataManager
.ActuatorData
command and response from the CDA. This will allow the GDA to check if the command has been sent to, received and acknowledged by, the CDA.Threshold Crossing Rules - Configuration File Updates
NOTE: The example code provided here assumes there's a single CDA and GDA in the test loop.
PiotConfig.props
(you may also want to store these key names withinConfigConst
for convenience):min seconds between readings before triggering actuation event
humidityMaxTimePastThreshold = 300
ideal average humidity level (% relative)
nominalHumiditySetting = 40.0
min value before turning on humidifier (% relative)
triggerHumidifierFloor = 30.0
max value before turning off humidifier (% relative)
triggerHumidifierCeiling = 50.0
// TODO: add these to ConfigConst this.handleHumidityChangeOnDevice = configUtil.getBoolean( ConfigConst.GATEWAY_DEVICE, "handleHumidityChangeOnDevice");
this.humidityMaxTimePastThreshold = configUtil.getInteger( ConfigConst.GATEWAY_DEVICE, "humidityMaxTimePastThreshold");
this.nominalHumiditySetting = configUtil.getFloat( ConfigConst.GATEWAY_DEVICE, "nominalHumiditySetting");
this.triggerHumidifierFloor = configUtil.getFloat( ConfigConst.GATEWAY_DEVICE, "triggerHumidifierFloor");
this.triggerHumidifierCeiling = configUtil.getFloat( ConfigConst.GATEWAY_DEVICE, "triggerHumidifierCeiling");
// TODO: basic validation for timing - add other validators for remaining values if (this.humidityMaxTimePastThreshold < 10 || this.humidityMaxTimePastThreshold > 7200) { this.humidityMaxTimePastThreshold = 300; }
handleIncomingDataAnalysis(ResourceNameEnum resourceName, SensorData data)
. NOTE: You'll notice in the sample (and incomplete) code below that I added two convenience methods: one to convert the ISO 8601 timestamp String into a JavaOffsetDateTime
instance, and another to send theActuatorData
command to the CDA.this.actuatorDataListener.onActuatorDataUpdate(data)
in the private methodsendActuatorCommandtoCda(ResourceNameEnum resource, ActuatorData data)
. If you create a standalone test for this functionality (as depicted below under the Tests section), you'll need to review the updates to the actuator handler in PIOT-GDA-08-003 to ensure null ref's are handled properly. Why? The handler maintains anActuatorData
ref that is invoked within this call; however, it's only initialized when the handler's GET method is invoked. The test below never initializes theActuatorData
ref (by design), so it's important to check for a null ref first.Estimate
Tests
Simple Test Setup
DeviceDataManager
logic ONLYDeviceDataManagerSimpleCdaActuationTest
(or any other name you choose). If you'd like, you can copy the template fromDeviceDataManagerWithCommsTest.java
and remove all the existing test methods.DeviceDataManager
when receivingSensorData
messages that are from the CDA's humidity readings. Actions include the following:PiotConfig.props
, sethumidityMaxTimePastThreshold = 10
seconds (for this test)DeviceDataManager
reads this, or set the value directly (for this test)SensorData
messagetypeID = ConfigConst.HUMIDITY_SENSOR_TYPE
nominalHumiditySetting
fromPiotConfig.props
humidityMaxTimePastThreshold
humidityMaxTimePastThreshold
Integration Test Setup