-
Notifications
You must be signed in to change notification settings - Fork 10
MQTT
Main purpose of MQTT in THiNX is the Device Status. It does not work without that (shows only last connected time).
Secondary purposes are: firmware update (multi-file+ott), actionable notifications and generic messaging.
-
Authentication
-
Channels
-
Status Channel
-
Device Channel
-
-
Notifications
-
Status Notifications
-
Device Registration
-
Actionable Notifications
-
-
Streamed Firmware Updates
- Stream Client connection requirements
-
On QoS
THiNX server enables the authentication on MQTT on device registration.
Client devices must authenticate to the MQTT broker at thinx.cloud
on ports 1883
and 8883
using their owner_id
and api_key
used on registration as MQTT as username/password.
There are two designated channels:
/owner_id/udid/status - for status (connected/disconnected/registration) messages
Device SHOULD send status notifications and registration data to this channel in order to aquire possible firmware update.
Status channels take all the heavy annoying high-speed traffic.
/owner_id/udid - for user communication with device
The device channel is used for human communication to the device (e.g. respond to Actionable Notifications).
/owner_id/shared - for user communication between devices of same owner
The device channel is used for machine-to-machine communication between devices of same owner, because devices otherwise do not have access to others’ channels.
Device SHOULD send following messages to this channel:
{ "status": "connected" }
{ "status": "disconnected" } (as MQTT Last Will)
Device CAN send following message to this channel in order to aquire possible firmware update:
{ "registration":
{ "mac":"5CCF7FE4631D",
"firmware":"thinx-firmware-esp8266-1.7.24:2017-07-25",
"version":"1.7.24",
"commit":"24e715f7fb5dc3ebe228165dae45fa933fade1bd",
"owner":"cedc16bb6bb06daaa3ff6d30666d91aacd6e3efbf9abbc151b4dcade59af7c12",
"alias":"robotdyn-mega+wifi",
"platform":"platformio"
}
}
In case the 'commit' parameter is omitted, version will be used for matching. The 'alias' parameter can be ommitted as well, because it's only informative and not processed in any way.
The backend may reply with either OK
or UPDATE_AVAILABLE
response types.
In case the device has THINX_AUTO_UPDATE
disabled, it MUST ask user for consent before upgrading. This is done through Actionable Notifications sent to device channel.
Actionable notification declares response_type
of bool
or string
and the notification may not be responded to at all. MQTT messages are forwarded using WebSocket to the RTM console so user can see what happens and can react.
Each notification has a corellation-id called nid
which is currently based on udid and therefore each device can hold only one pending transaction. Can be easily extended to UDID in future.
- Device finds out it has update available
- Device sends actionable notification in following format:
{
notification: {
udid: "41528570-6965-11e7-9b6d-6924bbc83a7c",
nid: "nid:12345A",
title: "Firmware update available",
body: "Do you want to update your device now?",
type: "action",
response_type: "bool"
}
}
- The transaction is kept in Redis, notification is extended with UDID and NID in Messenger.js and forwarded to web interface using websocket.
{
notification: {
udid: "41528570-6965-11e7-9b6d-6924bbc83a7c",
nid: "nid:12345A",
title: "Firmware update available",
body: "Do you want to update your device now?",
type: "action",
response_type: "bool"
response: true
done: true
}
}
-
User responds to notification using Yes/No buttons (or string in future) and the reply to notification is sent using API call to the MQTT queue and forwarded using Messenger back to the device and stored to Redis.
-
In case the request reply is true, device can commence the firmware update now.
On future roadmap.
- Status Notifications should be sent from device with QoS 0 and use the RETAIN feature
- Actionable Notifications should be send/replied to with QoS 2 (Retain is questionable here, must be unretained from device side after action is done)