Skip to content

Commit bd5b9ea

Browse files
update to sdk version 1.3.1 (#20)
1 parent 57f7b87 commit bd5b9ea

14 files changed

+101
-588
lines changed

examples/Azure_IoT_Central_ESP32/Azure_IoT_Central_ESP32.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@
7878
static const char* wifi_ssid = IOT_CONFIG_WIFI_SSID;
7979
static const char* wifi_password = IOT_CONFIG_WIFI_PASSWORD;
8080

81-
// TODO: remove this after updating library with Azure SDK for C version 1.3.0-beta.2 or later.
82-
#define AZURE_SDK_CLIENT_USER_AGENT_WORKAROUND "DeviceClientType=" AZURE_SDK_CLIENT_USER_AGENT
83-
8481
/* --- Function Declarations --- */
8582
static void sync_device_clock_with_ntp_server();
8683
static void connect_to_wifi();
@@ -334,7 +331,7 @@ void setup()
334331
* throughout the lifetime of the sample. This variable must also not lose context so other
335332
* components do not overwrite any information within this structure.
336333
*/
337-
azure_iot_config.user_agent = AZ_SPAN_FROM_STR(AZURE_SDK_CLIENT_USER_AGENT_WORKAROUND);
334+
azure_iot_config.user_agent = AZ_SPAN_FROM_STR(AZURE_SDK_CLIENT_USER_AGENT);
338335
azure_iot_config.model_id = azure_pnp_get_model_id();
339336
azure_iot_config.use_device_provisioning = true; // Required for Azure IoT Central.
340337
azure_iot_config.iot_hub_fqdn = AZ_SPAN_EMPTY;

examples/Azure_IoT_Central_ESP32_AzureIoTKit/Azure_IoT_Central_ESP32_AzureIoTKit.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@
8484
static const char* wifi_ssid = IOT_CONFIG_WIFI_SSID;
8585
static const char* wifi_password = IOT_CONFIG_WIFI_PASSWORD;
8686

87-
// TODO: remove this after updating library with Azure SDK for C version 1.3.0-beta.2 or later.
88-
#define AZURE_SDK_CLIENT_USER_AGENT_WORKAROUND "DeviceClientType=" AZURE_SDK_CLIENT_USER_AGENT
89-
9087
/* --- Function Declarations --- */
9188
static void sync_device_clock_with_ntp_server();
9289
static void connect_to_wifi();
@@ -339,7 +336,7 @@ void setup()
339336
* throughout the lifetime of the sample. This variable must also not lose context so other
340337
* components do not overwrite any information within this structure.
341338
*/
342-
azure_iot_config.user_agent = AZ_SPAN_FROM_STR(AZURE_SDK_CLIENT_USER_AGENT_WORKAROUND);
339+
azure_iot_config.user_agent = AZ_SPAN_FROM_STR(AZURE_SDK_CLIENT_USER_AGENT);
343340
azure_iot_config.model_id = azure_pnp_get_model_id();
344341
azure_iot_config.use_device_provisioning = true; // Required for Azure IoT Central.
345342
azure_iot_config.iot_hub_fqdn = AZ_SPAN_EMPTY;

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=Azure SDK for C
2-
version=1.0.0-beta.3
2+
version=1.0.0-beta.4
33
author=Microsoft Corporation
44
maintainer=Microsoft Corporation <[email protected]>
55
sentence=Azure SDK for C library for Arduino.
6-
paragraph=This is an Arduino port of the Azure SDK for C (1.3.0-beta.1). It allows you to use your Arduino device with Azure services like Azure IoT Hub and Azure Device Provisioning Service. See README.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
6+
paragraph=This is an Arduino port of the Azure SDK for C (1.3.1). It allows you to use your Arduino device with Azure services like Azure IoT Hub and Azure Device Provisioning Service. See README.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
77
category=Communication
8-
url=https://github.com/Azure/azure-sdk-for-c/tree/1.3.0-beta.1
8+
url=https://github.com/Azure/azure-sdk-for-c/tree/1.3.1
99
architectures=*
1010
includes=az_core.h,az_iot.h,azure_ca.h

src/az_http_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ AZ_NODISCARD AZ_INLINE _az_http_policy_apiversion_options
8383
_az_http_policy_apiversion_options_default()
8484
{
8585
return (_az_http_policy_apiversion_options){
86-
._internal = { .option_location = _az_http_policy_apiversion_option_location_header,
87-
.name = AZ_SPAN_EMPTY,
88-
.version = AZ_SPAN_EMPTY }
86+
._internal = { .name = AZ_SPAN_EMPTY,
87+
.version = AZ_SPAN_EMPTY,
88+
.option_location = _az_http_policy_apiversion_option_location_header }
8989
};
9090
}
9191

src/az_iot_common.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,8 @@ typedef struct
162162
/**
163163
* @brief Initializes the Telemetry or C2D properties.
164164
*
165-
* @note The properties init API will not encode properties. In order to support
166-
* the following characters, they must be percent-encoded (RFC3986) as follows:
167-
* - `/` : `%2F`
168-
* - `%` : `%25`
169-
* - `#` : `%23`
170-
* - `&` : `%26`
171-
* Only these characters would have to be encoded. If you would like to avoid the need to
172-
* encode the names/values, avoid using these characters in names and values.
165+
* @note The properties must adhere to the character restrictions listed in the below link.
166+
* https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-construct
173167
*
174168
* @param[in] properties The #az_iot_message_properties to initialize.
175169
* @param[in] buffer Can either be an unfilled (but properly sized) #az_span or an #az_span
@@ -190,14 +184,8 @@ AZ_NODISCARD az_result az_iot_message_properties_init(
190184
/**
191185
* @brief Appends a name-value property to the list of properties.
192186
*
193-
* @note The properties append API will not encode properties. In order to support
194-
* the following characters, they must be percent-encoded (RFC3986) as follows:
195-
* `/` : `%2F`
196-
* `%` : `%25`
197-
* `#` : `%23`
198-
* `&` : `%26`
199-
* Only these characters would have to be encoded. If you would like to avoid the need to
200-
* encode the names/values, avoid using these characters in names and values.
187+
* @note The properties must adhere to the character restrictions listed in the below link.
188+
* https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-construct
201189
*
202190
* @param[in] properties The #az_iot_message_properties to use for this call.
203191
* @param[in] name The name of the property. Must be a valid, non-empty span.

src/az_iot_hub_client.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ static const az_span hub_client_param_equals_span = AZ_SPAN_LITERAL_FROM_STR("="
2121

2222
static const az_span hub_digital_twin_model_id = AZ_SPAN_LITERAL_FROM_STR("model-id");
2323
static const az_span hub_service_api_version = AZ_SPAN_LITERAL_FROM_STR("/?api-version=2020-09-30");
24-
static const az_span client_sdk_version
25-
= AZ_SPAN_LITERAL_FROM_STR("DeviceClientType=c%2F" AZ_SDK_VERSION_STRING);
24+
static const az_span client_sdk_device_client_type_name
25+
= AZ_SPAN_LITERAL_FROM_STR("DeviceClientType");
26+
static const az_span client_sdk_version_default_value
27+
= AZ_SPAN_LITERAL_FROM_STR("azsdk-c%2F" AZ_SDK_VERSION_STRING);
2628

2729
AZ_NODISCARD az_iot_hub_client_options az_iot_hub_client_options_default()
2830
{
2931
return (az_iot_hub_client_options){ .module_id = AZ_SPAN_EMPTY,
30-
.user_agent = client_sdk_version,
32+
.user_agent = client_sdk_version_default_value,
3133
.model_id = AZ_SPAN_EMPTY,
3234
.component_names = NULL,
3335
.component_names_length = 0 };
@@ -76,7 +78,9 @@ AZ_NODISCARD az_result az_iot_hub_client_get_user_name(
7678
}
7779
if (az_span_size(*user_agent) > 0)
7880
{
79-
required_length += az_span_size(*user_agent) + az_span_size(hub_client_param_separator_span);
81+
required_length += az_span_size(hub_client_param_separator_span)
82+
+ az_span_size(client_sdk_device_client_type_name)
83+
+ az_span_size(hub_client_param_equals_span) + az_span_size(*user_agent);
8084
}
8185
// Note we skip the length of the model id since we have to url encode it. Bound checking is done
8286
// later.
@@ -104,6 +108,8 @@ AZ_NODISCARD az_result az_iot_hub_client_get_user_name(
104108
if (az_span_size(*user_agent) > 0)
105109
{
106110
remainder = az_span_copy_u8(remainder, *az_span_ptr(hub_client_param_separator_span));
111+
remainder = az_span_copy(remainder, client_sdk_device_client_type_name);
112+
remainder = az_span_copy_u8(remainder, *az_span_ptr(hub_client_param_equals_span));
107113
remainder = az_span_copy(remainder, *user_agent);
108114
}
109115

src/az_iot_hub_client.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ typedef struct
4343
{
4444
/**
4545
* The module name (if a module identity is used).
46+
* Must conform to the requirements of the MQTT spec for topic
47+
* names (listed below) and of the IoT Hub (listed below)
48+
* http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718106
49+
* https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#device-identity-properties
4650
*/
4751
az_span module_id;
4852

@@ -94,12 +98,10 @@ AZ_NODISCARD az_iot_hub_client_options az_iot_hub_client_options_default();
9498
*
9599
* @param[out] client The #az_iot_hub_client to use for this call.
96100
* @param[in] iot_hub_hostname The IoT Hub Hostname.
97-
* @param[in] device_id The Device ID. If the ID contains any of the following characters, they must
98-
* be percent-encoded as follows:
99-
* - `/` : `%2F`
100-
* - `%` : `%25`
101-
* - `#` : `%23`
102-
* - `&` : `%26`
101+
* @param[in] device_id The Device ID. Must conform to the requirements of the MQTT spec for
102+
* topic names (listed below) and of the IoT Hub (listed below)
103+
* http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718106
104+
* https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#device-identity-properties
103105
* @param[in] options A reference to an #az_iot_hub_client_options structure. If `NULL` is passed,
104106
* the hub client will use the default options. If using custom options, please initialize first by
105107
* calling az_iot_hub_client_options_default() and then populating relevant options with your own

src/az_iot_hub_client_twin.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,17 @@ AZ_NODISCARD az_result az_iot_hub_client_twin_parse_received_topic(
173173
{
174174
// Is a reported prop response
175175
out_response->response_type = AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_REPORTED_PROPERTIES;
176-
_az_RETURN_IF_FAILED(az_iot_message_properties_find(
177-
&props, az_iot_hub_twin_version_prop, &out_response->version));
176+
177+
result = az_iot_message_properties_find(
178+
&props, az_iot_hub_twin_version_prop, &out_response->version);
179+
if (result == AZ_ERROR_ITEM_NOT_FOUND)
180+
{
181+
out_response->version = AZ_SPAN_EMPTY;
182+
}
183+
else
184+
{
185+
_az_RETURN_IF_FAILED(result);
186+
}
178187
}
179188
else // 200 or 202
180189
{

src/az_iot_provisioning_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ AZ_NODISCARD az_iot_provisioning_client_options az_iot_provisioning_client_optio
7575
* @param[in] global_device_hostname The device provisioning services global host name.
7676
* @param[in] id_scope The ID Scope.
7777
* @param[in] registration_id The Registration ID. This must match the client certificate name (CN
78-
* part of the certificate subject).
78+
* part of the certificate subject). Must conform to the limitations listed in the link below:
79+
* https://docs.microsoft.com/azure/iot-dps/concepts-service#registration-id
7980
* @param[in] options __[nullable]__ A reference to an #az_iot_provisioning_client_options
8081
* structure. Can be `NULL` for default options.
8182
* @pre \p client must not be `NULL`.

src/az_json.h

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ typedef struct
285285
*/
286286
AZ_NODISCARD AZ_INLINE az_json_writer_options az_json_writer_options_default()
287287
{
288-
az_json_writer_options options = (az_json_writer_options) {
288+
az_json_writer_options options = {
289289
._internal = {
290290
.unused = false,
291291
},
@@ -303,17 +303,39 @@ AZ_NODISCARD AZ_INLINE az_json_writer_options az_json_writer_options_default()
303303
*/
304304
typedef struct
305305
{
306+
/// The total number of bytes written by the #az_json_writer to the output destination buffer(s).
307+
/// This read-only field tracks the number of bytes of JSON written so far, and it shouldn't be
308+
/// modified by the caller.
309+
int32_t total_bytes_written;
310+
306311
struct
307312
{
313+
/// The destination to write the JSON into.
308314
az_span destination_buffer;
309-
int32_t bytes_written;
310-
// For single contiguous buffer, bytes_written == total_bytes_written
311-
int32_t total_bytes_written; // Currently, this is primarily used for testing.
315+
316+
/// The bytes written in the current destination buffer.
317+
int32_t bytes_written; // For single contiguous buffer, bytes_written == total_bytes_written
318+
319+
/// Allocator used to support non-contiguous buffer as a destination.
312320
az_span_allocator_fn allocator_callback;
321+
322+
/// Any struct that was provided by the user for their specific implementation, passed through
323+
/// to the #az_span_allocator_fn.
313324
void* user_context;
325+
326+
/// A state to remember when to emit a comma between JSON array and object elements.
314327
bool need_comma;
328+
329+
/// The current state of the writer based on the last token written, used for validating the
330+
/// correctness of the JSON being written.
315331
az_json_token_kind token_kind; // needed for validation, potentially #if/def with preconditions.
332+
333+
/// The current state of the writer based on the last JSON container it is in (whether array or
334+
/// object), used for validating the correctness of the JSON being written, and so it doesn't
335+
/// overflow the maximum supported depth.
316336
_az_json_bit_stack bit_stack; // needed for validation, potentially #if/def with preconditions.
337+
338+
/// A copy of the options provided by the user.
317339
az_json_writer_options options;
318340
} _internal;
319341
} az_json_writer;
@@ -390,18 +412,17 @@ az_json_writer_get_bytes_used_in_destination(az_json_writer const* json_writer)
390412
/**
391413
* @brief Appends the UTF-8 text value (as a JSON string) into the buffer.
392414
*
393-
* @note If you receive an #AZ_ERROR_NOT_ENOUGH_SPACE result while appending data for which there is
394-
* theoretically space, note that the JSON writer requires at least 64-bytes of slack within the
395-
* output buffer, above the theoretical minimal space needed. The JSON writer pessimistically
396-
* requires at least 64-bytes of space when writing any chunk of data larger than 10 characters
397-
* because it tries to write in 64 byte chunks (10 character * 6 if all need to be escaped into the
398-
* unicode form).
399-
*
400415
* @param[in,out] ref_json_writer A pointer to an #az_json_writer instance containing the buffer to
401416
* append the string value to.
402417
* @param[in] value The UTF-8 encoded value to be written as a JSON string. The value is escaped
403418
* before writing.
404419
*
420+
* @note If you receive an #AZ_ERROR_NOT_ENOUGH_SPACE result while appending data for which there is
421+
* sufficient space, note that the JSON writer requires at least 64 bytes of slack within the
422+
* output buffer, above the theoretical minimal space needed. The JSON writer pessimistically
423+
* requires this extra space because it tries to write formatted text in chunks rather than one
424+
* character at a time, whenever the input data is dynamic in size.
425+
*
405426
* @remarks If \p value is #AZ_SPAN_EMPTY, the empty JSON string value is written (i.e. "").
406427
*
407428
* @return An #az_result value indicating the result of the operation.
@@ -420,20 +441,19 @@ AZ_NODISCARD az_result az_json_writer_append_string(az_json_writer* ref_json_wri
420441
* is, without any formatting or spacing changes. No modifications are made to this text, including
421442
* escaping.
422443
*
444+
* @note If you receive an #AZ_ERROR_NOT_ENOUGH_SPACE result while appending data for which there is
445+
* sufficient space, note that the JSON writer requires at least 64 bytes of slack within the
446+
* output buffer, above the theoretical minimal space needed. The JSON writer pessimistically
447+
* requires this extra space because it tries to write formatted text in chunks rather than one
448+
* character at a time, whenever the input data is dynamic in size.
449+
*
423450
* @remarks A single, possibly nested, JSON value is one that starts and ends with {} or [] or is a
424451
* single primitive token. The JSON cannot start with an end object or array, or a property name, or
425452
* be incomplete.
426453
*
427454
* @remarks The function validates that the provided JSON to be appended is valid and properly
428455
* escaped, and fails otherwise.
429456
*
430-
* @note If you receive an #AZ_ERROR_NOT_ENOUGH_SPACE result while appending data for which there is
431-
* theoretically space, note that the JSON writer requires at least 64-bytes of slack within the
432-
* output buffer, above the theoretical minimal space needed. The JSON writer pessimistically
433-
* requires at least 64-bytes of space when writing any chunk of data larger than 10 characters
434-
* because it tries to write in 64 byte chunks (10 character * 6 if all need to be escaped into the
435-
* unicode form).
436-
*
437457
* @return An #az_result value indicating the result of the operation.
438458
* @retval #AZ_OK The provided \p json_text was appended successfully.
439459
* @retval #AZ_ERROR_NOT_ENOUGH_SPACE The destination is too small for the provided \p json_text.
@@ -456,6 +476,12 @@ az_json_writer_append_json_text(az_json_writer* ref_json_writer, az_span json_te
456476
* @param[in] name The UTF-8 encoded property name of the JSON value to be written. The name is
457477
* escaped before writing.
458478
*
479+
* @note If you receive an #AZ_ERROR_NOT_ENOUGH_SPACE result while appending data for which there is
480+
* sufficient space, note that the JSON writer requires at least 64 bytes of slack within the
481+
* output buffer, above the theoretical minimal space needed. The JSON writer pessimistically
482+
* requires this extra space because it tries to write formatted text in chunks rather than one
483+
* character at a time, whenever the input data is dynamic in size.
484+
*
459485
* @return An #az_result value indicating the result of the operation.
460486
* @retval #AZ_OK The property name was appended successfully.
461487
* @retval #AZ_ERROR_NOT_ENOUGH_SPACE The buffer is too small.
@@ -484,11 +510,10 @@ AZ_NODISCARD az_result az_json_writer_append_bool(az_json_writer* ref_json_write
484510
* @param[in] value The value to be written as a JSON number.
485511
*
486512
* @note If you receive an #AZ_ERROR_NOT_ENOUGH_SPACE result while appending data for which there is
487-
* theoretically space, note that the JSON writer requires at least 64-bytes of slack within the
513+
* sufficient space, note that the JSON writer requires at least 64 bytes of slack within the
488514
* output buffer, above the theoretical minimal space needed. The JSON writer pessimistically
489-
* requires at least 64-bytes of space when writing any chunk of data larger than 10 characters
490-
* because it tries to write in 64 byte chunks (10 character * 6 if all need to be escaped into the
491-
* unicode form).
515+
* requires this extra space because it tries to write formatted text in chunks rather than one
516+
* character at a time, whenever the input data is dynamic in size.
492517
*
493518
* @return An #az_result value indicating the result of the operation.
494519
* @retval #AZ_OK The number was appended successfully.
@@ -506,11 +531,10 @@ AZ_NODISCARD az_result az_json_writer_append_int32(az_json_writer* ref_json_writ
506531
* point and truncate the rest.
507532
*
508533
* @note If you receive an #AZ_ERROR_NOT_ENOUGH_SPACE result while appending data for which there is
509-
* theoretically space, note that the JSON writer requires at least 64-bytes of slack within the
534+
* sufficient space, note that the JSON writer requires at least 64 bytes of slack within the
510535
* output buffer, above the theoretical minimal space needed. The JSON writer pessimistically
511-
* requires at least 64-bytes of space when writing any chunk of data larger than 10 characters
512-
* because it tries to write in 64 byte chunks (10 character * 6 if all need to be escaped into the
513-
* unicode form).
536+
* requires this extra space because it tries to write formatted text in chunks rather than one
537+
* character at a time, whenever the input data is dynamic in size.
514538
*
515539
* @return An #az_result value indicating the result of the operation.
516540
* @retval #AZ_OK The number was appended successfully.
@@ -621,7 +645,7 @@ typedef struct
621645
*/
622646
AZ_NODISCARD AZ_INLINE az_json_reader_options az_json_reader_options_default()
623647
{
624-
az_json_reader_options options = (az_json_reader_options) {
648+
az_json_reader_options options = {
625649
._internal = {
626650
.unused = false,
627651
},

0 commit comments

Comments
 (0)