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" });