EdgeEventQueueRK
|
Store and forward publishing queue for Tracker Edge and Monitor Edge
This library is intended to be used with Tracker Edge or Monitor Edge for implementing custom store and forward queueing.
setup()
:loop()
:user_init()
:user_loop()
:To queue the data on the flash file system, use the publish()
method.
Sometimes you will want to publish an event without using the queue, because the event is temporal and historical data is not useful if the device is currently offline.
To do this, use EdgeEventQueueRK::cloudServicePublish
, which takes an eventName and eventData.
This is preferable to directly using Particle.publish because it will interleave the emptying of the queue with sending your non-queued message and will not exceed the publish rate limit.
The full API is:
eventName
The event name, as is used in Particle.publish
.eventData
The event data, as is used in Particle.publish
.publishFlags
Publish flags, as is used in Particle.publish. This is optional, and if omitted the default flags are used.priority
0 or 1. 0 is the default queue and 1 is the low priority queue.cb
Callback function to be called on successful completion or error. Optional. Not called if an immediate error results in a non-zero result code; callback is only called if the return value is 0.int
0 on success or a non-zero error codeThe callback function has this prototype:
status
is particle::Error::NONE
(0) or an system error code on errorCallback is a std::function so you can pass a lambda, which allows you to pass additional data via capture variables, or call a C++ class method and instance easily.
The eventName and eventValue are copied and do not need to remain valid until the callback is called. Once the cloudServicePublish call returns, the variables can go out of scope, so it's safe for them to be local variables on the stack.
Using cloudServicePublish interleaves your event with others in the system in a queue in RAM. The queue is finite in size (currently 8 elements per priority queue) and if the queue is full, -EBUSY (-16) is returned.
Note that this function does not use the disk queue! It's a low-level function used by the publish method in this class, or you can use it for your own purposes if you want to publish events that are not saved to disk if the device is currently offline.