GithubHelp home page GithubHelp logo

iot's Introduction

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

iot's People

Contributors

akiroz avatar cheungpat avatar steven-chan avatar

Watchers

James Cloos avatar Ramy Khalil avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.