Skip to content

SkygearIO/iot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IoT Plugin for Skygear

NodeJS SDK

Source

API Doc

Devices

Each IoT device must provide a platform interface object to the SDK:

{
  action: { // platform specific action, all optional.
    shutdown: async function() {}
    restart: async function() {}
  },
  // return a string that is unique to the hardware
  // could be SoC model + serial number
  deviceSecret: string
  appVersion: string
}

Each device has:

  • a deviceSecret provided by the hardware
  • a deviceID after registration
  • a loginID after logging in (like a session ID)

Users and Roles

There are 2 Skygera IoT specific roles:

  • iot-device can call device-specific lambdas.
  • iot-manager can read/write iot_* tables and send messages to devices using a lambda.

Database Schema

  • iot_device (ACL: public = no, iot-manager/device = rw)

    • _id (skygear user id)
    • secret (string)
    • class (string)
    • login (FK: iot_device_login._id)
    • status (FK: iot_device_status._id)
    • active (bool, true unless the device has been de-registered)
  • iot_device_login (ACL: public = no, iot-manager/device = rw)

    • deviceID (string)
    • sdkVersion (string)
    • appVersion (string)
  • iot_device_status (ACL: public = no, iot-manager/device = rw)

    • deviceID (string)
    • status (online, offline)
    • metadata (JSON)

Determining Device Status

A device is online iff the latest iot_device_status record is created within X minutes of the current time AND the status field is online.

PubSub

  • iot-request-status A channel for the server to globally request status reports from all devices subscribing to it.

  • iot-<SHA256(deviceSecret)> A secure channel for the server to send messages to a device, payload must be an object with atleast 1 key: "action". Users should use these channels via the iot:device-publish lambda. All actions prefixed with iot- will be executed by the device platform (supplied by the device platform.action map). Some pre-defined actions are:

    • iot-shutdown
    • iot-restart
{
  action: "",
  ...
}

Lambda

  • iot:add-device-role()

    • Adds the role iot-device to the request user
  • iot:report-status({deviceID: "", status: "online", metadata: {}}) (requires iot-device role)

    • Used by devices to report its current status
  • iot:device-publish([payload, deviceIDs]) (requires master key OR iot-manager role)

    • Publish messages to devices' secure channels, payloads must be an object with at least an "action" key.
    • payload: object, (see iot-<SHA256(deviceSecret)> channel above)
    • deviceIDs: array of device ID
  • iot:log(message) (requires iot-device role)

    • Logs message to the skygear portal
    • message: string

Releases

No releases published

Packages

No packages published