The loggers module exposes the historical data layer of the Weble IoT Universal Gateway. It lets you query timeseries (raw or aggregated), subscribe to live value streams, and manage logger instances — the database connectors that persist address values to disk. For the interface (Loggers menu, Log policies, charts), see Logging and history.
Load it with:
peer('supervision').require('loggers', function(err, loggers){
// loggers.query(...), loggers.live(...), loggers.getLoggers(...)
})
query(queryObject, callback)Retrieve historical values for one or more addresses, optionally aggregated. The callback is called multiple times as a stream — each call delivers one row (an object; an array of rows only with pack: true). When the stream is finished, the callback is called once more with err = 'end'.
loggers.query({
address : '4/7/25',
start : Date.now() - 86400000, // 24h ago
end : Date.now(),
aggregate : '15m'
}, function(err, row){
if(err === 'end') return console.log('done')
if(err) return console.error(err) // 'canceled', 'timeout', 'logger not connected', …
[].concat(row).forEach(function(r){ // one row per call (an array only with pack: true)
console.log(r.address, new Date(r.ts), r.value_min, r.value_avg, r.value_max)
})
})
| Field | Type | Description |
|---|---|---|
address |
string / array | Address key (id, name, alias) or array of address keys to query |
start |
Date | Start of the time window. If no row exists at exactly start, the previous row is included. |
end |
Date | End of the time window. If no row exists at exactly end, the next row is included. |
aggregate |
string | Optional. Aggregation interval. When set, returns one aggregated row per bucket (see below); when omitted, returns the raw rows. 'all' gives one bucket for the whole period. |
timezone |
string | Optional. IANA time zone (e.g. UTC, Europe/Paris) in which the aggregation buckets are calculated. Default: the time zone of the device. An error is returned if the logger does not support it. |
limit |
number | Optional. Maximum number of rows |
logger_id |
number | Optional. Query this logger only (default: the first connected mysql or cloud logger) |
Aggregation units for the aggregate field:
| Suffix | Unit |
|---|---|
s |
seconds (e.g. '30s') |
m |
minutes (e.g. '15m') |
h |
hours (e.g. '1h') |
d |
days (e.g. '1d') |
w |
weeks |
o |
months |
y |
years |
An offset can shift the buckets: 1d+6h gives days from 06:00 to 06:00 local time. Other examples: 1w-2h, 1d+330m. The offset unit is m or h.
Each row is an object. address is the key exactly as you passed it; ts is a timestamp in milliseconds.
{ address, ts, value, value_string }{ address, ts, start, end, value_avg, value_min, value_max, value_first, value_last, value_count }The stream ends with 'end', 'canceled' (after handle.cancel()) or 'timeout' (no row for 55 s). Other errors: 'logger not connected', 'missing address', 'addresse(s) not found', 'wrong aggregate', 'start date bigger than endate'.
The query call returns a handle with a cancel() method:
var handle = loggers.query({...}, function(err, row){...})
// later, to abort:
handle.cancel()
REST equivalent:
GET /loggers/data— see REST loggers endpoints.
Pass an array as the address field. Each row in the callback identifies its address via the address field (the key as you passed it).
loggers.query({
address : ['4/7/25', '4/7/26', '%M1'],
start : Date.now() - 3600000,
end : Date.now(),
aggregate : '1m'
}, function(err, row){
if(err === 'end') return
if(err) return console.error(err)
console.log(row.address, new Date(row.ts), row.value_avg)
})
live(queryObject, callback)Subscribe to live updates of one or more addresses. The callback fires every time a new value is received from the field bus, until the subscription is canceled.
var cancel = loggers.live({
address : ['4/7/25', '4/7/26']
}, function(err, update){
if(err) return console.error(err)
console.log(update.id, '=', update.value, 'at', update.value_date)
})
// Later, to stop receiving updates:
cancel()
The update object has the same shape as a row from query:
{
id : 23055,
value : 21.5,
value_string : '21.5°C',
value_date : Date
}
live is the recommended way to drive dashboards, mobile apps, and any UI that needs to react to value changes. It is more efficient than calling gateways.getLastValue in a loop, and it correctly multiplexes updates from many addresses over a single subscription.
REST equivalent:
GET /loggers/live(Server-Sent Events).
A logger is a configured database connector (local MySQL, log server, cloud) that persists address values. The gateway can run several loggers in parallel — for example one for local storage and one for cloud federation.
getLoggers(callback)Return all logger instances as an object keyed by logger id.
loggers.getLoggers(function(err, all){
Object.keys(all).forEach(function(id){
console.log(id, all[id].name, all[id].driver, all[id].state)
})
})
getLoggersLight(callback)Same as getLoggers but returns only minimal fields (id, name, description, cluster, log medium, log level). Use this for UI listings to avoid transferring the full configuration.
getLogger(loggerKey, callback)Return a single logger by id, name, or object.
insertLogger(logger, callback) / updateLogger(logger, callback) / replaceLogger(logger, callback) / deleteLogger(loggerKey, callback)Create, modify, or delete logger instances.
loggers.insertLogger({
name : 'Remote MySQL',
driver : 'mysql',
json : {
licence : '<licence key>',
storage : 'remote',
info : { host: '192.168.1.20', port: 3306, database: 'weble', user: 'weble', password: '…' }
}
}, function(err, newId){
console.log('logger created:', newId)
})
The json field's structure depends on the logger driver. For a database stored on the gateway itself, set storage (usb or fs) instead of info; prefer the web interface to create such loggers. A licence is required (invalid format otherwise). updateLogger merges the given fields into the logger; replaceLogger replaces its whole json. Both keep the licence.
startLogger(loggerKey, callback) / stopLogger(loggerKey, callback) / restartLogger(loggerKey, callback)Lifecycle control. Starting a logger triggers a connection attempt to the underlying database. The loggerState event is fired with 'connecting', then 'connected' on success or 'disconnected' on failure (the process is restarted automatically after a short delay).
startLogger and stopLogger also save the logger's active flag: a stopped logger stays stopped after a reboot, and restartLogger leaves it active.
Values reach the loggers through subscriptions. By default each logger is subscribed to the default subscription (as subscriber logger_<id>), which records every address whose logging is enabled. The subscription methods of this module (getSubscriptions, getSubscription, insertSubscription, updateSubscription, subscribe, flushSubscribe, …) and their parameters are described in Subscriptions (data acquisition pipeline), with JavaScript examples.
A task is a one-off background job that rewrites the history stored by a mysql logger. It is not a scheduler and not an export. A logger runs one task at a time; a finished or failed task is replaced by the next one. Tasks are persisted on disk so they survive restarts and continue where they left off.
Warning: tasks modify or delete logged values and cannot be undone. Export the period first (
querywithoutaggregate).
The same jobs are created from the interface in the Correction tab of the logger: see Correcting logged data.
getTasks(loggerKey, callback) / getTask(loggerKey, taskKey, callback)List the tasks of a logger, or fetch one by key. Always pass the logger id to getTasks.
loggers.getTasks(loggerId, function(err, tasks){
tasks.forEach(function(t){ console.log(t.id, t.start, t.end) })
})
insertTask(loggerKey, task, callback)Create a task on a logger. The logger must be connected.
| Field | Description |
|---|---|
type |
recompute (rebuild the aggregates from the raw values), function (JavaScript applied to each row), manual (list of corrections) or import (CSV) |
table |
logs (raw values) or an aggregate table: logs_minutely, logs_quarterly, logs_3hourly, logs_daily, logs_weekly, logs_monthly |
address |
Array of address keys, or allAddresses: true |
start, end |
Period (Date or ms) |
id |
Optional, default task_default |
loggers.insertTask(loggerId, {
type : 'recompute',
table : 'logs',
address : ['4/7/25'],
start : new Date('2026-01-01'),
end : new Date('2026-02-01')
}, function(err){
if(err) console.error(err)
})
Follow the progress with getTask(loggerId, 'task_default', cb) (status, percent).
deleteTask(loggerKey, taskKey, callback) / pauseTask(loggerKey, taskKey, callback) / resumeTask(loggerKey, taskKey, callback)Remove, pause, or resume a task. Paused tasks remain on disk but stop running until resumed.
requireDriver(driverName, callback)Load the driver-specific API of a logger driver — same pattern as gateways.requireDriver. Use this to access methods that are not part of the generic loggers API.
loggers.requireDriver('mysql', function(err, mysqlApi){
// driver-specific methods here
})
| Event | Arguments | Description |
|---|---|---|
loggerInserted |
(logger) |
New logger created |
loggerUpdated |
(newLogger, oldLogger) |
Logger modified |
loggerDeleted |
(logger) |
Logger removed |
loggerState <loggerId> |
(state) |
Connection state changed ('connecting', 'connected', 'disconnected') |
taskInserted / taskInserted <loggerId> |
(task) |
Task created |
taskDeleted / taskDeleted <loggerId> |
(task) |
Task removed |
task |
Task progress | |
stats |
(stats) |
State counters changed (see 7.1) |
subscriptionInserted / subscriptionUpdated / subscriptionDeleted |
(subscription) |
Subscription lifecycle (see 3.6) |
getStats(callback)Returns, for each logger id, how many times the logger entered each state since the supervision started, and when it last did: { "3": { connecting: 4, connecting_date: 1764000000000, connected: 4, connected_date: …, disconnected: 3, disconnected_date: … } }. A growing disconnected count means the logger keeps failing. Takes only a callback.
getCrashLog(loggerKey, callback)Retrieve the last crash dump for a logger. Useful when a logger keeps disconnecting and you want to know why.
getLoggerLogLevel(loggerKey, callback) / setLoggerLogLevel(loggerKey, level, callback) / getDriverLogs(loggerKey, options, callback)Read or change the log level of a logger while it runs, without a restart. Levels are error, warn, info and log.
loggers.query({
address : 'tempLiving',
start : new Date(Date.now() - 86400000),
end : new Date(),
aggregate : '15m'
}, function(err, row){
if(err === 'end') return console.log('done')
if(err) return console.error(err)
console.log(new Date(row.ts), row.value_min, row.value_avg, row.value_max)
})
var sub = loggers.live({
address : ['tempLiving', 'tempBedroom']
}, function(err, update){
if(err) return ws.close()
ws.send(JSON.stringify(update))
})
ws.on('close', sub) // cancel the subscription when the client disconnects
loggers.query({
address : ['%M1', '%M2', '%M3'],
start : new Date('2026-01-01'),
end : new Date('2026-02-01')
// no aggregate → raw rows
}, function(err, row){
if(err === 'end') return finalize()
if(err) return console.error(err)
writeCsvRow(row) // { address, ts, value, value_string }
})