AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_pnp.c
static VOID sample_send_target_temperature_report(SAMPLE_CONTEXT *context, double current_device_temp_value,
                                                  UINT status, UINT version, UCHAR *description_ptr,
                                                  UINT description_len)
{
NX_AZURE_IOT_JSON_WRITER json_builder;
UINT bytes_copied;
UINT response_status;
UINT request_id;
ULONG reported_property_version;

    if (nx_azure_iot_json_writer_with_buffer_init(&json_builder, scratch_buffer, sizeof(scratch_buffer)))
    {
        printf("Failed to build reported response\r\n");
        return;
    }

    if (nx_azure_iot_json_writer_append_begin_object(&json_builder) ||
        nx_azure_iot_json_writer_append_property_name(&json_builder,
                                                      (UCHAR *)reported_temp_property_name,
                                                      sizeof(reported_temp_property_name) - 1) ||
        nx_azure_iot_json_writer_append_begin_object(&json_builder) ||
        nx_azure_iot_json_writer_append_property_with_double_value(&json_builder,
                                                                   (UCHAR *)reported_value_property_name,
                                                                   sizeof(reported_value_property_name) - 1,
                                                                   current_device_temp_value, DOUBLE_DECIMAL_PLACE_DIGITS) ||
        nx_azure_iot_json_writer_append_property_with_int32_value(&json_builder,
                                                                  (UCHAR *)reported_status_property_name,
                                                                  sizeof(reported_status_property_name) - 1,
                                                                  (int32_t)status) ||
        nx_azure_iot_json_writer_append_property_with_int32_value(&json_builder,
                                                                  (UCHAR *)reported_version_property_name,
                                                                  sizeof(reported_version_property_name) - 1,
                                                                  (int32_t)version) ||
        nx_azure_iot_json_writer_append_property_with_string_value(&json_builder,
                                                                   (UCHAR *)reported_description_property_name,
                                                                   sizeof(reported_description_property_name) - 1,
                                                                   description_ptr, description_len) ||
        nx_azure_iot_json_writer_append_end_object(&json_builder) ||
        nx_azure_iot_json_writer_append_end_object(&json_builder))
    {
        nx_azure_iot_json_writer_deinit(&json_builder);
        printf("Failed to build reported response\r\n");
    }
    else
    {
        bytes_copied = nx_azure_iot_json_writer_get_bytes_used(&json_builder);
        if (nx_azure_iot_hub_client_device_twin_reported_properties_send(&(context -> iothub_client),
                                                                         scratch_buffer, bytes_copied,
                                                                         &request_id, &response_status,
                                                                         &reported_property_version,
                                                                         (5 * NX_IP_PERIODIC_RATE)))
        {
            printf("Failed to send reported response\r\n");
        }
        nx_azure_iot_json_writer_deinit(&json_builder);
    }
}
/* Send desired property response as reported property.  */
Send desired property response as reported property.
Send desired property response as reported property .
static VOID sample_send_target_temperature_report(SAMPLE_CONTEXT *context, double current_device_temp_value,
                                                  UINT status, UINT version, UCHAR *description_ptr,
                                                  UINT description_len)
{
NX_AZURE_IOT_JSON_WRITER json_builder;
UINT bytes_copied;
UINT response_status;
UINT request_id;
ULONG reported_property_version;
    if (nx_azure_iot_json_writer_with_buffer_init(&json_builder, scratch_buffer, sizeof(scratch_buffer)))
    {
        printf("Failed to build reported response\r\n");
        return;
    }
    if (nx_azure_iot_json_writer_append_begin_object(&json_builder) ||
        nx_azure_iot_json_writer_append_property_name(&json_builder,
                                                      (UCHAR *)reported_temp_property_name,
                                                      sizeof(reported_temp_property_name) - 1) ||
        nx_azure_iot_json_writer_append_begin_object(&json_builder) ||
        nx_azure_iot_json_writer_append_property_with_double_value(&json_builder,
                                                                   (UCHAR *)reported_value_property_name,
                                                                   sizeof(reported_value_property_name) - 1,
                                                                   current_device_temp_value, DOUBLE_DECIMAL_PLACE_DIGITS) ||
        nx_azure_iot_json_writer_append_property_with_int32_value(&json_builder,
                                                                  (UCHAR *)reported_status_property_name,
                                                                  sizeof(reported_status_property_name) - 1,
                                                                  (int32_t)status) ||
        nx_azure_iot_json_writer_append_property_with_int32_value(&json_builder,
                                                                  (UCHAR *)reported_version_property_name,
                                                                  sizeof(reported_version_property_name) - 1,
                                                                  (int32_t)version) ||
        nx_azure_iot_json_writer_append_property_with_string_value(&json_builder,
                                                                   (UCHAR *)reported_description_property_name,
                                                                   sizeof(reported_description_property_name) - 1,
                                                                   description_ptr, description_len) ||
        nx_azure_iot_json_writer_append_end_object(&json_builder) ||
        nx_azure_iot_json_writer_append_end_object(&json_builder))
    {
        nx_azure_iot_json_writer_deinit(&json_builder);
        printf("Failed to build reported response\r\n");
    }
    else
    {
        bytes_copied = nx_azure_iot_json_writer_get_bytes_used(&json_builder);
        if (nx_azure_iot_hub_client_device_twin_reported_properties_send(&(context -> iothub_client),
                                                                         scratch_buffer, bytes_copied,
                                                                         &request_id, &response_status,
                                                                         &reported_property_version,
                                                                         (5 * NX_IP_PERIODIC_RATE)))
        {
            printf("Failed to send reported response\r\n");
        }
        nx_azure_iot_json_writer_deinit(&json_builder);
    }
}
static VOID sample_send_target_temperature_report ( SAMPLE_CONTEXT * context , double current_device_temp_value , UINT status , UINT version , UCHAR * description_ptr , UINT description_len ) { NX_AZURE_IOT_JSON_WRITER json_builder ; UINT bytes_copied ; UINT response_status ; UINT request_id ; ULONG reported_property_version ; if ( nx_azure_iot_json_writer_with_buffer_init ( & json_builder , scratch_buffer , sizeof ( scratch_buffer ) ) ) { printf ( " \r \n " ) ; return ; } if ( nx_azure_iot_json_writer_append_begin_object ( & json_builder ) || nx_azure_iot_json_writer_append_property_name ( & json_builder , ( UCHAR * ) reported_temp_property_name , sizeof ( reported_temp_property_name ) - 1 ) || nx_azure_iot_json_writer_append_begin_object ( & json_builder ) || nx_azure_iot_json_writer_append_property_with_double_value ( & json_builder , ( UCHAR * ) reported_value_property_name , sizeof ( reported_value_property_name ) - 1 , current_device_temp_value , DOUBLE_DECIMAL_PLACE_DIGITS ) || nx_azure_iot_json_writer_append_property_with_int32_value ( & json_builder , ( UCHAR * ) reported_status_property_name , sizeof ( reported_status_property_name ) - 1 , ( int32_t ) status ) || nx_azure_iot_json_writer_append_property_with_int32_value ( & json_builder , ( UCHAR * ) reported_version_property_name , sizeof ( reported_version_property_name ) - 1 , ( int32_t ) version ) || nx_azure_iot_json_writer_append_property_with_string_value ( & json_builder , ( UCHAR * ) reported_description_property_name , sizeof ( reported_description_property_name ) - 1 , description_ptr , description_len ) || nx_azure_iot_json_writer_append_end_object ( & json_builder ) || nx_azure_iot_json_writer_append_end_object ( & json_builder ) ) { nx_azure_iot_json_writer_deinit ( & json_builder ) ; printf ( " \r \n " ) ; } else { bytes_copied = nx_azure_iot_json_writer_get_bytes_used ( & json_builder ) ; if ( nx_azure_iot_hub_client_device_twin_reported_properties_send ( & ( context -> iothub_client ) , scratch_buffer , bytes_copied , & request_id , & response_status , & reported_property_version , ( 5 * NX_IP_PERIODIC_RATE ) ) ) { printf ( " \r \n " ) ; } nx_azure_iot_json_writer_deinit ( & json_builder ) ; } }
Send desired property response as reported property.
Send desired property response as reported property .