-
Notifications
You must be signed in to change notification settings - Fork 516
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
Notify the cloud about keepalive interval changes #1908
base: develop
Are you sure you want to change the base?
Changes from all commits
629e69d
15eff3d
53a5cd8
3c8b4e4
e1cd986
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
|
||
using particle::CloudDiagnostics; | ||
using particle::publishEvent; | ||
using particle::publishKeepaliveInterval; | ||
|
||
#ifndef SPARK_NO_CLOUD | ||
|
||
|
@@ -358,6 +359,7 @@ constexpr const char KEY_RESTORE_EVENT[] = "spark/device/key/restore"; | |
constexpr const char DEVICE_UPDATES_EVENT[] = "particle/device/updates/"; | ||
constexpr const char FORCED_EVENT[] = "forced"; | ||
constexpr const char UPDATES_PENDING_EVENT[] = "pending"; | ||
constexpr const char KEEPALIVE_INTERVAL_EVENT[] = "particle/device/keepalive"; | ||
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. The device service presently already has the 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. Good to know, thanks! I also noticed that the device service expects the interval to be in seconds, while the current code sends it in milliseconds. Are we sure it's safe if Device OS will start publishing 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. @m-mcgowan @JamesHagerman Pinging here again. Should I change the event name to 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. For visibility: we discussed this internally and decided to use the new event name for now. 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. @m-mcgowan Does the rest of the PR look good to you? |
||
|
||
inline bool is_suffix(const char* eventName, const char* prefix, const char* suffix) { | ||
// todo - sanity check parameters? | ||
|
@@ -1001,6 +1003,7 @@ int Spark_Handshake(bool presence_announce) | |
} | ||
|
||
Send_Firmware_Update_Flags(); | ||
publishKeepaliveInterval(); | ||
|
||
if (presence_announce) { | ||
Multicast_Presence_Announcement(); | ||
|
@@ -1018,6 +1021,7 @@ int Spark_Handshake(bool presence_announce) | |
|
||
publishSafeModeEventIfNeeded(); | ||
Send_Firmware_Update_Flags(); | ||
publishKeepaliveInterval(); | ||
|
||
if (!HAL_RTC_Time_Is_Valid(nullptr) && spark_sync_time_last(nullptr, nullptr) == 0) { | ||
spark_protocol_send_time_request(sp); | ||
|
@@ -1114,3 +1118,28 @@ void Spark_Wake(void) | |
CloudDiagnostics* CloudDiagnostics::instance() { | ||
return &g_cloudDiagnostics; | ||
} | ||
|
||
namespace particle { | ||
|
||
#ifndef SPARK_NO_CLOUD | ||
|
||
bool publishKeepaliveInterval(unsigned interval) { | ||
if (!interval) { | ||
// Get the current interval | ||
const auto r = spark_protocol_get_connection_property(spark_protocol_instance(), protocol::Connection::PING, | ||
&interval, nullptr, nullptr); | ||
if (r != 0) { | ||
return false; | ||
} | ||
} | ||
// TODO: Even though the keepalive interval is not supposed to be changed frequently, it would be | ||
// nice to make sure the previously published event is either sent or cancelled before publishing | ||
// a new event. This would help to mitigate the effect of possible out of order delivery | ||
char buf[16] = {}; | ||
snprintf(buf, sizeof(buf), "%u", interval); | ||
return publishEvent(KEEPALIVE_INTERVAL_EVENT, buf); | ||
} | ||
|
||
#endif // !defined(SPARK_NO_CLOUD) | ||
|
||
} // particle |
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.
I agree with this. The comms layer just provides the timeout and the system layer manages the multiple stakeholders that may choose to change it. Similarly to how we manage the LED.