Skip to content

Commit

Permalink
feat: Adds publish_blob
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Hui committed Feb 9, 2024
1 parent 674701e commit d2b7868
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/cellular/sf_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 15 additions & 0 deletions src/cellular/sf_cloud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace sf
SUCCESS,
ATTEMPTS_EXCEEDED,
TIMEOUT,
NOT_CONNECTED,
OVERSIZE_DATA,
OVERSIZE_NAME,
PUBLISH_FAIL,
}error_e;

/**
Expand Down Expand Up @@ -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
7 changes: 2 additions & 5 deletions src/cli/menuItems/systemCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d2b7868

Please sign in to comment.