|
void | hookResponseHandler (const char *event, const char *data) |
| Used internally to subscribe to the subscriptionName event ("DeviceNotesResponse")
|
|
|
GetFrequency | getFrequency = GetFrequency::MANUAL |
| How often to get the value from the cloud.
|
|
bool | getAtBootCompleted = false |
| If using GetFrequency::AT_BOOT, true if it's been done.
|
|
unsigned long | getPeriodicPeriodMs = 60000 |
| Period in milliseconds for GetFrequency::PERIODIC.
|
|
unsigned long | lastGetFromCloud = 0 |
| Last millis() value we got data from the cloud.
|
|
JsonParser | jp |
| JsonParser object. Parses data from cloud and is updated by JsonModifier.
|
|
std::function< void(JsonParser &)> | dataUpdatedCallback = 0 |
| Function that gets called when data is gotten from the cloud.
|
|
bool | callDataUpdatedCallback = false |
| Flag to indicate that dataUpdateCallback should be called from loop()
|
|
bool | doGetFromCloud = false |
| Flag to indicate that we should get data from cloud (when Particle.connected)
|
|
bool | hasValidData = false |
| True after data has been downloaded from the cloud the first time.
|
|
const char * | subscriptionName = "DeviceNotesResponse" |
| Event name used for subscription. Set before setup()
|
|
const char * | getEventName = "DeviceNotesGet" |
| Event name used to get data from the cloud.
|
|
const char * | putEventName = "DeviceNotesPut" |
| Event name to put data to the cloud.
|
|
◆ GetFrequency
The frequency for how often to get.
This is set by withGetAtBook() and withGetPeriodic() so you typically don't need to use these constants directly. Default is MANUAL.
◆ DeviceNotesHelper()
DeviceNotesHelper::DeviceNotesHelper |
( |
| ) |
|
Construct the helper object.
Typically you create only one, and as global variable.
◆ ~DeviceNotesHelper()
DeviceNotesHelper::~DeviceNotesHelper |
( |
| ) |
|
|
virtual |
Destructor.
Not normally needed as you create one from a global variable.
◆ getFromCloud()
void DeviceNotesHelper::getFromCloud |
( |
| ) |
|
|
inline |
Get data from the cloud.
This is typically needed if using GetFrequency::MANUAL. It can also be used in AT_BOOT or PERIODIC modes to request data manually. If using PERIODIC mode, this will adjust the period to start from now.
◆ getHasValidData()
bool DeviceNotesHelper::getHasValidData |
( |
| ) |
const |
|
inline |
Returns true if the data has been successfully parsed.
If there are multiple parts to the get requests, this is true after the last part. If ther data in the device notes is not valid JSON, this will never be true.
◆ getJsonParser()
JsonParser& DeviceNotesHelper::getJsonParser |
( |
| ) |
|
|
inline |
Access the JsonParser object.
This is used to get data that was sent and also to modify the data. The data is updated when the getFromCloud() method is called, or at the appropriate get frequency (at boot or periodic).
◆ putToCloud()
void DeviceNotesHelper::putToCloud |
( |
| ) |
|
Put the data to the cloud.
Since you can't send multi-part data to the cloud, this is limited to 622 bytes.
◆ withBufferSize()
Sets the buffer size.
It is most efficient if you set this to be larger than the largest data you will receive.
If you only get data (don't put it to the cloud) this can be a multiple part response that is quite large.
If you put data to the cloud, then you're limited to 622 bytes, the size of a single publish.
◆ withDataUpdatedCallback()
DeviceNotesHelper& DeviceNotesHelper::withDataUpdatedCallback |
( |
std::function< void(JsonParser &)> |
callback | ) |
|
|
inline |
Register a callback to be called when the device notes have been successfully retrieved.
- Parameters
-
callback | A function or lambda function to be called when the data has been received and parsed. |
The function prototype for the callback is:
void callback(JsonParser &jp);
The callback is called from within the loop() method (not from the subscription callback) so there are fewer concurrency issues to worry about in your callback. In particular, it's safe to publish from the data updated callback if you want to.
You can only register one callback. If call it again, the existing callback will be replaced. Setting it to 0 (NULL) removes the callback.
◆ withGetAtBoot()
Sets the get data at boot flag. Default is manually.
You should call this before setup().
◆ withGetEventName()
Change the event name used for the get event.
- Parameters
-
name | A c-string containing the name. This string will not be modified. It also will not be copied so it must remain valid after this call returns. Since you'll typically pass in a string constant that will be fine. You must generate a name in a stack allocated buffer. |
Default is "DeviceNotesGet". This must match the event field in the DeviceNotesGet webhook.
◆ withGetPeriodic()
Gets data periodically. Default is manually.
- Parameters
-
periodSecs | The number of seconds between fetches. Minimum is 10 seconds. |
◆ withPutEventName()
Change the event name used for the put event.
- Parameters
-
name | A c-string containing the name. This string will not be modified. It also will not be copied so it must remain valid after this call returns. Since you'll typically pass in a string constant that will be fine. You must generate a name in a stack allocated buffer. |
Default is "DeviceNotesPut". This must match the event field in the DeviceNotesPut webhook.
◆ withSubscriptionName()
Change the event name used for the subscription.
- Parameters
-
name | A c-string containing the name. This string will not be modified. It also will not be copied so it must remain valid after this call returns. Since you'll typically pass in a string constant that will be fine. You must generate a name in a stack allocated buffer. |
Default is "DeviceNotesResponse". This must match the hook-response field in the DeviceNotesGet webhook.
The documentation for this class was generated from the following files: