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)
There are 2 Skygera IoT specific roles:
iot-device
can call device-specific lambdas.iot-manager
can read/writeiot_*
tables and send messages to devices using a lambda.
-
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)
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-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 theiot:device-publish
lambda. All actions prefixed withiot-
will be executed by the device platform (supplied by the deviceplatform.action
map). Some pre-defined actions are:iot-shutdown
iot-restart
{
action: "",
...
}
-
iot:add-device-role()
- Adds the role
iot-device
to the request user
- Adds the role
-
iot:report-status({deviceID: "", status: "online", metadata: {}})
(requiresiot-device
role)- Used by devices to report its current status
-
iot:device-publish([payload, deviceIDs])
(requires master key ORiot-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)
(requiresiot-device
role)- Logs message to the skygear portal
- message: string