The API driver is an advanced driver that permits to make API calls to the IoT Universal Gateway modules using JSON formatted messages. With the help of routing functions, those API calls can be initiated from standard protocols such as HTTP(S), MQTT, BACnet, etc... making the IoT universal gateway API methods interfacable with any supported protocols.
The Getting started first section of this document explains with basic examples how to use the API driver.
The following sections are more technical and explain the modules of the driver. At the moment of this article, the API driver exposes the following IoT gateway modules
Each API module has its own methods, hence there is a two level structure for API calls (level 1 is the module to use, and the second level is the method to call). API calls can be customized or limited for security reasons inside routing functions.
Although the applications are numerous, one potential use case is to receive API calls from the MQTT protocol as shown in the schema below.
The last section of this article, Azure example, describes in details such an application. This example is taken from a project of an integration between the Azure IoT Hub and the API driver. It uses advanced routing functions and mechanisms. The Azure side uses the Azure IoT driver (gateway type azure). For a short, generic MQTT example, see API over MQTT.
The API gateway is listed in the System gateways category (when clicking on the "Insert gateway" button).
This section explains
The last section, Troubleshooting, lists the error messages returned by the driver.
The API gateway has few options:
| Label | JSON key | Default | Description |
|---|---|---|---|
| Segmentation | segmentation |
10000 |
Maximum length, in characters, of the JSON text of a reply. A longer reply is split into segments {"id", "segment", "total", "value"} emitted about 10 ms apart; concatenate the value strings in segment order to rebuild the JSON. Set 0 to disable segmentation. Stream replies are never segmented. |
| Reply with method | replyWithMethod |
false |
Adds the method key to every reply. |
| Reply with module | replyWithModule |
false |
Adds the module key to every reply. |
Example of a segmented reply: first segment {"id" : "myCallId", "segment" : 1,"total" : 10, "value" : "{..start of reply.."}, second segment {"id" : "myCallId", "segment" : 2,"total" : 10, "value" : "...json text segment..."}, ..., last segment {"id" : "myCallId", "segment" : 10,"total" : 10, "value" : "...end of reply...}"}. Segmentation is useful when working with protocols having size limitations on messages.
To expose only one module, add "gateways": false or "loggers": false to the gateway JSON (these two keys are not shown in the form).
Licence. The API driver is a licensed feature. Without the corresponding licence the gateway does not reach the connected state and its log shows
missing license.
After inserting the gateway, it automatically creates addresses for its available API modules and their methods along with their description, as shown below.

For sending requests there are 3 levels of addresses
%api%api/gateways and %api/loggers%api/gateways/getAddress, %api/gateways/readValueRequests are JSON objects formatted as follows:
{
"id" : "xyzIdCreatedByTheAPIuser", // optional but recommended to match replies with their requests.
"module" : "", // mandatory when writing on the root address "%api".
"method" : "", // mandatory when writing on the root address "%api",
// and on the modules addresses such as "%api/gateways" and "%api/loggers".
// "noreply" : true, optional parameter to not get any responses from the API after the request call.
// potential additional method specific parameters (depends on the method).
// .
// .
// .
}
Note that the module and method parameters are not needed when sending the request directly to a method address such as %api/gateways/readValue.
If the request is invalid, then an error is returned when writing it, and the request is not sent. As shown below writing an empty request to the method getAddress fails with the error "missing parameter: address".

For the getAddress method, a correct query must include the "address" parameter. When the query is successfully sent, the request address takes the value of its last request as shown below.

Using the same example on the getAddress method, after sending the request {"address" : "$test"} on the %api/gateways/getAddress method address, the request is sent to the gateway API and the reply is communicated on another address, the %api/reply address.

The API replies are always JSON objects structured as follows:
{
"id" : "xyzIdCreatedByTheAPIuser", // equals to the request "id" parameter if it was defined.
"module" : "gateways", // only defined if the gateway parameter "Reply with module" is set.
"method" : "getAddress", // only defined if the gateway parameter "Reply with method" is set.
"error" : "invalid address", // defined if the request API call ends with an error.
"value" : { // result of the request if it was successful.
"gateway_id":57,
"name":"$test",
"json":{
"readOnly":false,
"remanent":false
},
"id":163404,
"value":1,
"status":"online",
"status_date":1747831109715,
"value_string":"1",
"value_date":1747831136093
}
}
Using the id parameter to match replies with their request is important if the API gateway is used by multiple users or in general when parallel requests are made to the API. In case of parallel requests, the order of replies is not guaranteed, i.e. the first request could get its reply after other subsequent requests. Some API methods take more time than others to reply.
If the request id contains a /, the part before the last / selects the reply address and only the last part is returned as id:
| Request id | Reply emitted on | id in the reply |
|---|---|---|
"42" |
%api/reply |
"42" |
"cloud/42" |
%api/reply/cloud |
"42" |
"a/b/42" |
%api/reply/a and %api/reply/a/b |
"b/42" and "42" |
Nothing is emitted on %api/reply when a prefix is used. The reply address is created automatically the first time it is needed and is kept afterwards. Give each client its own prefix and route each %api/reply/<prefix> address to that client: every client then receives only its own replies. Stream requests follow the same rule with %api/stream/<prefix>. The Azure example uses this mechanism with the prefix sauter/.
Do not put a / in an id unless you want this behaviour. The id is always returned as a string, even if the request used a number. A request without id gets a reply without id.
Compact requests only applies to methods addresses (their name contains two / ).
If the method has a single argument, or if the other arguments are optional, it is possible to pass the argument directly to the method. The example below shows the results when we write $test (the name of the address) to the %api/gateways/getAddress method address.

