The Weble IoT Universal Gateway exposes a complete JavaScript Peer-to-Peer API that lets external applications, plugins, and remote scripts read and write values, query historical data, manage gateways and addresses, listen to live events, and control the system itself.
The API is modular: each subsystem (gateways, loggers, system, accounts, logics) is exposed as a named module that can be loaded on demand. Once loaded, the module exposes its methods as ordinary asynchronous JavaScript functions — exactly as if you had require()'d it locally.
External clients reach the API over WebSocket via socket.io, after authenticating with POST /auth.
A separate, smaller REST API is available for HTTP clients that prefer not to load the full peers runtime — typically the Weble Cloud uses it to query historical data and forward write operations to remote gateways.
| Peers API | REST API | |
|---|---|---|
| Transport | WebSocket (socket.io) | HTTPS |
| Auth | POST /auth (bootstraps client) |
POST /auth/rest → session cookie |
| Surface | The full system: every module, every method | A curated subset (loggers, peers dispatcher, system, streaming) |
| Best for | Browser UIs, Node.js integrations, deep integrations | Cloud, third-party HTTP clients, mobile apps |
The peers API is the native API of the gateway — every internal subsystem talks to every other through it. The REST API is a thin HTTP veneer over the same modules, exposed for clients that cannot run the peers runtime.
Once you are connected and have loaded a module, you have direct access to its methods. A few examples:
// Load the gateways module (read/write addresses, manage gateways and routes)
peer('supervision').require('gateways', function(err, gateways){
// Write a value to KNX group address 4/7/25
gateways.writeValue('4/7/25', 1, function(err){
if(err) console.error('write failed', err)
})
// Read the last cached value of a Modbus register
gateways.getLastValue('%M1', function(err, value, value_string, value_date){
console.log('M1 =', value, 'updated at', value_date)
})
// Listen to value changes
gateways.on('newValue 4/7/25', function(address, value){
console.log('KNX 4/7/25 changed to', value)
})
})
// Load the loggers module (historical data)
peer('supervision').require('loggers', function(err, loggers){
loggers.query({
address : '4/7/25',
start : new Date(Date.now() - 86400000), // 24h ago
end : new Date(),
aggregate : '15m'
}, function(err, row){
// Streaming callback — called once per row, then once more with err='end'
if(err == 'end') return console.log('done')
if(err) return console.error(err)
console.log(row)
})
})
// Load the system module (PM2, modem, network, restart)
peer('supervision').require('system', function(err, system){
system.totalmem(function(err, bytes){
console.log('Total memory:', bytes)
})
})
| Module | Description | Reference |
|---|---|---|
gateways |
Read/write values, manage gateways/addresses/routes, request driver-specific actions | reference |
loggers |
Historical timeseries queries, live value subscriptions, log streams, log connectors | reference |
system |
PM2 process control, modem/network/HTTP/HTTPS toggles, memory & CPU stats, firmware upgrade | reference |
accounts |
Create, list, update, delete user accounts; authenticate credentials | reference |
logics |
Start/stop logic blocks, insert custom logic modules | reference |
require, share, on, emit, and the underlying serialization work.
The peers protocol has no built-in security — authentication happens once at the entry point (POST /auth), and after that any connected peer can call any exposed method.
Always wrap the WebSocket bootstrap behind HTTPS, and keep the gateway behind a firewall or VPN if it is reachable from outside the local network. If your client is untrusted or only needs a small subset of operations, prefer the REST API.