Skip to end of metadata
Go to start of metadata

Scenario

  1. We have a remote "thermometer" thing with a float property "temperature"
  2. The "Temperature" property value is located on the remote device
  3. The device is to be connected to GadgetKeeper using the MQTT protocol
  4. It is possible to read a remote value (get) or write it (set) through the MQTT connection
  5. Since the "Temperature" property value is set to "Readonly", this value can be read but not set by GadgetKeeper

Prerequisites

  1. This example is based on the "thermometer" thing created in Create, Read, and Write Property scenario 
  2. 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"


  1. In the "Properties" section of "Thing: Thermometer", select the "temperature" property

  2. Click "Edit" to open the the "Edit Property" dialog

  3. Select "remote" as the new type for this property

  4. Check "Readonly" (value can be read by GK, but not set)

  5. Save property

2. Create MQTT connection to device


  1. In the "Thing: Thermometer" tab, open "Connections"

  2. Click "New" to open "Create Connection" dialog

  3. Set a name for the connection

  4. Set protocol to "json-rpc over messaging"

  5. Save the new connection parameters

Check out JSON-RPC over Messaging for configuration details.

3. Implement MQTT handler on device


  1. Obtain "thermometer" Thing Id by following instructions here.

  2. Connect your remote device to api.gadgetkeeper.com on port 1883.

  3. Subscribe to topic "thing.<THING_ID>" where THING_ID is the 32 digit character expression obtained in step 1.

  4. Set the remote device to listening mode for messages on the subscribed topic through port 1883.

  5. 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


  1. In the "Properties" section of "Thing: Thermometer", select "temperature"

  2. Click "Edit Value" to open "Property value" dialog

  3. The current "temperature" property value is automatically retrieved

  4. Click the "Get" button to update this value with the latest value stored on the "thermometer" device

5. Get property value using REST API


  1. 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
  2. Obtain required parameters

    • To obtain the Thing Id, see instructions here.

    • Obtain "temperature" property Id. See instructions here.

    • To create an API Key, see instructions here.

      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:

      

 

 

 

 

 

 

  • No labels