The prupose of this module is to help chopping SenML into smaller chunks and to automatically send chunks away via MQTT as soon as a number of entries have been collected (the chopping size). Data is collected per MQTT topic to send to. The module is tuned to be used from inside logic behind projects such as http2mqtt or mqtt2any.
Configuration happens through calling the chopper configure
with one of the
following options.
-header
should contain a header that is automatically added at the beginning of each chunk. When empty, no header will be added. The default is the beginning of a JSON array, i.e.[
.-footer
should contain a footer that is automatically added at the end of each chunk before it is sent away. When empty, no footer will be added. The default is the end of a JSON array, i.e.]
.-trimright
should contain one or several characters that will be trimmed away from the right of the chunk before the footer is added. This defaults is a,
, which allows the programmer to slopily add JSON lines, all terminated with a comma, a comma that will automatically be removed.-chunk
is the number of items to have in each chunk, a negative number will keep all items in a single chunk.-pulse
is the time (in milliseconds) to wait between sending (series of) chunks. When negative or zero, all chunks are sent at once.-throttle
contains the number of chunks to send in one go before waiting for-pulse
milliseconds again.-defaults
should contain a 3-ary list where the first element is a glob-style pattern to match against MQTT topics, and the two following items are the QoS and value of the retain flag to use. These defaults are used when chunks are constructed without specific QoS and/or retain flag information.-debug
is the command to call to write out debug information, it will be called with two additional arguments, i.e. the message to print out and the level, i.e. one ofWARN
,NOTICE
,INFO
,DEBUG
,TRACE
. When empty, the default, no debug output will occur.-send
is the command to call to send chopped content to the remote. The command will be called with exactly four more arguments, i.e., in order, the MQTT topic to send to, the data to be sent, the QoS and the value of the retain flag. When empty, the default, nothing will be sent.
You can at any time start the construction (and chopping) of a message through
calling chopper append
. You can issue as many calls to the procedure as
necessary to create a JSON object. Once the JSON object is done, you should call
the chopper close
(as in closing the object), possibly with some QoS and
retain information. When no information is provided, the defaults from
-defaults
will be looked for. The module might decide to automatically send
data (via the command specified at -send
) whenever necessary. Once you are
sure that you have no more JSON data objects to add to the array, you should
call the chopper send
command, once again possibly with QoS and retain
information (see above).
An example of this flow can be found at the end of the implementation as a crude form of testing and demo.