mDash device management

mDash is a cloud backend for connected products. Its main purpose to provide remote firmware update, remote device control, and health monitor. It is supposed to be used together with a product-specific cloud service.

mDash is available as a managed service at https://mdash.net, as well as private on-premises installation.

How to enable mDash

Assuming Mongoose is already integrated in your firmware (if not, follow the Integration Guide),

Step 1. Login to https://mdash.net, create a device and copy the device password in the clipboard:

Step 2. Edit mongoose_config.h, enable mDash and set the password:

#define MG_ENABLE_MDASH 1
#define MG_MDASH_KEY "..."           // Paste the copied password here
#define MG_FIRMWARE_VERSION "1.0.0"
#define MG_TLS MG_TLS_BUILTIN

Step 3. Rebuild and reflash

How to perform firmware OTA update

Step 1. Rebuild your firmware .bin file

Step 2. Use Web UI on https://mdash.net to update: click on the "download" button, and select the .bin file:

Alternatively, use can use automation or curl. Get your API key from https://mdash.net/#/keys, then run this command:

curl -su :MDASH_API_KEY -F file=@FIRMWARE.BIN https://mdash.net/api/v2/devices/DEVICE_ID/ota

How to implement device control

The device connects to mDash using secure Websocket link, where it exchanges JSON-RPC frames. There are several built-in JSON-RPC functions implemented by the mDash connector inside Mongoose, but it is possible to add any number of custom JSON-RPC functions. mDash bridges all JSON-RPC requests automatically to HTTP REST.

Let's demonstrate that by implementing a function that lets us read and write any pin remotely. Add that to your main.c:

static void mg_rpc_sys_pin(struct mg_rpc_req *r) {
  int pin = (int) mg_json_get_long(r->frame, "$.params.pin", -1);
  int val = (int) mg_json_get_long(r->frame, "$.params.val", -1);
  if (pin >=0 && val >= 0) {
    hal_gpio_write(pin, val);  // Both pin and val are set: write pin
    mg_rpc_ok(r, "true");
  } else if (pin >= 0) {
    mg_rpc_ok(r, "%d", hal_gpio_read(pin)); // Only pin is set: read pin
  } else {
    mg_rpc_err(r, 500, "%m", MG_ESC("set pin and val"));
  }
}
  // Add after mg_mgr_init():
  mg_rpc_add(&mgr.rpcs, mg_str("Sys.Pin"), mg_rpc_sys_pin, NULL);

Rebuild and reflash. Then you can call your RPC:

curl -su :$MDASH_API_KEY https://mdash.net/api/v2/devices/device1/rpc/Sys.Pin -d '{"pin": 0}'
curl -su :$MDASH_API_KEY https://mdash.net/api/v2/devices/device1/rpc/Sys.Pin -d '{"pin": 0, "val": 0}'

To get a list of all RPCs,

curl -su :$MDASH_API_KEY https://mdash.net/api/v2/devices/device1/rpc/RPC.List

See also: JSON-RPC reference.

How to enable Health Monitor

In your mongoose_config.h, enable health monitor:

#define MG_ENABLE_HEALTH 1

Rebuild and reflash. Now, if you're using mdash, you'll get crash backtrace in case if your device crashes.