GadgetKeeper and Thing exchange messages using an use external MQTT broker :to exchange messages.
(GadgetKeeper sends
request, device responds)
Device () (publishes) Device Device (publishes)
How it works:
(Device sends request,
GadgetKeeper responds)
- GadgetKeeper subscribes to a request topic on MQTT message broker
- Device (Thing) subscribes to the response topic on MQTT message broker
- Device sends (publishes) a command to the request topic
- GadgetKeeper receives command from the request topic
- GadgetKeeper sends (publishes) a response to the response topic
- Device receives the response
- GadgetKeeper disconnects from MQTT message broker
Communication Protocols: | MQTT | |||||
---|---|---|---|---|---|---|
RPC Protocol: | JSON-RPC 2.0 | |||||
How it works: |
|
|
|
|
|
|
Constraints: |
|
Connection Settings
...
Field | Required | Description | Dialog |
---|---|---|---|
Name | x | Connection connection name | |
Protocol | x | Select select "json-rpc over mqtt" | |
Host | x | MQTT broker host | |
Port | x | MQTT broker port | |
Secure | When checked, the connection uses use MQTTS | ||
Request topic | x | Topic topic to send a command | |
Response topic | x | Topic topic to receive a response | |
Connection, ms | x |
Number number of milliseconds GadgetKeeper can spend spent on connection to MQTT broker |
|
Response, ms | x |
Number number of milliseconds GadgetKeeper will wait for Thing to receive message and send response |
|
Date format | x |
Date date format representation:
|
|
Description | Connection connection description |
Example
...
Scenario Using MQTT
Info |
---|
See Message Format for detailed instructions on how to format a request/response message using the JSON-RPC 2.0 protocol |
Device (thing) responds to a request from GadgetKeeper:
...
Given
- Thing has remote method "echo"
- Thing will want to be set up able to execute handle this method in response to a command from GadgetKeeper
Workflow
- Thing establishes MQTT connection to the specified MQTT Broker server
- Thing subscribes to the specified request topic
- GadgetKeeper subscribes to the specified response topic
-
GadgetKeeper sends (publishes) a JSON-RPC request message to the request topic:
Code Block language javascript { "jsonrpc":"2.0", "method":"echo", "params":"hello world!", "id":990909000 }
-
Thing receives the JSON request message and sends (publishes) send a response back to the response topic:
Code Block { "jsonrpc":"2.0", "result":"hello world!", "id":990909000 }
-
GadgetKeeper receives the response and disconnects from MQTT broker
...
Workflow
...
...
Code Block | ||
---|---|---|
|
||
{
"jsonrpc":"2.0",
"id":"7755",
"method":"things.methods.execute",
"params": {
"thingId":"990fc000c90211e2b5566c626dd90e00",
"methodId":"99614181155811e4abd06c626dd90e00",
"async":true,
"args":"hello world!"
}
}
|
...
GadgetKeeper receives the JSON request message and sends (publishes) a response back to the response topic:
Code Block |
---|
{
"jsonrpc":"2.0",
"id":"7755",
"result":"hello world!"
}
|
...
Thing receives the response and disconnects from MQTT broker
Info |
---|
See Messaging with External MQTT Broker for more information on how to set up and use an external MQTT broker |