thincloud.h
IoT_Error_t commissioning_request(char *buffer, const char *requestId, const char *deviceType, const char *physicalId, char **relatedDeviceIds, uint32_t idsSize)
{
    if (deviceType == NULL || physicalId == NULL)
    {
        FUNC_EXIT_RC(NULL_VALUE_ERROR);
    }

    json_object *obj = json_object_new_object();
    if (requestId != NULL)
    {
        json_object *value = json_object_new_string(requestId);
        json_object_object_add(obj, "id", value);
    }

    json_object *method = json_object_new_string("commission");
    json_object_object_add(obj, "method", method);

    json_object *params = json_object_new_array();
    json_object *data = json_object_new_object();
    json_object *dataObj = json_object_new_object();

    json_object *deviceTypeValue = json_object_new_string(deviceType);
    json_object *physicalIdValue = json_object_new_string(physicalId);
    json_object_object_add(data, "deviceType", deviceTypeValue);
    json_object_object_add(data, "physicalId", physicalIdValue);

    if (relatedDeviceIds != NULL && idsSize > 0)
    {
        json_object *relatedDevices = json_object_new_array();
        for (uint32_t i = 0; i < idsSize; i++)
        {
            const char *id = relatedDeviceIds[i];
            if (id == NULL || strlen(id) <= 0)
            {
                continue;
            }

            json_object *deviceId = json_object_new_string(id);
            json_object *deviceIdObj = json_object_new_object();
            json_object_object_add(deviceIdObj, "deviceId", deviceId);
            json_object_array_add(relatedDevices, deviceIdObj);
        }

        json_object_object_add(data, "relatedDevices", relatedDevices);
    }

    json_object_object_add(dataObj, "data", data);
    json_object_array_add(params, dataObj);

    json_object_object_add(obj, "params", params);

    const char *str = json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN);

    strcpy(buffer, str);

    json_object_put(obj);

    FUNC_EXIT_RC(SUCCESS);
}
/**
 * @brief Build a commissioning request
 * 
 * Construct a commissioning request.
 * 
 * @param[out] buffer           Pointer to a string buffer to write to 
 * @param[in]  requestId        Unique ID for the request
 * @param[in]  deviceType       Requesting device's type
 * @param[in]  physicalId       Device's physical ID
 * @param[in]  relatedDeviceIds List of devices to associate on commissioning
 * @param[in]  idsSize          Size of related device ids list 
 * 
 * @return Zero on success, negative value otherwise 
 */
@brief Build a commissioning request

Construct a commissioning request.



@return Zero on success, negative value otherwise
@brief Build a commissioning request Construct a commissioning request . @return Zero on success negative value otherwise
IoT_Error_t commissioning_request(char *buffer, const char *requestId, const char *deviceType, const char *physicalId, char **relatedDeviceIds, uint32_t idsSize)
{
    if (deviceType == NULL || physicalId == NULL)
    {
        FUNC_EXIT_RC(NULL_VALUE_ERROR);
    }
    json_object *obj = json_object_new_object();
    if (requestId != NULL)
    {
        json_object *value = json_object_new_string(requestId);
        json_object_object_add(obj, "id", value);
    }
    json_object *method = json_object_new_string("commission");
    json_object_object_add(obj, "method", method);
    json_object *params = json_object_new_array();
    json_object *data = json_object_new_object();
    json_object *dataObj = json_object_new_object();
    json_object *deviceTypeValue = json_object_new_string(deviceType);
    json_object *physicalIdValue = json_object_new_string(physicalId);
    json_object_object_add(data, "deviceType", deviceTypeValue);
    json_object_object_add(data, "physicalId", physicalIdValue);
    if (relatedDeviceIds != NULL && idsSize > 0)
    {
        json_object *relatedDevices = json_object_new_array();
        for (uint32_t i = 0; i < idsSize; i++)
        {
            const char *id = relatedDeviceIds[i];
            if (id == NULL || strlen(id) <= 0)
            {
                continue;
            }
            json_object *deviceId = json_object_new_string(id);
            json_object *deviceIdObj = json_object_new_object();
            json_object_object_add(deviceIdObj, "deviceId", deviceId);
            json_object_array_add(relatedDevices, deviceIdObj);
        }
        json_object_object_add(data, "relatedDevices", relatedDevices);
    }
    json_object_object_add(dataObj, "data", data);
    json_object_array_add(params, dataObj);
    json_object_object_add(obj, "params", params);
    const char *str = json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN);
    strcpy(buffer, str);
    json_object_put(obj);
    FUNC_EXIT_RC(SUCCESS);
}
IoT_Error_t commissioning_request ( char * buffer , const char * requestId , const char * deviceType , const char * physicalId , char * * relatedDeviceIds , uint32_t idsSize ) { if ( deviceType == NULL || physicalId == NULL ) { FUNC_EXIT_RC ( NULL_VALUE_ERROR ) ; } json_object * obj = json_object_new_object ( ) ; if ( requestId != NULL ) { json_object * value = json_object_new_string ( requestId ) ; json_object_object_add ( obj , " " , value ) ; } json_object * method = json_object_new_string ( " " ) ; json_object_object_add ( obj , " " , method ) ; json_object * params = json_object_new_array ( ) ; json_object * data = json_object_new_object ( ) ; json_object * dataObj = json_object_new_object ( ) ; json_object * deviceTypeValue = json_object_new_string ( deviceType ) ; json_object * physicalIdValue = json_object_new_string ( physicalId ) ; json_object_object_add ( data , " " , deviceTypeValue ) ; json_object_object_add ( data , " " , physicalIdValue ) ; if ( relatedDeviceIds != NULL && idsSize > 0 ) { json_object * relatedDevices = json_object_new_array ( ) ; for ( uint32_t i = 0 ; i < idsSize ; i ++ ) { const char * id = relatedDeviceIds [ i ] ; if ( id == NULL || strlen ( id ) <= 0 ) { continue ; } json_object * deviceId = json_object_new_string ( id ) ; json_object * deviceIdObj = json_object_new_object ( ) ; json_object_object_add ( deviceIdObj , " " , deviceId ) ; json_object_array_add ( relatedDevices , deviceIdObj ) ; } json_object_object_add ( data , " " , relatedDevices ) ; } json_object_object_add ( dataObj , " " , data ) ; json_object_array_add ( params , dataObj ) ; json_object_object_add ( obj , " " , params ) ; const char * str = json_object_to_json_string_ext ( obj , JSON_C_TO_STRING_PLAIN ) ; strcpy ( buffer , str ) ; json_object_put ( obj ) ; FUNC_EXIT_RC ( SUCCESS ) ; }
@brief Build a commissioning request
@brief Build a commissioning request