Sets the value of a property for a specified device.

setThingProperties(params, callback)

Parameter Type Description
params object The parameter object. For more information, see the table Parameter descriptions of params.
callback(err) function The callback function. The callback function must follow standard JavaScript practices.
  • If the call is successful, err is null.
  • If the call fails, err contains the error information.
Table 1. Parameter descriptions of params
Parameter Type Description
productKey String The key of the product to which the devices belong. It is a unique identifier issued by IoT Platform for the product.
deviceName String The name of the device. The device name is generated when the device is created.
payload Object

The property identifiers and the property values to be set.

Log on to the IoT Platform console. On the Define Feature tab of the product details page, click View TSL to view the identifier of each service.

Sample requests

The following example sets the LightSwitch property value of the LightDev2 device to 1. A value of 1 indicates the device is switched on.

'use strict';

const leSdk = require('linkedge-core-sdk');
const iotData = new leSdk.IoTData();

const setPropertiesParams = {
  productKey: 'a1ZJTVsqj2y', // Please replace it with your Product Key.
  deviceName: 'LightDev2',   // Please replace it with your Device Name.
  payload: {'LightSwitch': '1'} // The property defined in the Product TSL.
};
/* Promise wrapper for setThingProperties. */ 
function setThingProperties(params) {
  return new Promise((resolve, reject) => {
    iotData.setThingProperties(params, (err, data) => {
      err ? reject(err) : resolve(data);
    });
  });
}

exports.handler = function (event, context, callback) {
  setThingProperties(setPropertiesParams).then((data) => {
    console.log("-- Set Property Success. Return " + JSON.stringify(data));
    callback(null);
  }).catch((err) => {
    console.log(err);
    callback(err);
  });
};