Skip to main content

Events

Subscribe to discrete events published by devices in real time. Events are user-defined moments like "door opened", "boot complete", or "geofence entered" — see the Device SDK Event module for the publishing side.

Access via app.events.

API

stream()

Subscribe to events by name.

app.events.stream(params)
ParameterTypeDescription
namestringThe event name to subscribe to
callbackfunctionCalled with each incoming event payload

Returns true if the subscription was created, false if already subscribed to that event name

app.events.stream({
name: "door_opened",
callback: (data) => {
console.log("Door event:", data);
},
});

The callback receives an object with value (the payload the device sent via device.event.send()) and timestamp (a Unix timestamp of when the event was published).

Example callback data:

{
"value": {
"door": "front",
"method": "keycard"
},
"timestamp": 1743292800000
}
{
"value": {
"zone": "warehouse-A",
"lat": 40.7128,
"lng": -74.006
},
"timestamp": 1743292860000
}

off()

Unsubscribe from an event.

app.events.off(params)
ParameterTypeDescription
namestringThe event name to unsubscribe from
app.events.off({ name: "door_opened" });

history()

Query historical events for a device over a time range.

await app.events.history(params)
ParameterTypeDescription
device_identstringThe device identifier
event_namesstring[]Event names to query
startstringStart time (ISO 8601, UTC)
endstringEnd time (ISO 8601, UTC)

Returns an object keyed by event name, each containing an array of entries.

const events = await app.events.history({
device_ident: "sensor_01",
event_names: ["door_opened", "door_closed"],
start: "2026-01-01T00:00:00.000Z",
end: "2026-01-08T00:00:00.000Z",
});

events.door_opened.forEach((entry) => {
console.log(`${entry.timestamp}:`, entry.value);
});

Example response:

{
"door_opened": [
{ "value": { "door": "front", "method": "keycard" }, "timestamp": 1774690200000 },
{ "value": { "door": "front", "method": "keycard" }, "timestamp": 1774690800000 }
],
"door_closed": [
{ "value": { "door": "front" }, "timestamp": 1774690260000 }
]
}

Event names you requested but that have no data in the range are still included as empty arrays.

History retention

History retention depends on your plan. Queries outside your retention window will return empty arrays.