From d2b786842e4e5acf96243fca2ce662d6c6083306 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 8 Feb 2024 17:18:04 -0800 Subject: [PATCH] feat: Adds publish_blob --- src/cellular/sf_cloud.cpp | 21 +++++++++++++++++++++ src/cellular/sf_cloud.hpp | 15 +++++++++++++++ src/cli/menuItems/systemCommands.cpp | 7 ++----- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/cellular/sf_cloud.cpp b/src/cellular/sf_cloud.cpp index 8854dffd..cb9ea950 100644 --- a/src/cellular/sf_cloud.cpp +++ b/src/cellular/sf_cloud.cpp @@ -67,4 +67,25 @@ namespace sf::cloud nvram.put(NVRAM::CLOUD_CONNECT_COUNTER, n_attempts); return retval; } + + int publish_blob(const char* title, const char* blob) + { + if (strlen(blob) > particle::protocol::MAX_EVENT_DATA_LENGTH) + { + return OVERSIZE_DATA; + } + if (strlen(title) > particle::protocol::MAX_EVENT_NAME_LENGTH) + { + return OVERSIZE_NAME; + } + if (!Particle.connected()) + { + return NOT_CONNECTED; + } + if (!Particle.publish(title, blob)) + { + return PUBLISH_FAIL; + } + return SUCCESS; + } } \ No newline at end of file diff --git a/src/cellular/sf_cloud.hpp b/src/cellular/sf_cloud.hpp index 389a99ff..66957fbc 100644 --- a/src/cellular/sf_cloud.hpp +++ b/src/cellular/sf_cloud.hpp @@ -9,6 +9,10 @@ namespace sf SUCCESS, ATTEMPTS_EXCEEDED, TIMEOUT, + NOT_CONNECTED, + OVERSIZE_DATA, + OVERSIZE_NAME, + PUBLISH_FAIL, }error_e; /** @@ -40,6 +44,17 @@ namespace sf * @return false if in an error condition, otherwise true */ bool initialize_counter(void); + + /** + * @brief Publishes the specified message + * + * + * @param title Message title. Must be 1-64 characters and only letters, + * numbers, underscores, dashes, or slashes. + * @param blob Message blob. Must be 1024 bytes or less, UTF-8 encoded. + * @return 0 on success, otherise error code. + */ + int publish_blob(const char* title, const char* blob); }; }; #endif \ No newline at end of file diff --git a/src/cli/menuItems/systemCommands.cpp b/src/cli/menuItems/systemCommands.cpp index 9e322c10..e105d2fd 100644 --- a/src/cli/menuItems/systemCommands.cpp +++ b/src/cli/menuItems/systemCommands.cpp @@ -49,12 +49,9 @@ void CLI_doUpload(void) sprintf(integer_string, "%d", integer); strcat(other_string, integer_string); - pSystemDesc->pRecorder->openSession(); - SS_ensemble10Func(); - pSystemDesc->pRecorder->closeSession(); - CLI_nextState = STATE_UPLOAD; - SF_OSAL_printf("Quit the menu to set the next state" __NL__); + int success = sf::cloud::publish_blob(other_string, "Particle was here!"); + SF_OSAL_printf("Particle publish: %d" __NL__, success); } void CLI_self_identify(void)