Scenario:
- We have a remote "thermometer" thing with a float property "temperature"
- The "Temperature" property value is located on the remote device
- The device is to be connected to GadgetKeeper using the MQTT protocol
- It is possible to read a remote value (get) or write it (set) through the MQTT connection
- Since the "Temperature" property value is set to "Readonly", this value can be read but not set by GadgetKeeper
Prerequisites:
- This example is based on the "thermometer" thing created in Create, Read, and Write Property scenario
- The "temperature" property must be implemented and managed by firmware on the remote device itself.
Steps:
For a complete description of all the settings used for the dialog boxes in this tutorial, see Thing Property Settings and Thing Connection Settings.
1. Set "temperature" property as "remote"
-
In the "Properties" section of "Thing: Thermometer", select the "temperature" property
-
Click "Edit" to open the the "Edit Property" dialog
-
Select "remote" as the new type for this property
-
Check "Readonly" (value can be read by GK, but not set)
-
Save property
2. Create MQTT connection to device
-
In the "Thing: Thermometer" tab, open "Connections"
-
Click "New" to open "Create Connection" dialog
-
Set a name for the connection
-
Set protocol to "json-rpc over messaging"
-
Save the new connection parameters
Check out JSON-RPC over Messaging for configuration details.
Refer to hardware specific examples for more details
3. Implement MQTT handler on device
-
Obtain "thermometer" Thing Id by following instructions here.
-
Connect your remote device to api.gadgetkeeper.com on port 1883.
-
Subscribe to topic "thing.<THING_ID>" where THING_ID is the 32 digit character expression obtained in step 1.
-
Set the remote device to listening mode for messages on the subscribed topic through port 1883.
-
In order to get an updated temperature value from the remote device, GadgetKeeper sends the following request in JSON-RPC message format:
The remote device receives this request through the topic listener, and replies with <TEMPERATURE> as "result" and the same "id" as provided in request:
Check out JSON-RPC over Messaging for details.
4. Get property value using UI
-
In the "Properties" section of "Thing: Thermometer", select "temperature"
-
Click "Edit Value" to open "Property value" dialog
-
The current "temperature" property value is automatically retrieved
-
Click the "Get" button to update this value with the latest value stored on the "thermometer" device
5. Get property value using REST API
- Check out the GadgetKeeper API - Thing Properties page for details on how to perform basic method operations on GadgetKeeper API using cURL or a REST API tool
-
Obtain required parameters
4. Use API Explorer to perform REST calls using UI
5. Use cURL to perform REST calls using command lines:
To get the remote "temperature" property value: