-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config: add support for lastWill and keep alive #468
Open
AmarOk1412
wants to merge
1
commit into
awslabs:main
Choose a base branch
from
AmarOk1412:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -381,6 +381,15 @@ int SharedCrtResourceManager::establishConnection(const PlainConfig &config) | |
|
||
connection = mqttClient->NewConnection(clientConfig); | ||
|
||
if (config.fleetProvisioningRuntimeConfig.completedFleetProvisioning && config.lastWillTopic.has_value() && config.lastWillMessage.has_value()) { | ||
Aws::Crt::ByteBuf payload = Aws::Crt::ByteBufFromCString(config.lastWillMessage->c_str()); | ||
if (connection->SetWill(config.lastWillTopic->c_str(), Aws::Crt::Mqtt::QOS::AWS_MQTT_QOS_AT_LEAST_ONCE, false, payload)) { | ||
LOG_INFO(TAG, "MQTT connection set will succeeded"); | ||
} else { | ||
LOG_INFO(TAG, "MQTT connection set will failed"); | ||
Comment on lines
+387
to
+389
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have more meaning full logs pasted over here? Also DEBUG logs will make more sense over here? |
||
} | ||
} | ||
|
||
if (!*connection) | ||
{ | ||
LOGM_ERROR(TAG, "MQTT Connection Creation failed with error: %s", ErrorDebugString(connection->LastError())); | ||
|
@@ -461,7 +470,18 @@ int SharedCrtResourceManager::establishConnection(const PlainConfig &config) | |
LOG_ERROR(TAG, "Device Client is not able to set reconnection settings. Device Client will retry again."); | ||
return RETRY; | ||
} | ||
if (!connection->Connect(config.thingName->c_str(), false)) | ||
|
||
int keepAliveTimeSecs = 0; | ||
if (config.connectKeepAlive.has_value()) { | ||
keepAliveTimeSecs = *config.connectKeepAlive; | ||
} | ||
|
||
int pingTimeoutMs = 0; | ||
if (config.connectTimeout.has_value()) { | ||
pingTimeoutMs = *config.connectTimeout; | ||
} | ||
|
||
if (!connection->Connect(config.thingName->c_str(), false, keepAliveTimeSecs, pingTimeoutMs)) | ||
{ | ||
LOGM_ERROR(TAG, "MQTT Connection failed with error: %s", ErrorDebugString(connection->LastError())); | ||
return RETRY; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add documentation around using this feature. I suspect user will also have to create an IoT Rule, add detailed documentation around setup required for this feature to help other users use it with ease. You will also have to update setup file and config file template to help other users set the config easily.
It is not very clear on what is the use case for this feature and why you would like to add this feature to know the device state on when it is disconnected. Can you share more details on that?
Maintaining a shadow for this feature alone is not a good idea since shadow feature is expensive than using MQTT Pub Sub messages to determine the device state.
Also consider using Device Defender feature which in timely manner uploads device side metrics to cloud. Check is you can use any DD metric to determine the device state instead?