If the method has multiple arguments, those can be passed using an array of arguments.
The request id can be passed as first argument using the following notation [{id:"xyzId"}, "$test"]
It is possible to merge multiple requests in a single request:
{
"id" : "xyz",
"requests" : [
{
"module":"gateways",
"method":"writeValue",
"address" : "$test",
"value" : 12
},{
"module" : "gateways",
"method" : "readValue",
"address" : "$test"
}
]
}
Here is the response if it succeeded:
[
{
"id":"xyz"
},
{
"id":"xyz",
"value":12
}
]
The request can be written to %api, to a module address or to a method address. id, module and method given at the top level are inherited by the requests that do not define them. The requests are started one after the other without waiting for the previous reply; the array of replies is emitted once all replies have arrived, in order of arrival. Give each request its own id if you need to match them. In the example above, the readValue request is therefore not guaranteed to read back the value written by writeValue.
The gateways module is the heart of the Universal IoT Gateway as it manages gateways (drivers), addresses (data points), and the mappings / routes between the addresses. Through the API driver, gateways and addresses can be read, and address values can be read and written.
Gateways are the drivers that communicates on the field buses. There is different types of gateway, each protocol has its own gateway type. Mostly encountered protocols are bacnet, modbus, KNX, m-bus, MQTT, etc.. The type of a gateway is defined in its "driver" property.
Common properties between all gateways are the "id", "name", "description" parameters, but the "json" property will contain an object that varies depending on the gateway "driver" property.
Gateways can be inserted, updated, or deleted (not through the API driver). Once a gateway is inserted, it is possible to start or stop it. Once a gateway is started, it will try to connect.
Each gateway has multiples addresses. The most important address properties are its "value" which contains the decoded address value, the "value_string" which contains the text encoded value (the encoding varies depending on the protocol), and "value_date" which contains the unix timestamp in milliseconds indicating when the value was emitted by the driver.
Other common properties of addresses are the "id" (address unique numerical id), the "name" (unique within its gateway), "description", "gateway_id" (contains the unique numerical of the address gateway), and "log" which indicates the default acquisition for the default subscription (only applicable if time series logging is activated on the device; the accepted values are described in Log and Store value policies).
Each address object has also a "json" property that will vary depending on the gateway protocol. It can even vary inside the protocol depending on the address name (each protocol can have different types or levels of addresses).
The driver creates one %api/<module>/<method> address per exposed method, with its description, so the address list of the gateway is always the reference for your firmware version. In version 9.1:
getGateways, getGatewayDrivers, getGateway, getAddresses, getAddressesByGateway, getAddress, getAddressIdsByName, getLastValue, readValue, writeValue, getGatewayLogLevel, setGatewayLogLevel, getDriverLogsgetSubscriptions, getSubscription, insertSubscription, updateSubscription, replaceSubscription, deleteSubscription, subscribe, unsubscribe, flushSubscribe, ackSubscribe, pauseSubscribe, resumeSubscribe, getLoggerLogLevel, setLoggerLogLevel, getDriverLogsNew methods can appear with an update. When requests come from an external system, always filter the permitted module/method pairs in the routing function that writes to %api (see the Azure example).
Description and examples of the main gateways module methods.
Gets all gateways.
{
"id": "myCallId",
"module": "gateways",
"method": "getGateways"
}
Reply example
{
"id": "myCallId",
"module": "gateways",
"method": "getGateways",
"value": {
"55": {
"id": 55,
"name": "testbacnet",
"description": "",
"driver": "bacnet",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"vendorId": 80,
"vendorName": "Weble",
"modelName": "EY-GTW103S",
"id": 700,
"bacnetDriver": "CSharp",
"covLifetime": 10,
"manageStatusFlags": [
1,
1,
1,
1
],
"sendIamAtStart": false,
"defaultPriority": 16,
"onErrorValue": "",
"errorRetries": 0,
"objectValue": "all properties",
"ip": [
{
"interface": "192.168.178.67/24",
"port": 47808,
"networkNumber": 0,
"timeSyncBroadcastMs": "",
"bbmds": [],
"foreignRegistrations": []
}
],
"mstp": []
},
"private_json": {}
},
"57": {
"id": 57,
"name": "internal",
"description": "",
"driver": "virtual",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {},
"private_json": {}
},
"66": {
"id": 66,
"name": "MBUS Signature energetique",
"description": "",
"driver": "remote",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"url": "192.168.178.99",
"username": "remoteuser",
"password": "...",
"gateway": 18,
"pushInitialValues": false,
"ignoreInitialValues": false
},
"private_json": {
"id": 18,
"name": "mbus",
"description": "",
"driver": "mbus",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"type": "serial",
"host": "192.168.1.1",
"port": 10001,
"serialPort": "/dev/ttyS1",
"serialBaudRate": 2400,
"onlyValues": true,
"emitOnlyChanges": "eachCycles",
"polling": 1000,
"tcpServer": false,
"tcpServerPort": 8222,
"requestTimeout": 5000,
"idleTimeout": 100,
"retry": 0,
"applyUnitFactor": true,
"legacyDriver": false
},
"private_json": {}
}
},
"67": {
"id": 67,
"name": "Meteo",
"description": "",
"driver": "previsionMeteo",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"locality": "yens"
},
"private_json": {}
},
"76": {
"id": 76,
"name": "testmodbus",
"description": "",
"driver": "modbus",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"type": "tcpSlave",
"ascii": false,
"host": "192.168.1.99",
"port": 502,
"unitId": 1,
"registerOffset": -1,
"serialPort": "",
"requestTimeout": 3000,
"idleTimeout": 20,
"baudRate": 19200,
"parity": "N",
"stopBit": 1,
"ignoreFirstValuesMs": 0,
"onErrorValue": "",
"optimizeRead": false,
"errorRetries": 2,
"fillWithZeros": false,
"mode": "local slave",
"forwardSerial": "",
"forwardBaudRate": 19200,
"forwardStopBit": 1,
"forwardHost": "",
"forwardPort": "",
"forwardRequestTimeout": 500,
"forwardIdleTimeout": 0
},
"private_json": {}
},
"114": {
"id": 114,
"name": "apitest_internal",
"description": "",
"driver": "virtual",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {},
"private_json": {}
},
"115": {
"id": 115,
"name": "testbacnet (1)",
"description": "",
"driver": "bacnet",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"vendorId": 80,
"vendorName": "Weble",
"modelName": "EY-GTW103S",
"id": 7444,
"bacnetDriver": "CSharp",
"covLifetime": 10,
"manageStatusFlags": [
1,
1,
1,
1
],
"sendIamAtStart": false,
"defaultPriority": 16,
"onErrorValue": "",
"errorRetries": 0,
"objectValue": "all properties",
"ip": [
{
"interface": "192.168.178.67/24",
"port": 47809,
"networkNumber": 0,
"timeSyncBroadcastMs": "",
"bbmds": [],
"foreignRegistrations": []
}
],
"mstp": []
},
"private_json": {}
},
"123": {
"id": 123,
"name": "sauter_cloud_azure",
"description": "",
"driver": "azure",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"connectionString": "...",
"protocol": "mqtt"
},
"private_json": {}
},
"124": {
"id": 124,
"name": "gateway_api",
"description": "",
"driver": "api",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"segmentation": 10000,
"replyWithMethod": true,
"replyWithModule": true
},
"private_json": {}
}
}
}
In this example,
"protocol": "mqtt"of the Azure gateway is a legacy value meaning MQTT over WebSocket (port 443). New gateways store"mqtt ws".
The gateways to retrieve can optionally be filtered with the filter parameter. The request below gets only bacnet gateways.
{
"id": "myCallId",
"module": "gateways",
"method": "getGateways",
"filter": {
"driver": [
"bacnet"
]
}
}
Reply example
{
"id": "myCallId",
"module": "gateways",
"method": "getGateways",
"value": {
"55": {
"id": 55,
"name": "testbacnet",
"description": "",
"driver": "bacnet",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"vendorId": 80,
"vendorName": "Weble",
"modelName": "EY-GTW103S",
"id": 700,
"bacnetDriver": "CSharp",
"covLifetime": 10,
"manageStatusFlags": [
1,
1,
1,
1
],
"sendIamAtStart": false,
"defaultPriority": 16,
"onErrorValue": "",
"errorRetries": 0,
"objectValue": "all properties",
"ip": [
{
"interface": "192.168.178.67/24",
"port": 47808,
"networkNumber": 0,
"timeSyncBroadcastMs": "",
"bbmds": [],
"foreignRegistrations": []
}
],
"mstp": []
},
"private_json": {}
},
"115": {
"id": 115,
"name": "testbacnet (1)",
"description": "",
"driver": "bacnet",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"vendorId": 80,
"vendorName": "Weble",
"modelName": "EY-GTW103S",
"id": 7444,
"bacnetDriver": "CSharp",
"covLifetime": 10,
"manageStatusFlags": [
1,
1,
1,
1
],
"sendIamAtStart": false,
"defaultPriority": 16,
"onErrorValue": "",
"errorRetries": 0,
"objectValue": "all properties",
"ip": [
{
"interface": "192.168.178.67/24",
"port": 47809,
"networkNumber": 0,
"timeSyncBroadcastMs": "",
"bbmds": [],
"foreignRegistrations": []
}
],
"mstp": []
},
"private_json": {}
}
}
}
Gets one specified gateway. The gateway parameter can either be its unique numerical id or the name of the gateway.
{
"id": "myCallId2",
"module": "gateways",
"method": "getGateway",
"gateway": 55
}
{
"id": "myCallId2",
"module": "gateways",
"method": "getGateway",
"gateway": "testbacnet"
}
Reply example
{
"id": "myCallId2",
"module": "gateways",
"method": "getGateway",
"value": {
"id": 55,
"name": "testbacnet",
"description": "",
"driver": "bacnet",
"active": 1,
"internal": 0,
"cluster": 0,
"state": "connected",
"json": {
"vendorId": 80,
"vendorName": "Weble",
"modelName": "EY-GTW103S",
"id": 700,
"bacnetDriver": "CSharp",
"covLifetime": 10,
"manageStatusFlags": [
1,
1,
1,
1
],
"sendIamAtStart": false,
"defaultPriority": 16,
"onErrorValue": "",
"errorRetries": 0,
"objectValue": "all properties",
"ip": [
{
"interface": "192.168.178.67/24",
"port": 47808,
"networkNumber": 0,
"timeSyncBroadcastMs": "",
"bbmds": [],
"foreignRegistrations": []
}
],
"mstp": []
},
"private_json": {}
}
}
Gets all addresses of the system.
{
"id": "call1234",
"module": "gateways",
"method": "getAddresses"
}
As for gateways, it is possible to filter the addresses by their properties. Here is an example of how a request to get only bacnet addresses.
{
"id": "call1234",
"module": "gateways",
"method": "getAddresses",
"filter": {
"gateway.driver": [
"bacnet"
]
}
}
Reply example
{
"id": "call1234",
"module": "gateways",
"method": "getAddresses",
"value": {
"111644": {
"id": 111644,
"alias": null,
"name": "%bac:local/analogValue:1",
"description": "aaaaa ||| CO2 from Airthings device 2950010267",
"log": "none",
"json": {
"remanent": null,
"defaultPriority": ""
},
"gateway_id": 55,
"value": {
"objectName": "aaaaa",
"description": "CO2 from Airthings device 2950010267",
"reliability": 0,
"covIncrement": 0.001,
"units": "partsPerMillion",
"priorityArray": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"relinquishDefault": 0,
"statusFlags": [
0,
0,
0,
0
],
"presentValue": 0
},
"value_string": "{\"objectName\":\"aaaaa\",\"description\":\"CO2 from Airthings device 2950010267\",\"reliability\":0,\"covIncrement\":0.001,\"units\":\"partsPerMillion\",\"priorityArray\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],\"relinquishDefault\":0,\"statusFlags\":[0,0,0,0],\"presentValue\":0}",
"value_date": 1746429395235,
"status": "online",
"status_date": 1746429396195
},
"111645": {
"id": 111645,
"alias": null,
"name": "%bac:local/analogValue:2",
"description": "analogValue:2 ||| description of analogValue:2",
"log": "none",
"json": {
"remanent": null,
"defaultPriority": ""
},
"gateway_id": 55,
"value": {
"objectName": "analogValue:2",
"description": "description of analogValue:2",
"reliability": 0,
"covIncrement": 0.001,
"units": "noUnits",
"priorityArray": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"relinquishDefault": 0,
"statusFlags": [
0,
0,
0,
0
],
"presentValue": 0
},
"value_string": "{\"objectName\":\"analogValue:2\",\"description\":\"description of analogValue:2\",\"reliability\":0,\"covIncrement\":0.001,\"units\":\"noUnits\",\"priorityArray\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],\"relinquishDefault\":0,\"statusFlags\":[0,0,0,0],\"presentValue\":0}",
"value_date": 1746429394695,
"status": "online",
"status_date": 1746429396195
},
"111646": {
"id": 111646,
"alias": null,
"name": "%bac:local",
"description": null,
"log": null,
"json": {},
"gateway_id": 55,
"value": {
"name": "testbacnet",
"id": 700,
"description": "testbacnet",
"segmentationSupported": "segmentedBoth",
"maxApduLengthAccepted": 1476,
"vendorIdentifier": 80,
"vendorName": "Weble",
"modelName": "EY-GTW103S",
"ip": [
{
"address": "192.168.178.67/24:47808",
"router": 0,
"networkNumber": 0,
"timeSyncMode": "none",
"timeSyncBroadcastMs": 2000,
"timeSyncUtc": 0,
"bbmds": [],
"foreignRegistrations": []
}
],
"mstp": [],
"covLifetime": 10
},
"value_string": "{\"name\":\"testbacnet\",\"id\":700,\"description\":\"testbacnet\",\"segmentationSupported\":\"segmentedBoth\",\"maxApduLengthAccepted\":1476,\"vendorIdentifier\":80,\"vendorName\":\"Weble\",\"modelName\":\"EY-GTW103S\",\"ip\":[{\"address\":\"192.168.178.67/24:47808\",\"router\":0,\"networkNumber\":0,\"timeSyncMode\":\"none\",\"timeSyncBroadcastMs\":2000,\"timeSyncUtc\":0,\"bbmds\":[],\"foreignRegistrations\":[]}],\"mstp\":[],\"covLifetime\":10}",
"value_date": 1746429394954,
"status": "online",
"status_date": 1746429396195
}
},
// ... and many other addresses.
}
Gets all addresses of one given gateway. The "gateway" parameter can be either the numerical id (here 55) or the gateway name (here "testbacnet")
{
"id" : "call12346",
"module" : "gateways",
"method" : "getAddressesByGateway",
"gateway" : 55
}
{
"id": "call12346",
"module": "gateways",
"method": "getAddressesByGateway",
"gateway": "testbacnet"
}
Reply example (here all addresses have their "gateway_id" property equal to 55)
Unlike getAddresses, which returns an object keyed by address id, getAddressesByGateway returns an array of address objects (same structure as in getAddresses).
{
"id": "call12346",
"module": "gateways",
"method": "getAddressesByGateway",
"value": [
{ "id": 111644, "name": "%bac:local/analogValue:1", "gateway_id": 55, "log": "none", "value": { "presentValue": 0 }, "status": "online" },
{ "id": 111645, "name": "%bac:local/analogValue:2", "gateway_id": 55, "log": "none", "value": { "presentValue": 0 }, "status": "online" }
]
}
Gets a single address by address key. The "address" parameter can be the address numerical id (111899)
{
"id": "api_call_id_123",
"module": "gateways",
"method": "getAddress",
"address": 111899
}
It is also possible to get the address by its name ("%bac:local/analogInput:1"). As the address names are not necessarily unique (e.g. 2 or more gateways of the same type), it is recommended to prefix the key with the gateway id ("55¬%bac:local/analogInput:1") or gateway name ("testbacnet¬%bac:local/analogInput:1").
{
"id": "api_call_id_123",
"module": "gateways",
"method": "getAddress",
"address": "testbacnet\u00ac%bac:local/analogInput:1"
}
To specify the gateway, the object notation {"gateway" : 55, "name" : "%bac:local/analogInput:1"} is also working.
{
"id": "api_call_id_123",
"module": "gateways",
"method": "getAddress",
"address": {
"gateway": 55,
"name": "%bac:local/analogInput:1"
}
}
Reply example
{
"id": "api_call_id_123",
"module": "gateways",
"method": "getAddress",
"value": {
"id": 111899,
"alias": null,
"name": "%bac:local/analogInput:1",
"description": "test2 ||| fd",
"log": "none",
"json": {
"remanent": null,
"defaultPriority": ""
},
"gateway_id": 55,
"value": {
"objectName": "test2",
"description": "fd",
"reliability": 0,
"covIncrement": 0.001,
"units": "noUnits",
"statusFlags": [
0,
0,
0,
0
],
"presentValue": 0
},
"value_string": "{\"objectName\":\"test2\",\"description\":\"fd\",\"reliability\":0,\"covIncrement\":0.001,\"units\":\"noUnits\",\"statusFlags\":[0,0,0,0],\"presentValue\":0}",
"value_date": 1746429395386,
"status": "online",
"status_date": 1746429396195
}
}
{
"id": "api_call_id_14",
"module": "gateways",
"method": "getAddress",
"address": [
111899,
{
"gateway": 55,
"name": "%bac:local/analogInput:1"
}
]
}
Gets the last known value of an address by address key. The address parameter behaves the same as for the getAddress method. (If address is an array, value, value_string and value_date are returned as arrays in the same order.)
{
"id": "myCallId",
"module": "gateways",
"method": "getLastValue",
"address": "testbacnet\u00ac%bac:local/analogInput:1"
}
Reply example
{
"id": "myCallId",
"module": "gateways",
"method": "getLastValue",
"value": {
"objectName": "test2",
"description": "fd",
"reliability": 0,
"covIncrement": 0.001,
"units": "noUnits",
"statusFlags": [
0,
0,
0,
0
],
"presentValue": 0
},
"value_string": "{\"objectName\":\"test2\",\"description\":\"fd\",\"reliability\":0,\"covIncrement\":0.001,\"units\":\"noUnits\",\"statusFlags\":[0,0,0,0],\"presentValue\":0}",
"value_date": 1746429395386
}
Reads the address value on the driver. This query will usually write some packets on the field bus of the protocol. For example reading a modbus RTU register will write the modbus request packets on the RS485 twisted pair bus and wait for the response. This method should be used sparingly as it could impact performances of field buses.
{
"id": "myCallId_read123",
"module": "gateways",
"method": "readValue",
"address": "testbacnet\u00ac%bac:local/analogInput:1/presentValue"
}
Reply example
{
"id":"myCallId_read123",
"module":"gateways",
"method":"readValue",
"value":12
}
Writes the address value on the driver. This method should be used sparingly as it could impact performances of field buses.
{
"id": "6c3a738c-266d-4de3-b248-8b7bae0021a6",
"module": "gateways",
"method": "writeValue",
"value": 13,
"address": "testbacnet\u00ac%bac:local/analogInput:1/presentValue"
}
Reply example
{
"id" : "6c3a738c-266d-4de3-b248-8b7bae0021a6",
"module" : "gateways",
"method" : "writeValue"
}
In case of errors, as for other all API methods the error is returned in the "error" property. In this example we try to write the text "BONJOUR" into an analog bacnet object, which only accepts numerical values.
{
"id": "6c3a738c-266d-4de3-b248-8b7bae0021a6",
"module": "gateways",
"method": "writeValue",
"value": "BONJOUR",
"address": "testbacnet\u00ac%bac:local/analogInput:1/presentValue"
}
And we get as result the "invalid value" error message in the reply JSON.
{
"error":"invalid value",
"id":"6c3a738c-266d-4de3-b248-8b7bae0021a6",
"module":"gateways",
"method":"writeValue"
}
The API for subscriptions and loggers is designed to record the data and send the data records to the loggers. The data is recorded by subscriptions, and loggers are subscribed to those to receive their data. The schema below describes the data flow coming from any protocols (BACnet, KNX, Modbus, M-Bus, ...), then filtered / recorded by subscriptions, and forwarded to their subscribers (i.e. the historical data loggers). Once the data is stored into their loggers storage (cloud, time series database, etc..) it can be retrieved by an application (web interface or other) for energy monitoring, installation troubleshooting, or any other use cases. This architecture is highly versatile and configurable.

