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
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.
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:
![]() | 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. |
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>
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
<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>