PublishQueueExtRK
|
Queued publish for Particle devices using typed and extended publish
This is version of PublishQueuePosixRK that is designed for use with typed and extended publish in Device OS 6.3.0 and later.
This library can only be used Device OS 6.3.0 and later, but offers several benefits:
You can also find full browseable API documentation at the link or in the docs directory of this repository.
In many cases, you simply call this from setup:
And this from loop:
To publish you do something like this:
The default maximum file queue size is 100, which corresponds to 100 events. Each event takes is stored in a single file. In many cases, an event will fit in a single 4096-byte flash sector, but it could require more. A full 16K event could take 5 sectors.
This library depends on an additional library:
You must call this from setup() to initialize this library.
You must call the loop method from the global loop() function!
Sets the file-based queue size (default is 100)
size
The maximum number of files to store (one event per file)If you exceed this number of events, the oldest event is discarded.
Gets the file queue size.
Sets the directory to use as the queue directory. This is required!
dirPath
the pathname, Unix-style with / as the directory separator.Typically you create your queue either at the top level ("/myqueue") or in /usr ("/usr/myqueue"). The directory will be created if necessary, however only one level of directory will be created. The parent must already exist.
The dirPath can end with a slash or not, but if you include it, it will be removed.
You must call this as you cannot use the root directory as a queue!
Gets the directory path set using withDirPath()
The returned path will not end with a slash.
This is the recommended version to use, which takes a CloudEvent
that includes the event name and can include typed data, binary data, or structured data.
You can also Variant
that can include typed data, binary data, or structured data.
eventName
The name of the event (63 character maximum).data
The event data as a Variant
object reference.type
The ContentType
of the dataThe data is written to a file on the file system before this call returns.
This overload takes a Variant
but not a ContentType
. It should only be used when passing a VariantMap
for structured data.
eventName
The name of the event (63 character maximum).data
The event data as a Variant
object reference.The data is written to a file on the file system before this call returns.
Overload for publishing an event.
eventName
The name of the event (63 character maximum).true if the event was queued or false if it was not.
This function almost always returns true. If you queue more events than fit in the buffer the oldest (sometimes second oldest) is discarded.
Overload for publishing an event.
eventName
The name of the event (63 character maximum).data
The event data as UTF-8 text. Up to 1024 bytes depending on the Device OS version and device.true if the event was queued or false if it was not.
For larger data and typed data, use the overload that takes a CloudEvent
or Variant
.
This function almost always returns true. If you queue more events than fit in the buffer the oldest (sometimes second oldest) is discarded.
Empty both the RAM and file based queues. Any queued events are discarded.
Pause or resume publishing events.
value
The value to set, true = pause, false = normal operationIf called while a publish is in progress, that publish will still proceed, but the next event (if any) will not be attempted.
This is used by the automated test tool; you probably won't need to manually manage this under normal circumstances.
Gets the state of the pause publishing flag.
Determine if it's a good time to go to sleep.
If a publish is not in progress and the queue is empty, returns true.
If pausePublishing is true, then return true if either the current publish has completed, or not cloud connected.
Gets the total number of events queued.
This is the number of events in the RAM-based queue and the file-based queue. This operation is fast; the file queue length is stored in RAM, so this command does not need to access the file system.
If an event is currently being sent, the result includes this event.
Lock the queue protection mutex.
This is done internally; you probably won't need to call this yourself. It needs to be public for the WITH_LOCK() macro to work properly.
Attempt the queue protection mutex.
Unlock the queue protection mutex.