Subscriptions record address values into a buffer and deliver the records to their subscribers (the loggers, or your own application through the API driver). The subscription keeps one buffer per subscriber and sends it again until the subscriber has acknowledged it.
The complete reference has moved to Subscriptions (data acquisition pipeline): subscription object, addresses and acquisition syntax (
always,on_update,on_cov, cron,adr.log), record encoding, flush and store settings, thedefaultsubscription, subscriber options and events.
In short:
id, addresses, acquisition, encoding, flush, store) decides what is recorded and when it is sent. Create it with insertSubscription or replaceSubscription (see 3.3).subscribe. Through the API driver, subscribe reads subscription, subscriber (required: letters, digits and _), ack ("id" or "md5"), ackTimeout (ms, default 50000) and lifetime (ms).[timestamp_ms, address, value, value_string], delivered in the value of flush messages.default subscription feeds the loggers. It can also be managed from Loggers > Subscriptions (see Loggers): change it only if you know why.
The parameters below are those of
loggers.queryin the peers API and the REST API. They cannot be sent to%api/loggers.
Here are the parameters to query historical data:
111905) or an array of addresses identifiers ([111905,111654, ...]).1747000800000 is 12 may 20251747087200000 is 13 may 2025true or false. If true, it also takes also the data points just before the start date.true or false. If true, it also takes the data points just after the end date.60000 (number of milliseconds, here 1 minute)."60s" (text containing the number of seconds suffixed with letter s)."15m" (text containing the number of minutes suffixed with letter m)."12h" (text containing the number of hours suffixed with letter h)."7d" (text containing the number of days suffixed with letter d)."2w" (text containing the number of weeks suffixed with letter w)."12o" (text containing the number of months suffixed with letter o)."none" (do not send values for the empty intervals), "last" (fill empty intervals with the last known value before the interval), "linear" (line interpolation between the value before and after the empty intervals), "boundaries" (fill only the first and last intervals and does not fill empty intervals in between). Setting "linear" is correct for line charts."left" (default) or "center". Only for aggregates. Setting "center" is correct for line charts.Example of a query without aggregation
{
"address" : "%mbus:1/0",
"start" : 1747000800000,
"end" : 1747087200000
}
Example of its raw history records (result of query)
{
"ts": 1747000810800,
"address": "%mbus:1/0",
"value": 29848,
"value_string": "29848"
}
{
"ts": 1747000824489,
"address": "%mbus:1/0",
"value": 29848,
"value_string": "29848"
}
{
"ts": 1747000838172,
"address": "%mbus:1/0",
"value": 29848,
"value_string": "29848"
}
Example of a query with an aggregation of 15 minutes
{
"address" : "%mbus:1/0",
"start" : 1747000800000,
"end" : 1747087200000,
"aggregate" : "15m"
}
Example of aggregated records
{
"ts": 1747000800000,
"address": "%mbus:1/0",
"value_first": 29848,
"value_last": 29848,
"value_min": 29848,
"value_max": 29848,
"value_avg": 29847.999999999996,
"value_var": 7.22908759445041e-23,
"value_count": 65,
"start": 1747000800000,
"end": 1747001700000
}
{
"ts": 1747001700000,
"address": "%mbus:1/0",
"value_first": 29848,
"value_last": 29848,
"value_min": 29848,
"value_max": 29848,
"value_avg": 29848,
"value_var": 1.9258444355258506e-23,
"value_count": 66,
"start": 1747001700000,
"end": 1747002600000
}
{
"ts": 1747002600000,
"address": "%mbus:1/0",
"value_first": 29848,
"value_last": 29848,
"value_min": 29848,
"value_max": 29848,
"value_avg": 29848,
"value_var": 1.5999431539513596e-23,
"value_count": 66,
"start": 1747002600000,
"end": 1747003500000
}
{
"ts": 1747003500000,
"address": "%mbus:1/0",
"value_first": 29848,
"value_last": 29848,
"value_min": 29848,
"value_max": 29848,
"value_avg": 29848.000000000007,
"value_var": 3.8721077832233975e-23,
"value_count": 66,
"start": 1747003500000,
"end": 1747004400000
}
{
"ts": 1747004400000,
"address": "%mbus:1/0",
"value_first": 29848,
"value_last": 29848,
"value_min": 29848,
"value_max": 29848,
"value_avg": 29848.000000000004,
"value_var": 4.958824868814964e-23,
"value_count": 66,
"start": 1747004400000,
"end": 1747005300000
}
{
"ts": 1747005300000,
"address": "%mbus:1/0",
"value_first": 29848,
"value_last": 29848,
"value_min": 29848,
"value_max": 29848,
"value_avg": 29848.000000000004,
"value_var": 6.83044366977094e-23,
"value_count": 66,
"start": 1747005300000,
"end": 1747006200000
}
methods to configure the subscriptions : getSubscriptions, getSubscription, insertSubscription, updateSubscription, replaceSubscription, and deleteSubscription.
methods to interact with subscriptions : subscribe, unsubscribe, flushSubscribe, ackSubscribe, pauseSubscribe, and resumeSubscribe.
recorded data is delivered by subscribe (see below). The query (history) and live methods of the loggers module are not exposed by the API driver: to read historical data, use the peers API or the REST API.
This method gets all the subscriptions.
{
"id": "12345",
"module": "loggers",
"method": "getSubscriptions"
}
It can also get all subscriptions starting with a prefix ending with /. In the following example it gets all subscriptions whose id starts with "weble/".
{
"id": "12345",
"module": "loggers",
"method": "getSubscriptions",
"subscription": "weble/"
}
The reply is an array of subscriptions objects.
this method gets a single subscription.
{
"id": "getSingleSub12345",
"module": "loggers",
"method": "getSubscription",
"subscription": "default"
}
{
"id": "qwertz",
"module": "loggers",
"method": "insertSubscription",
"subscription": {
"id": "weble/myNewSubscription",
"addresses": [
111905,
111654
],
"acquisition": "on_cov 0.01"
}
}
This method changes the subscription parameters. If the subscription doesn't exists it returns an error.
{
"id": "myCallId99",
"module": "loggers",
"method": "updateSubscription",
"subscription": {
"id": "weble/myNewSubscription",
"addresses": [
111905
],
"acquisition": "on_cov 0.001"
}
}
This method inserts a new subscription or updates the existing subscription.
{
"id": "myCallId98",
"module": "loggers",
"method": "replaceSubscription",
"subscription": {
"id": "weble/myNewSubscription",
"addresses": [
111905
],
"acquisition": "on_cov 0.001"
}
}
This method deletes an existing subscription. It returns an error if it doesn't exists. Calling this method automatically unsubscribes from the subscription all of its subscribed subscribers. Which means that if you are subscribed to this subscription, you will receive a message with the unsubscribed error : {"error" : "unsubscribed", ...}.
{
"id": "myCallId97",
"module": "loggers",
"method": "deleteSubscription",
"subscription": "weble/myNewSubscription"
}
{
"id":"subscribeCallId_xyz",
"module":"loggers",
"method":"subscribe",
"subscription":"default", // subscribe to the default subscription whose acquisition is normally defined by the address log parameter.
"subscriber" : "mySubscriberName", // mandatory: letters, digits and "_" only. Use one distinct name per consumer.
"lifetime":120000 // last 2 minutes
// "ack" : "id" optional parameter to acknowledge the records with an ack token.
}
If subscriber is missing, the reply is {"error": "invalid subscriber", ...}. If it contains other characters, the reply is {"error": "subscribe failed with error invalid subscriber", ...}.
Replies example
{
"id":"subscribeCallId_xyz",
"module":"loggers",
"method":"subscribe",
"subscription":"default",
"event":"flush",
"value":[
[
1746619446731,
111905,
27.407
],[
1746619446736,
111654,
12
]
]
}
{
"id":"subscribeCallId_xyz",
"module":"loggers",
"method":"subscribe",
"subscription":"default",
"event":"flush",
"value":[
[
1746619448000,
111905,
27.2
]
]
}
//after 2 minutes, receives end of life error
{
"id":"subscribeCallId_xyz",
"module":"loggers",
"method":"subscribe",
"subscription":"default",
"error" : "end of life"
}
Every message of a subscribe call carries the request id and an event:
event |
Meaning |
|---|---|
subscribed |
The subscriber is attached to the subscription named in subscription. First message after a successful call. |
flush |
value is an array of records. When ack was requested, ack holds the token to send back with ackSubscribe. |
keepalive |
No record was sent during the keepalive delay. |
unsubscribed |
The subscriber was detached from that subscription. |
resubscribed |
subscribe was called again for an existing subscriber. |
warning |
value is a text, for example when the subscription does not exist yet and the driver waits for it to be created. |
A message with error (for example end of life, unsubscribed, invalid subscriber) ends the call.
With "ack": "id" the token in ack is a number; with "ack": "md5" it is the md5 hash of the value array. Records that are not acknowledged within ackTimeout (50000 ms by default) are sent again. Acknowledging an unknown token returns the error no ack listeners.
Ends the subscription of the given subscriber.
{
"id": "123",
"module": "loggers",
"method": "unsubscribe",
"subscription": "default",
"subscriber": "mySubscriberName"
}
Forces the subscription to flush the buffer for the given subscriber.
{
"id": "flushCall_xyz",
"module": "loggers",
"method": "flushSubscribe",
"subscription": "default",
"subscriber": "mySubscriberName"
}
When calling the subscribe method the "ack" parameter configures if and how the data records should be acknowledged (confirmation of reception). If records must be acknowledged, the ackSubscribe method should be called to confirm reception of the records. If records are not acknowledged, the subscription will try to send again the records until acknowledgment.
{
"id": "333",
"module": "loggers",
"method": "ackSubscribe",
"subscription": "default",
"subscriber": "mySubscriberName",
"ack" : "6035d08d6aa19995e8ce50f6ceca286c"
}
Here ack is the md5 hash of the records [[1746619446731,111905,27.407],[1746619446736,111654,12]].
When a subscriber calls this method, the subscription will stop to send him new records (until it is resumed by calling the resumeSubscribe method). It returns an error "already paused" if it is already paused. Note that the subscription is still recording new records for this subscriber and adding those to its buffer of records for later consumption.
{
"id": "334",
"module": "loggers",
"method": "pauseSubscribe",
"subscription": "default",
"subscriber": "mySubscriberName"
}
The inactive option can be added to stop the subscription without fully unsubscribing (i.e. the subscriber object will still be present in the subscription). It empties the subscriber buffer and stops recording new values for him until resumeSubscribe is called.
{
"id": "334",
"module": "loggers",
"method": "pauseSubscribe",
"subscription": "default",
"subscriber": "mySubscriberName",
"inactive" : true
}
Resumes the flushing of the subscription. Returns the error "not paused" if the subscriber was not paused.
{
"id": "3355",
"module": "loggers",
"method": "resumeSubscribe",
"subscription": "default",
"subscriber": "mySubscriberName"
}
When API replies are too long, such as for retrieving all addresses of the system, it is possible to specify in the request JSON the stream option. This can be used to stream big request replies as files, such as uploading files to a FTP server or to the azure IoT HUB as shown in next section.
{
"id": "9c1efcd1-d127-4f5b-a6b3-d9709d1484c0",
"module": "gateways",
"method": "getAddresses",
"stream": 1
}
When this option is set such as in the request below, the reply is not directly emitted in the %api/replyaddress, but instead the request is stored in "%api/stream address and waiting to be consumed. Nonetheless the %api/reply emits the original request if it was successful.
%api/reply value after the stream request :
{
"id": "9c1efcd1-d127-4f5b-a6b3-d9709d1484c0",
"module": "gateways",
"method": "getAddresses",
"stream": 1
}
%api/stream value after the stream request :
{
"9c1efcd1-d127-4f5b-a6b3-d9709d1484c0":{
"id":"9c1efcd1-d127-4f5b-a6b3-d9709d1484c0",
"module":"gateways",
"method":"getAddresses",
"stream":1
},
/*.... other request streams waiting to be consumed*/
}
The %api/stream is streamable, and this readable stream can be consumed from other drivers that support streaming. In the stream object options, the option id must be specified with the id of the request (here 9c1efcd1-d127-4f5b-a6b3-d9709d1484c0).
The streamed file contains {"value": ...} (plus module / method if enabled) and no id; for getAddresses the value is an array of addresses. The id of a stream request must be a string.
Example of a stream triggering object that can be routed to a writable stream address (here %azure:file_upload).
{
name : "%api/stream", // the readable stream address
gateway_id : 124, // the API gateway id
sourceOptions : {
"id" : "9c1efcd1-d127-4f5b-a6b3-d9709d1484c0"
},
destinationOptions : {
"name" : "addresses.json" //blob name for the Azure IoT Hub upload
}
}
When the %azure:file_upload address is written with the object above, the azure driver reads the reply stream from the API driver and uploads the reply as a JSON file to the azure IoT Hub blob storage.
The goal of this project is to get all bacnet addresses and to subscribe to their value changes. This example shows an advanced use case of how to process API requests coming from some protocol (here MQTT Azure IoT hub). There are 4 routes described below
history/. Additionally, it automatically pauses subscriptions if the azure gateway gets disconnected, and resumes those once the azure gateway is back online.
value,value,-1,%azure:telemetry_in/body from the Azure gateway.%apifrom the API gateway.function azureToApi(value, source,dest, infos){
// 1. checks that the object received is correct
// 2. checks if the method calls are permitted.
// 3. checks if the api gateway is online
// 4. adds the "sauter/" to requests for call ids and subscriptions.
// 5. sets the subscriber to "sauter" for subscribes.
// 6. sets the subscribe acknowledgment to "md5" for the ACK_SUBSCRIPTION route.
if(!value) return
if(!value || (value && value.constructor.name != "Object")){
console.error("invalid telemetry from azure",value)
return
}
if(!value.method || !value.module){
console.error("invalid telemetry from azure", value)
return
}
if(!value.id) value.id = "defaultId"
var permitted = infos.context.permitted
if(!permitted){
permitted = {
"gateways" : {
"getAddress" : 1,
"getAddresses" : 1,
"getAddressesByGateway" : 1,
"getGateways" : 1,
"getGateway" : 1,
"getLastValue" : 1,
"readValue" : 1,
"writeValue" : 1
},
"loggers" : {
"getSubscription" : 1,
"getSubscriptions" : 1,
"insertSubscription" : 1,
"replaceSubscription" : 1,
"updateSubscription" : 1,
"deleteSubscription" : 1,
"subscribe" : 1,
"unsubscribe" : 1,
"flushSubscribe" : 1,
"pauseSubscribe" : 1,
"resumeSubscribe" : 1
}
}
infos.context.permitted = permitted
}
if(!permitted[value.module]) {
this.writeValue(source.gateway_id + "¬%azure:out", {id : value.id, module : value.module, method : value.method, error : "invalid module"})
return
}
if(!permitted[value.module][value.method]){
this.writeValue(source.gateway_id + "¬%azure:out", {id : value.id, module : value.module, method : value.method, error : "invalid method"})
return
}
let apiGw = this.getGateway(dest.gateway_id)
if(apiGw.state != "connected"){
this.writeValue(source.gateway_id + "¬%azure:out", {id : value.id, module : value.module, method : value.method, error : "API driver not connected"})
return
}
if(value.method == "getSubscriptions"){
value.subscription = "sauter/"
}else if(value.method == "getSubscription" || value.method == "deleteSubscription"){
value.subscription = "sauter/" + value.subscription
}else if(value.method == "insertSubscription" || value.method == "updateSubscription" || value.method == "replaceSubscription"){
value.subscription.id = "sauter/" + value.subscription.id
}else if(value.method == "subscribe" || value.method == "unsubscribe" || value.method == "flushSubscribe" || value.method == "pauseSubscribe" || value.method == "resumeSubscribe"){
value.subscription = "sauter/" + (value.subscription[0] == "/" ? value.subscription.substring(1) : value.subscription)
if(!value.subscriber) value.subscriber = "sauter"
if(value.method == "subscribe"){
value.ack = "md5"
}
}
value.id = "sauter/" + (value.id || "")
return value
}
value,value,-1,%api/reply/sauter from the API gateway.["%azure:out","%azure:file_upload"]from the Azure gateway. The %azure:out address is used for normal messages, while the %azure:file_uploadis used for requests having the stream parameter (for big datasets such as the gateways getAddresses method reply).function apiToAzure(v, source,dest, infos){
// removes the "sauter/" prefixes from replies values for getSubscription(s).
if(v && v.id == "autoSubscribe" && v.method == "subscribe" && v.event != "flush"){
//do not send autoSubscribe errors or info to sauter cloud.
return
}
if(!infos.context.transform){
infos.context.transform = function(v){
if(v.value){
if(v.value.id && v.value.id.startsWith("sauter/")){
v.value.id = v.value.id.substring(7)
}else if(v.value.constructor.name == "Array"){
for(let subv of v.value){
if(subv.id && subv.id.startsWith && subv.id.startsWith("sauter/")){
subv.id = subv.id.substring(7)
}
}
}
}
if(v.subscription && v.subscription.startsWith && v.subscription.startsWith("sauter/")){
v.subscription = v.subscription.substring(7)
}
}
}
if(v.stream){
if(dest.name != "%azure:file_upload") return;
return { //stream object
name : "%api/stream/sauter",
gateway_id : source.gateway_id,
sourceOptions : {
"id" : v.id,
"transform" : infos.context.transform
},
destinationOptions : {
"name" : v.id, //
}
}
}else{
if(dest.name != "%azure:out") return;
infos.context.transform(v)
return v
}
}
value,value,-1,%azure:telemetry_out/body from the Azure gateway.none (no destination address).function subscribesAck(v,source,dest,infos){
// listens to azure telemetry out notifications to acknowledge the records using the md5 hash.
if(v.method == "subscribe"){
if(v.event == "flush"){
var loggers = this.loggers
var crypto = this.crypto
let md5 = crypto.createHash('md5').update(JSON.stringify(v.value)).digest("hex")
if(!infos.context.ackCallback){
infos.context.ackCallback = function(err){
if(err){
console.error("ACK callback error",err)
}
}
}
loggers.ackSubscribe({
subscription : "sauter/",
subscriber : "sauter",
ack : md5
},infos.context.ackCallback)
}
}
}
gateway status (see Routes),status,0,["gateway_api", "sauter_cloud_azure"]. Listens to both the API and Azure gateway statuses.nonefunction autoSubscribe(statusObj,source,dest,infos){
// 1. subscribes automatically to subscription ids starting with prefix "sauter/history/"
// 2. If the azure gateway disconnects pauses all "sauter/" subscriptions.
// Resumes the paused subscriptions when the azure gateway is online.
var gateways = this;
var status = statusObj.status
if(statusObj.name == "gateway_api"){
if(status == "connected"){
gateways.writeValue("%api/loggers/subscribe", {
id : "sauter/autoSubscribe",
ack : "md5",
subscriber : "sauter",
subscription : "sauter/history/" //all subscriptions whose id starts with sauter/history/..xyz..
},function(err){
if(err){
console.error("error at sauter subscribe",err)
}
})
}
}else { //azure has issues, needs to pause sauter subscribes
var context = infos.context
var loggers = this.loggers //in this case, use the API directly
if(status == "connected"){
if(!context.pausedSubscriptions) return // no pause were made before, so do nothing
let subs = Object.keys(context.pausedSubscriptions)
loggers.resumeSubscribe({
subscriber : "sauter",
subscription : subs
},function(err,res){
for(let sub of subs){
delete context.pausedSubscriptions[sub]
}
if(Object.keys(context.pausedSubscriptions).length == 0) delete context.pausedSubscriptions
})
}else{
loggers.pauseSubscribe({
subscriber : "sauter",
subscription : "sauter/"
},function(err,errorBySub){
let subs = Object.keys(errorBySub)
for(let sub of subs){
if(!errorBySub[sub]){ // null means no error
if(!context.pausedSubscriptions) context.pausedSubscriptions = {}
context.pausedSubscriptions[sub] = true
}
}
})
}
}
}
| Error | Cause |
|---|---|
address not found |
The request was written to an address that does not exist on the API gateway. |
read only |
%api/reply... and %api/stream... cannot be written. |
module not found |
module is missing or is not gateways / loggers. |
api method not found / missing api for that function |
The method does not exist or is not exposed by the API driver. |
missing parameter: <name> |
A mandatory parameter of the method is missing. |
parameter is not a number / string / object / array: <name> |
Wrong JSON type for that parameter. |
stream id conflict |
The stream request could not be registered under this id. Send it again with another id (for example a UUID). |
missing license (gateway log) |
The API driver licence is missing: the gateway does not reach the connected state. |
log property of an addressapi.jssauter_cloud_azure gateway of the examples is an Azure IoT Hub gateway, not a Sauter driver)