-
Notifications
You must be signed in to change notification settings - Fork 12
Skygear IoT Feature Spec
Akiroz edited this page Apr 3, 2017
·
15 revisions
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
deviceSecretprovided by the hardware - a
deviceIDafter registration - a
loginIDafter logging in (like a session ID)
const skygearIoT = require('skygear-iot');
skygearIoT.device.platform-
skygearIoT.device.deviceID(iot_device._idor null) -
skygearIoT.device.loginID(iot_device_login._idor null)
skygearIoT.device is read-only.
-
skygearIoT.initialize(platform)initializes SDK with a provided platform -
skygearIoT.registerDevice(user)register this device with provided user, adds roleiot-deviceto user -
skygearIoT.log(message, attachment)log to skygear portal (with optional object attachment) -
skygearIoT.reportStatus()report status to the skygear server -
skygearIoT.getDeviceChannelName()returns pubsub channel for this device
There are 2 Skygera IoT specific roles:
-
iot-devicecan write to theiot_*tables. -
iot-managercan read/writeiot_*tables and send messages to devices using a lambda.
-
iot_device(ACL: public no access)- _id (skygear user id)
- deviceSecret (string)
- class (string)
- active (bool, true unless the device has been de-registered)
-
iot_device_login(ACL: public no access)- device_id (FK:
iot_device._id) - sdk_version (string)
- app_version (string)
- device_id (FK:
-
iot_device_status(ACL: public no access)- device_id (FK:
iot_device._id) - login_id (FK:
iot_device_login._id) - status (online, offline)
- ip (string)
- device_id (FK:
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.
-
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". Some pre-defined actions are:iot-request-statusiot-shutdowniot-restart
{
action: "",
...
}
-
iot:add-device-roleadds the roleiot-deviceto the request user -
iot:device-publish(requires either master key ORiot-managerrole) publish messages to device's secure channels -
iot:loglogs message to the skygear portal
- Add pubsub subscribe once helper function