diff --git a/src/cellular/sf_cloud.cpp b/src/cellular/sf_cloud.cpp index 51885635..26400e9e 100644 --- a/src/cellular/sf_cloud.cpp +++ b/src/cellular/sf_cloud.cpp @@ -4,6 +4,7 @@ #include "product.hpp" #include "sys/NVRAM.hpp" #include "system.hpp" +#include "consts.hpp" #include @@ -11,6 +12,7 @@ namespace sf::cloud { + system_tick_t last_publish_time = 0; int wait_connect(int timeout_ms) { uint16_t n_attempts; @@ -74,6 +76,12 @@ namespace sf::cloud int publish_blob(const char* title, const char* blob) { + system_tick_t time_since_last = millis() - last_publish_time; + // SF_OSAL_printf("%u ms since last publish" __NL__, time_since_last); + if (time_since_last < SF_UPLOAD_MS_PER_TRANSMIT) + { + delay(SF_UPLOAD_MS_PER_TRANSMIT - time_since_last); + } if (strlen(blob) > particle::protocol::MAX_EVENT_DATA_LENGTH) { return OVERSIZE_DATA; @@ -90,6 +98,7 @@ namespace sf::cloud { return PUBLISH_FAIL; } + last_publish_time = millis(); return SUCCESS; } diff --git a/src/cellular/sf_cloud.hpp b/src/cellular/sf_cloud.hpp index 990ff344..87ca2ef7 100644 --- a/src/cellular/sf_cloud.hpp +++ b/src/cellular/sf_cloud.hpp @@ -55,6 +55,7 @@ namespace sf /** * @brief Publishes the specified message * + * This function may block for as much as 20 seconds. * * @param title Message title. Must be 1-64 characters and only letters, * numbers, underscores, dashes, or slashes.