|  | 
| 37 | 37 | #define TELEMETRY_BUFFER_SIZE 256 | 
| 38 | 38 | #define PROPERTIES_BUFFER_SIZE 128 | 
| 39 | 39 | 
 | 
|  | 40 | +// define static strings for content type and -encoding on message property bag  | 
|  | 41 | +static const UCHAR content_type_property[] = "$.ct"; | 
|  | 42 | +static const UCHAR content_encoding_property[] = "$.ce"; | 
|  | 43 | +static const UCHAR content_type_json[] = "application%2Fjson"; | 
|  | 44 | +static const UCHAR content_encoding_utf8[] = "utf-8"; | 
|  | 45 | + | 
| 40 | 46 | static UCHAR telemetry_buffer[TELEMETRY_BUFFER_SIZE]; | 
| 41 | 47 | static UCHAR properties_buffer[PROPERTIES_BUFFER_SIZE]; | 
| 42 | 48 | 
 | 
| @@ -666,6 +672,28 @@ UINT azure_iot_nx_client_publish_telemetry(AZURE_IOT_NX_CONTEXT* context_ptr, | 
| 666 | 672 |  return status; | 
| 667 | 673 |  } | 
| 668 | 674 | 
 | 
|  | 675 | + // set the ContentType property on the message to "application/json" (url-encoded) | 
|  | 676 | + status = nx_azure_iot_hub_client_telemetry_property_add(packet_ptr, content_type_property, sizeof( content_type_property )-1, | 
|  | 677 | + content_type_json, sizeof( content_type_json )-1, | 
|  | 678 | + NX_WAIT_FOREVER); | 
|  | 679 | + if (status != NX_AZURE_IOT_SUCCESS) | 
|  | 680 | + { | 
|  | 681 | + printf("Error: cannot set ContentType message property (0x%08X)\r\n", status); | 
|  | 682 | + nx_azure_iot_hub_client_telemetry_message_delete(packet_ptr); | 
|  | 683 | + return status; | 
|  | 684 | + } | 
|  | 685 | + | 
|  | 686 | + // set the ContentEncoding property on the message to "utf-8" | 
|  | 687 | + status = nx_azure_iot_hub_client_telemetry_property_add(packet_ptr, content_encoding_property, sizeof( content_encoding_property )-1, | 
|  | 688 | + content_encoding_utf8, sizeof( content_encoding_utf8 )-1, | 
|  | 689 | + NX_WAIT_FOREVER); | 
|  | 690 | + if (status != NX_AZURE_IOT_SUCCESS) | 
|  | 691 | + { | 
|  | 692 | + printf("Error: Canot set ContentEncoding message property (0x%08X)\r\n", status); | 
|  | 693 | + nx_azure_iot_hub_client_telemetry_message_delete(packet_ptr); | 
|  | 694 | + return status; | 
|  | 695 | + } | 
|  | 696 | + | 
| 669 | 697 |  telemetry_length = nx_azure_iot_json_writer_get_bytes_used(&json_writer); | 
| 670 | 698 |  if ((status = nx_azure_iot_hub_client_telemetry_send( | 
| 671 | 699 |  &context_ptr->iothub_client, packet_ptr, telemetry_buffer, telemetry_length, NX_WAIT_FOREVER))) | 
|  | 
0 commit comments