-
Notifications
You must be signed in to change notification settings - Fork 0
notifications.md
The dashboard provides a special secure Websocket endpoint
wss://dash.mongoose-os.com/api/v2/notify
. This is a read-only notifications endpoint.
Each notification is a JSON object with three keys:
-
name
: notification name, e.g. "online", "offline", "rpc.in.GetInfo", "rpc.out.Log" -
id
: an ID of a device that generated the event -
data
: optional notification-specific data.
The online
and offline
events are generated by the dashboard. The
rpc.out.*
events are generated by the device: these are JSON-RPC requests
without an ID (notifications). For example, dash
library forwards all
device logs to the dashboard as Log
RPC calls, thus generating rpc.out.Log
events.
RPC call to the device generate rpc.in.*
events.
The dashboard UI uses /api/v2/notify
endpoint in order to catch state changes.
Login to the dashboard and open the developer tools / network / WS panel to
see it in action.
You can implement your own service that attaches to the /api/v2/notify
,
for example in Node JS (don't forget to substitute API_TOKEN with your real
API access token):
const Websocket = require('ws');
const addr = 'wss://dash.mongoose-os.com/api/v2/notify?access_token=API_TOKEN';
const ws = new Websocket(addr, { origin: addr });
ws.on('message', msg => console.log('Got message:', msg.toString()));
To see your mDash API tokens, login to mDash and click on "Keys" tab:
The API is documented at mDash API. Below are quick examples.
In C/C++:
mgos_dash_notifyf("MyStat", "{temperature: %f}", 12.34);
In JavaScript:
Dash.notify('MyStat', {temperature: 12.34});
Note that the format of data is arbitrary - it could be anything: a number,
a string, an array, or a complex nested object. It's up to you. In this
example, a simple object {"temperature": 12.34}
is used. The
example generates the following notification:
{
"id": "DEVICE_ID", // This is the device ID that generated notification
"name": "rpc.out.MyStat", // "rpc.out.EVENT_NAME", in our case rpc.out.MyStat
"data": {"temperature": 12.34} // Your event payload - arbitrary
}
Further possible actions:
- Catch this notification (see section above) and do your custom action
- Modify the PWA mobile app, which catches all notifications, and show the data somehow to the user
- Save the data automatically to the database, and graph it. See Data Storage section
ADS1X1X I2C ADS7843/XPT2046 SPI APDS9960 I2C ATCA BH1730 sensor BME280/BMP280 BQ27421 Barometers Bosch BM222 CCS811 I2C DHT DS3231 I2C Dallas RMT ESP32 touch sensor HTU21D(F) I2C ILI9341 SPI IMU INA219 I2C INA226 I2C INA3221 I2C Inventek ISM43xxx WiFi MAX7219 I2C MAX72xx LED matrix MCP23XXX I2C MCP9808 I2C MQ135 gas sensor Neopixel Onewire RMT PCF857X I2C SHT31 I2C SSD1306 OLED STMPE610 SPI Si7005 sensor Si7021 I2C TI TMP006 temp sensor VEML6075 I2C VFS (LittleFS) VFS (RAM) VFS (SPI NOR Flash) VFS (SPIFFS) VFS (Winbond W25XXX) VFS (another device) VFS (encryption) VFS bh1750 I2C
RPC core RPC loopback RPC over BLE GATT RPC over MQTT RPC over UART RPC over UDP Service - ATCA Service - Config Service - Cron Service - FS Service - GATT client Service - GPIO Service - I2C Service - OTA Service - WiFi