Data Services

Data services is an optional feature that is used to send data to and from Device Cloud. Data service transfers are either initiated from Device Cloud (Device Request) or the device itself (Send data).

send_data and device_request examples are ready to use for both the TWR-K60N512 and TWRK53N512 towers showing this functionality.

To enable this feature on other examples it is necessary to define the following macro in the connector_config.h file:

#define CONNECTOR_DATA_SERVICE

Sending data to Device Cloud

The send data sample demonstrates how to send data from a device to Device Cloud. Using the connector_send_data() function, this application writes data to a file on Device Cloud.

The 'send data' sample was described in Creating your first application from an example. Please review this section to learn how to run and test the example.

Process a device request from Device Cloud

The device request sample demonstrates how to process data sent from Device Cloud. Using the connector_register_device_request_callbacks() function to register a custom callback, this application allows you to turn the TWR board's LEDs (LED1 or LED2) ON or OFF.

To process a sample device request:

  1. Log in to your Device Cloud account. Once logged in, select the API Explorer menu from within the Documentation tab.
  2. Click the SCI Targets button in the toolbar.
  3. Clicking this button will bring up the Select devices to be used in examples dialog box. Within this box you will select the target device that you would like to send requests to.
  4. Click the Add Targets drop-down menu and choose the Device ID that corresponds to your device. Click the Add button and then click OK to exit the dialog.
    Warning If you do not know your device’s Device ID you can locate it by navigating to the Devices page and locating your device in the list. The device’s Device ID is displayed within the Device ID column.
  5. Within the API Explorer toolbar click on the Examples drop-down menu then select SCI > Data Service > Send Request. Once you have selected an example, source code for the selected example as well as the HTTP method that will be used is displayed. In order for you to turn LED1 or LED2 ON or OFF you will need to modify this example text slightly.
  6. Replace the target with "LED1" or "LED2" and the payload with ON or OFF as needed. For example, to turn ON LED1 the request should be:

    <sci_request version="1.0">
           <data_service>
               <targets>
                   <device id="00000000-00000000-XXXXXXFF-FFXXXXXX"/>
               </targets>
               <requests>
                   <device_request target_name="LED1">
                       ON
                   </device_request>
               </requests>
            </data_service>
        </sci_request>

  7. Click the Send button to send this request to Device Cloud. You should see the following in the console output on the terminal window for the received request:

    Turning ON LED1
    LED1 action is Success

  8. Observe the output displayed within the Web Services Responses panel on the right side of the page. Click on the response text to view the entire response from the device. You should see something similar to the following:

        <sci_reply version="1.0">
            <data_service>
                <device id="00000000-00000000-XXXXXXFF-FFXXXXXX">
                    <requests>
                        <device_request target_name="LED1" status="1">Success</device_request>
                    </requests>
                </device>
            </data_service>
        </sci_reply>