Skip to main content
Version: 2.3.x

MQTT Client

Remote API Invocation

Setting Up the MQTT Client

remote-api

Example - Generating a Request From a Remote Client

$ mosquitto_pub -h 10.144.8.139 \
-t '/devices/1/request' \
-m '{"path":"/device/general","method":"GET","headers":[{"request-expired-time":"2020-11-12 11:45:26"},{"request-id":"1"}],"requestBody":{"enable":true,"port":22}}'
  • path: API path (don't need prefix /api/v1)
  • method: API method
  • headers: API headers
    • required headers:
      • request-expired-time: UTC, format: 2020-11-12 11:45:26
      • request-id: integer string
  • requestBody: API request body, json object

Example - Receiving a Response

$ mosquitto_sub -h 10.144.8.139 -t '/devices/1/response' -v

/devices/1/response
{
"request-id": "1",
"state": 200,
"payload": {"data":{"type":"general","description":"1","hostName":"Moxa","modelName":"UC-8100A-ME-T-LX","deviceType":"gateway","serialNumber":"TAICB1046773","firmwareVersion":"1.3.1","thingsproVersion":"1.1.0-594","cpu":"ARMv7Processorrev2(v7l)","memorySize":1055838208,"disk":[{"name":"System","mount":"/","device":"/dev/root","total":6827344896,"free":4880628736,"used":1659873280,"percent":25.37837731628948,"tags":{"used":"systemDiskUsed","free":"systemDiskFree","percent":"systemDiskPercent"}}],"lastBootTime":"2019-12-20T11:31:20+08:00"}}
}

Response to an Invalid Request

$ mosquitto_sub -h 10.144.8.139 -t '/devices/1/response' -v

/devices/1/response
{
"request-id": 1,
"payload": {
"error": {
"code": 404,
"message": "page not found"
}
},
"state": 404
}

Response to a Request With Invalid Headers

$ mosquitto_sub -h 10.144.8.139 -t '/devices/1/response' -v

/devices/1/response
{
"request-id": -1,
"payload": {
"code": 400,
"message": "request time invalid(before now)"
},
"state": 400
}

Last updated on 2022-07-22 by Cecilia Fernandes