MQTT API ‐ Invocation - CassiaNetworks/CassiaSDKGuide GitHub Wiki
API Invocation
Invoke HTTP RESTful API via MQTT:
- Request messages are described using
method
, url
, and body
fields for the HTTP RESTful API request.
- Response messages are described using
code
and body
fields for the HTTP RESTful API response.
- Both request and response messages use the
id
field for correlation.
Interaction Flow
sequenceDiagram
participant Server as User Application Service
participant MQTT as User MQTT Server
participant Gateway as Cassia Bluetooth Gateway
participant Device as User BLE Device
rect rgba(136, 177, 234,0.4)
Server --) Gateway: API Request
Gateway --) Gateway: Request Processing
opt
rect rgba(136, 177, 234,0.4)
note over Gateway,Device: BLE Interaction
Gateway --) Device: BLE Request
Device -) Device: BLE Request Processing
Device --) Gateway: BLE Response
Gateway --) Gateway: Response Processing
end
end
Gateway --) Server: API Response
end
API Request
Request Message
{
"id": "35656",
"action": "api",
"timestamp": 1678698297028,
"gateway": "CC:1B:E0:E2:8F:2C",
"data": {
"url": "/gap/nodes/D8:0B:CB:62:5C:2B/connection?",
"method": "POST",
"body": {}
}
}
Field Descriptions
Field |
Field |
Type |
Required |
Default |
Description |
id |
|
string |
Yes |
- |
Message ID, unique identifier, response message ID consistent with request |
action |
|
string |
Yes |
- |
Message type distinction |
timestamp |
|
uint32 |
Yes |
- |
Timestamp in milliseconds |
gateway |
|
string |
Yes |
- |
Gateway MAC address |
data |
|
object |
Yes |
- |
Message payload |
|
url |
string |
Yes |
- |
HTTP API URL, including options and query parameters |
|
method |
string |
Yes |
- |
HTTP API method |
|
body |
object/array |
Yes |
- |
HTTP API body |
API Response
Topic |
Action |
up/{gateway}/api_reply |
api_reply |
Response Message
{
"id": "35656",
"action": "api_reply",
"timestamp": 1678698297028,
"gateway": "CC:1B:E0:E2:8F:2C",
"data": {
"code": 200,
"body": {}
}
}
Field Descriptions
Field |
Field |
Type |
Required |
Default |
Description |
id |
|
string |
Yes |
- |
Message ID, unique identifier, response message ID consistent with request |
action |
|
string |
Yes |
- |
Message type |
timestamp |
|
uint32 |
Yes |
- |
Timestamp in milliseconds |
gateway |
|
string |
Yes |
- |
Gateway MAC address |
data |
|
object |
Yes |
- |
Message payload |
|
code |
uint32 |
Yes |
- |
HTTP status code |
|
body |
object/array |
Yes |
- |
HTTP API response body |