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.
- JavaScript
- Python
app.events.stream(params)await app.events.stream(params)| Parameter | Type | Description |
|---|---|---|
name | string | The event name to subscribe to |
callback | function | Called with each incoming event payload |
Returns true if the subscription was created, false if already subscribed to that event name
- JavaScript
- Python
app.events.stream({
name: "door_opened",
callback: (data) => {
console.log("Door event:", data);
},
});
await app.events.stream({
"name": "door_opened",
"callback": lambda data: print("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.
- JavaScript
- Python
app.events.off(params)await app.events.off(params)| Parameter | Type | Description |
|---|---|---|
name | string | The event name to unsubscribe from |
- JavaScript
- Python
app.events.off({ name: "door_opened" });
await app.events.off({"name": "door_opened"})