PIOT-GDA-11-003: Create / edit module CloudClientConnector and connect into DeviceDataManager #113
Labels
exercise
New feature to implement as an exercise
Milestone
Description
CloudClientConnector
that implementsICloudClient
.CloudClientConnector
intoDeviceDataManager
Review the README
Estimated effort may vary greatly
Actions
programmingtheiot/gda/connection
source folder, create a new (or edit the existing) Java class namedCloudClientConnector
. It will implementICloudClient
, and will instanceMqttClientConnector
, as it will delegate much of its work to it.CloudClientConnector
, as follows:ICloudClient
interface by simply logging messages indicating the methods have been called.connectClient
as follows:disconnectClient()
to check ifthis.mqttClient
is non-null, and if so, invoke its disconnect method. Be sure to return a boolean indicating success or failure.createTopicName()
, as follows:this.topicPrefix
is set based on contents from the configuration file, so can be further customized by updatingPiotConfig.props
.setDataMessageListener()
method by setting the passed inIDataMessageListener
reference tothis.dataMsgListener
.MqttClientConnector
instance will also have a reference to theIDataMessageListener
instance and will handle subscription callbacks accordingly.publishMessageToCloud()
) as follows (you may want to modify it to suit your specific needs):ICloudClient
(namedsendEdgeDataToCloud()
) as follows (you may want to modify these to suit your specific needs):messageReceived()
method implemented withinMqttClientConnector
. While you can use this for handling incoming messages from the cloud service, it will require implementation of the appropriate verification logic withinmessageReceived()
to process the MQTT payload and determine what type of message should be processed, as well as where it originated. This can pose some parsing and logical flow challenges, so it's best to use the delegated approach specified forCloudClientConnector
in PIOT-GDA-11-004.Integrate with
DeviceDataManager
CloudClientConnector
withinDeviceDataManager
by storing a class-scoped boolean namedenableCloudClient
to determine ifDeviceDataManager
will establish a cloud connection or not. Here's one approach:enableCloudClient
key / value (boolean flag) toPiotConfig.props
.DeviceDataManager
with a reference toCloudClientConnector
. This will only need to be set (and subsequently activated as indicated below) ifenableCloudClient
is true. For this activity, it will need to be true of course.CloudClientConnector
within theDeviceDataManager
constructor calledcloudClient
. It's type will beICloudClient
.startManager()
method to include a call tothis.cloudClient.connectClient()
. NOTE: All connections should be started successfully before theSystemPerformanceManager
is started. This will mitigate any potential data loss condition where new system performance data is passed intoDeviceDataManager
before the cloud connection is established.stopManager()
method to include any appropriate unsubscribe calls (we'll dig into this further in Lab Module 10), followed by a call tothis.cloudClient.disconnectClient()
.handleActuatorCommandRequest()
method to handle incoming ActuatorData commands properly.handleSensorMessage()
andhandleSystemPerformanceMessage()
methods to pass their respective data tocloudClient
(ifcloudClient
is non-null and connected). These calls should be the last ones in each method.handleUpstreamTransmission()
private method with the requisite functionality to send data to the cloud service.Estimate
Tests
PiotConfig.props
to point to the cloud service provider's MQTT broker instance and will need to also ensure the provider's root certificates and credentials are available and loaded via the PIOT-CFG-10-001 instructions previously discussed.credFile
andcertFile
(these can reside anywhere on your local filesystem of course, but remember - NEVER commit sensitive data, including these files, to your Git repository!)CloudClientConnectorTest
. All test cases should pass with relevant output in the log file / console indicating success.The text was updated successfully, but these errors were encountered: