A subscription records address values into a buffer and delivers the records to one or more subscribers. It is the pipeline between the gateway drivers and the historical loggers (time series database, cloud), and it can also feed your own applications with buffered, acknowledged data.
Subscriptions belong to the loggers module. They can be managed:
loggers module, JavaScript);By default, every logger receives its values from the
defaultsubscription. Change it only if you know why: a wrongdefaultsubscription stops history recording.

addresses) and decides when a value becomes a record (acquisition).flush rules. If the subscriber does not answer, the records are kept, in RAM or on disk (store), and sent again later.There are two levels of settings:
| Level | Defined by | Holds |
|---|---|---|
| Subscription | insertSubscription / updateSubscription / replaceSubscription |
What to record and when, buffer size, flush and disk rules |
| Subscriber | the subscriber itself, when it calls subscribe |
Its name, acknowledgment mode, lifetime, keepalive, encoding |
| Property | Default | Description |
|---|---|---|
id |
(required) | Name of the subscription. Letters, digits, ., -, _ and /. A / cannot be first, last or doubled (weble/floor1/meters is valid). Regular expression: /^(?!/)(?!.//)(?!./)[\.\-a-zA-Z_0-9\/]+/ |
addresses |
(required) | Addresses to record, see 2.1 |
acquisition |
"always" |
When to record a value, see 2.2 |
maxEntries |
100000 (if maxBytes is not set either) |
Maximum number of records in each subscriber buffer. When the buffer is full, the oldest records are lost |
maxBytes |
— | Maximum size of each subscriber buffer, in bytes of JSON text. When it is exceeded, the oldest records are lost |
encoding |
see 3 | Format of the records |
flush |
{"onEntries": 1} |
When to send the buffer, see 4 |
store |
— | When to secure the buffer on disk, see 5 |
subscribers |
{} |
Current subscribers. Read-only: it changes when subscribers call subscribe / unsubscribe |
The subscription JSON cannot contain line breaks (error forbidden line break in subscription JSON).
| Value | Meaning |
|---|---|
"all" |
Every address of the box |
"gateway_id=4" |
Every address of gateway 4 |
[1223, 2155, 5122] |
A list of address keys (ids, or "<gateway_id>¬<name>" keys) |
"1223" or "55¬%bac:local/analogInput:1" |
One address, given as a string |
{"address": 1223, "acquisition": "0 0 * * *"} |
An item of the list with its own acquisition (the other items use the subscription acquisition) |
A bare number ("addresses": 1223) is refused with invalid addresses; an empty list with addresses is empty; a missing property with missing addresses.
The acquisition is a text that decides when a new value becomes a record.
| Acquisition | Records |
|---|---|
"always" |
Every new value, even if it is equal to the previous one |
"on_update" |
A new value only if it differs from the previous value |
"on_cov 0.1" |
A new value only if it differs by at least 0.1 from the last recorded value. "on_cov 0" behaves like on_update: consecutive identical values are not recorded |
"900000" |
Every 900 000 ms (15 minutes), aligned on the clock: hh:00, hh:15, hh:30, hh:45 |
"*/15 * * * *" |
At the times of a cron expression (here every 15 minutes) |
"adr.log" |
The acquisition written in the Log property of each address (can differ for each address; an address without logging is not recorded) |
Cron expressions use the standard five fields minute hour day-of-month month day-of-week: months are 1–12, Sunday is 0 or 7.
Timing options of on_cov (in ms):
min — minimum delay between two records. "on_cov 0.1 min 10000" records at most once every 10 s.maxdiff — records a changed value after this delay, even if the change is smaller than the threshold. "on_cov 0.1 maxdiff 60000" records a small change after 60 s.max — forces a record after this delay even if the value did not change. "on_cov 0.1 max 900000" records at least every 15 minutes.They can be combined: "on_cov 0.1 min 10000 maxdiff 60000 max 900000". The aliases throttle (= min), forceafter (= maxdiff) and heartbeat (= max) are also accepted.
Several conditions are joined with or: "0 13 1 * * or 0 0 * * * or on_cov 0.1" records on the first day of each month at 1 pm, every day at midnight, and whenever the value changes by 0.1 or more.
A record is a JSON array: [timestamp, address, value, value_string]. The timestamp is a Unix time in milliseconds. The encoding object of the subscription (or of the subscriber, see 7) chooses the other items:
| Key | Values | Effect |
|---|---|---|
address |
empty (default) | The address id for "all" / "gateway_id=N" subscriptions, otherwise the address key exactly as written in addresses |
"id" |
The address id (same as "$id") |
|
"logger" |
"<gateway_id>" + | + "<name>", the format used by loggers |
|
| a pattern with jokers | $id, $name, $gateway_id, $description, $json.xyz.abc. Example: "$gateway_id¬$name" gives "55¬%bac:local/analogInput:1" |
|
"none" |
No address in the record: [timestamp, value…] |
|
value |
"json" (default) |
The decoded value as it is (number, text or object) |
"numerical" |
The decoded value as a number. Use it when only numbers are expected | |
"none" |
No decoded value | |
value_string |
"none" (default) |
No encoded value |
"driver" |
Adds the value text encoded by the driver. It can hold more than the decoded value: raw bytes in Modbus (before data type, scale and offset), the sender's individual address in KNX |
Example with {"address": "id", "value": "numerical", "value_string": "driver"}:
[1746619446731, 111905, 27.407, "27.407"]
Loggers (subscribers named logger_<id>) always receive the logger / numerical / driver encoding, whatever the subscription says.
The flush object decides when the buffer is sent to each subscriber and how much is sent at once.
| Key | Description |
|---|---|
maxEntries |
Maximum number of records per flush (100 if not set) |
maxBytes |
Maximum size of one flush, in bytes |
onEntries |
Flush as soon as the buffer holds this number of records. Default 1: every new record is sent at once |
onInterval |
Flush at the times of a cron expression, or every N milliseconds |
minDelay |
Minimum delay in ms between two flushes |
maxDelay |
Maximum delay in ms between two flushes, as long as records are waiting |
parallel |
Maximum number of flushes sent and not yet acknowledged by the subscriber (default 1) |
A slow subscriber that acknowledges late can have several flushes in progress: parallel limits them.
Records are kept in RAM. The store object decides when they are written to disk, so that they survive a restart or a long outage of the subscriber. Transitions between RAM and disk are automatic.
| Key | Description |
|---|---|
disk |
Storage device. Use "system" |
onEntries |
Write the buffer to disk when it holds this number of records |
onAckTimeouts |
Write the buffer to disk after this number of consecutive acknowledgment timeouts. The counter is reset by a successful acknowledgment. Timeouts while the subscriber is paused do not count |
onPausedDelay |
Write the buffer to disk when the subscriber has been paused for this delay in ms. Default 300000 (5 minutes). When the subscriber is a driver (a logger), stopping or restarting the driver pauses and resumes it automatically |
onRamOverflow |
true: when the system RAM is more than 90 % used, write the records to disk instead of dropping them |
maxEntries |
Maximum number of records kept on disk (protects the SD card) |
maxDuration |
Maximum duration in ms of the disk storage (protects the SD card). Past this duration a warning is logged and the buffer goes back to RAM as soon as it allows it |
When the buffer has drained and the subscriber answers again, the records return to RAM.
default subscriptionThe default subscription always exists. It cannot be deleted (cannot delete default subscription).
adr.log).default automatically, as subscriber logger_<id>, with acknowledgment by id.addresses property is kept when you edit it: all other settings are reset to the built-in values each time the system starts. To use other acquisition, flush or store settings, create a dedicated subscription and subscribe the logger to it.Built-in value:
{
"id" : "default",
"acquisition" : "adr.log", // Log property of each address
"addresses" : "all",
"maxEntries" : 1000000, // per subscriber
"encoding" : {
"value" : "numerical",
"value_string" : "driver"
},
"flush" : {
"maxEntries" : 100, // at most 100 records per flush
"onEntries" : 1, // flush as soon as there is a record
"minDelay" : 250, // at least 250 ms between flushes
"maxDelay" : 1000, // at most 1 s between flushes
"parallel" : 20 // up to 20 flushes waiting for acknowledgment
},
"store" : {
"disk" : "system",
"onEntries" : 100000, // disk above 100 000 records
"onAckTimeouts" : 1, // disk after one acknowledgment timeout
"maxDuration" : 604800000, // one week
"maxEntries" : 1000000,
"onPausedDelay" : 300000 // disk after 5 minutes of pause
},
"subscribers" : {
"logger_1" : { /* subscriber object of logger 1 */ }
}
}
A subscriber attaches itself to a subscription with subscribe. Its options are stored as a subscriber object in the subscribers property of the subscription.
| Property | Description |
|---|---|
subscription |
Id of the subscription. With a trailing / ("live/"), subscribes to every subscription whose id starts with live/ (live/sub1, live/floor1/sub3…), including those created later. Several ids can be separated with commas or given as an array |
subscriber |
Required. Name of the subscriber: letters, digits and _ only. Use one distinct name per consumer (device, process, application) |
lifetime |
In ms. The subscriber is unsubscribed automatically after this delay unless it calls subscribe again (renewal). Without lifetime, the subscriber is permanent and kept across restarts until unsubscribe |
keepalive |
In ms (minimum 5000). When nothing was sent during this delay, the subscriber receives an empty keepalive message |
ack |
Acknowledgment mode: "id" (each flush carries a numerical token to send back), "md5" (send back the md5 hash of the records), "auto" (peers API only: the JavaScript client acknowledges by itself on reception). Empty or false: the records are removed from the buffer as soon as they are sent |
ackTimeout |
In ms. Delay before unacknowledged records are sent again. Default 50000 |
encoding |
Own record encoding (see 3); the subscription encoding is used otherwise |
Pause and resume. pauseSubscribe stops the flushes to a subscriber: the subscription keeps recording for it, and the records are sent after resumeSubscribe. With the option inactive: true, the buffer is emptied and nothing is recorded for that subscriber until it resumes, but the subscriber object stays in the subscription. pauseSubscribe returns already paused and resumeSubscribe returns not paused when there is nothing to do.
Messages received by a subscriber. Every message carries an event:
| Event | Meaning |
|---|---|
subscribed |
The subscriber is attached to the subscription. First message after a successful call |
flush |
A batch of records. With ack, the message also holds the token to send back with ackSubscribe |
keepalive |
Nothing was sent during the keepalive delay |
unsubscribed |
The subscriber was detached from one subscription |
resubscribed |
subscribe was called again with the same subscriber (renewal) |
warning |
Information text, for example when the subscription does not exist yet: the subscriber waits for it to be created |
An error ends the subscribe call: end of life (lifetime reached), unsubscribed, no more subscriptions, invalid subscriber, invalid subscription, subscribe failed with error …. Deleting a subscription unsubscribes all its subscribers.
Acknowledgment. With "ack": "id" the token is a number; with "ack": "md5" it is the md5 hash of the JSON text of the records array. Records not acknowledged within ackTimeout are sent again. Acknowledging an unknown token returns no ack listeners.
| Method | Argument | Description |
|---|---|---|
getSubscriptions |
prefix (optional) | All subscriptions. "weble" returns weble and its descendants; "weble/" the descendants only |
getSubscription |
id | One subscription, or the error not found |
insertSubscription |
subscription object | Creates a subscription. Error subscription already exists if the id is taken |
updateSubscription |
subscription object | Replaces the definition of an existing subscription: send the complete object. Error subscription not found if it does not exist, no changes if nothing changed. The loggers already subscribed stay subscribed |
replaceSubscription |
subscription object | Creates the subscription, or replaces it if it exists |
deleteSubscription |
id | Deletes a subscription and unsubscribes its subscribers. "weble/" deletes all the descendants of weble |
subscribe |
subscriber options | Attaches a subscriber and receives the records, see 7 |
unsubscribe |
{subscription, subscriber} |
Detaches a subscriber |
flushSubscribe |
{subscription, subscriber} |
Sends the buffer of that subscriber now |
ackSubscribe |
{subscription, subscriber, ack} |
Acknowledges a flush |
pauseSubscribe |
{subscription, subscriber} (+ inactive) |
Pauses the flushes |
resumeSubscribe |
{subscription, subscriber} |
Resumes the flushes |
During the start of the system, the methods return not ready.
Connect as described in Getting started, then load the loggers module. subscribe calls its callback once for every message: (err, event, subscriptionId, value, ack). For flush, value is the array of records; for warning, it is the text. It returns a function that cancels the subscription.
peer('supervision').require('loggers', function(err, loggers){
if(err) return console.error(err)
// 1. A subscription for two meters, one record per change of 0.01
loggers.replaceSubscription({
id : "myapp/meters",
addresses : [111905, 111654],
acquisition : "on_cov 0.01",
encoding : { address : "id", value : "numerical" }
}, function(err){
if(err) return console.error("replaceSubscription", err)
// 2. Receive the records, acknowledged automatically
var cancel = loggers.subscribe({
subscription : "myapp/meters",
subscriber : "myapp",
ack : "auto",
lifetime : 600000, // renew before 10 minutes, or the subscriber ends
keepalive : 30000
}, function(err, event, subscriptionId, value, ack){
if(err) return console.error("subscribe ended:", err)
if(event == "flush") value.forEach(function(r){ console.log(r[0], r[1], r[2]) })
})
})
})
To acknowledge yourself, subscribe with ack: "id" and call loggers.ackSubscribe({subscription: subscriptionId, subscriber: "myapp", ack: ack}, cb) once the records are safely processed.
With the API driver, write a request to the %api/loggers address; replies arrive on the reply address. The parameters are written at the top level of the request:
{
"id": "sub1",
"module": "loggers",
"method": "insertSubscription",
"subscription": {
"id": "weble/myNewSubscription",
"addresses": [111905, 111654],
"acquisition": "on_cov 0.01"
}
}
{
"id": "subscribeCallId_xyz",
"module": "loggers",
"method": "subscribe",
"subscription": "weble/myNewSubscription",
"subscriber": "mySubscriberName",
"ack": "md5",
"ackTimeout": 10000,
"lifetime": 120000
}
For subscribe, the API driver reads subscription, subscriber, ack, ackTimeout and lifetime. Every reply carries the request id, the subscription and an event; a flush holds the records in value:
{
"id": "subscribeCallId_xyz",
"module": "loggers",
"method": "subscribe",
"subscription": "weble/myNewSubscription",
"event": "flush",
"value": [[1746619446731, 111905, 27.407], [1746619446736, 111654, 12]]
}
Acknowledge with the md5 hash of the JSON text of value:
{
"id": "333",
"module": "loggers",
"method": "ackSubscribe",
"subscription": "weble/myNewSubscription",
"subscriber": "mySubscriberName",
"ack": "6035d08d6aa19995e8ce50f6ceca286c"
}
The other methods follow the same form, with subscription (and subscriber when needed) at the top level. Request and reply details: API driver › Loggers module.
| Error | Cause |
|---|---|
invalid subscription id |
The id does not match the rule of 2 |
invalid subscriber |
subscriber missing, or with characters other than letters, digits and _ |
missing addresses / invalid addresses / addresses is empty |
See 2.1 |
subscription already exists |
insertSubscription on an existing id: use updateSubscription or replaceSubscription |
subscription not found |
Wrong id, or the subscription was deleted |
no changes |
updateSubscription with an identical object |
cannot delete default subscription |
The default subscription is permanent |
no ack listeners |
Unknown or already acknowledged token |
not ready |
The system is still starting |