1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
# Azure IoT Hub Client Properties
**nx_azure_iot_hub_client_reported_properties_component_begin**
***
<div style="text-align: right">Append the necessary characters to a reported property JSON payload belonging to a subcomponent.</div>
**Prototype**
```c
UINT nx_azure_iot_hub_client_reported_properties_component_begin(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr,
NX_AZURE_IOT_JSON_WRITER *writer_ptr,
const UCHAR *component_name_ptr,
USHORT component_name_length);
```
**Description**
<p>This routine appends the necessary characters to a reported properties JSON payload belonging to a subcomponent. The payload will be of the form: </p>
```c
"reported": {
"<component_name>": {
"__t": "c",
"temperature": 23
}
}
```
**Note** This API should be used in conjunction with
```c
nx_azure_iot_hub_client_reported_properties_component_end()
```
**Parameters**
| Name | Description |
| - |:-|
| hub_client_ptr [in] | A pointer to a `NX_AZURE_IOT_HUB_CLIENT`. |
| writer_ptr [in] | A pointer to a #NX_AZURE_IOT_JSON_WRITER. |
| component_name_ptr [in] | A pointer to a component name. |
| component_name_length [in] | Length of `component_name_ptr`. |
**Return Values**
* NX_AZURE_IOT_SUCCESS Successful if JSON payload was prefixed successfully.
**Allowed From**
Threads
**Example**
**See Also**
<div style="page-break-after: always;"></div>
**nx_azure_iot_hub_client_reported_properties_component_end**
***
<div style="text-align: right">Append the necessary characters to end a reported property JSON payload belonging to a subcomponent.</div>
**Prototype**
```c
UINT nx_azure_iot_hub_client_reported_properties_component_end(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr,
NX_AZURE_IOT_JSON_WRITER *writer_ptr);
```
**Description**
<p>This routine appends the necessary characters to end a reported properties JSON payload</p>
**Note** This API should be used in conjunction with
```c
nx_azure_iot_hub_client_reported_properties_component_begin()
```
**Parameters**
| Name | Description |
| - |:-|
| hub_client_ptr [in] | A pointer to a `NX_AZURE_IOT_HUB_CLIENT`. |
| writer_ptr [in] | A pointer to a #NX_AZURE_IOT_JSON_WRITER. |
**Return Values**
* NX_AZURE_IOT_SUCCESS The JSON payload was suffixed successfully.
**Allowed From**
Threads
**Example**
**See Also**
<div style="page-break-after: always;"></div>
**nx_azure_iot_hub_client_reported_properties_status_begin**
***
<div style="text-align: right"> Begin a property response payload with confirmation status.</div>
**Prototype**
```c
UINT nx_azure_iot_hub_client_reported_properties_status_begin(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr,
NX_AZURE_IOT_JSON_WRITER *writer_ptr,
const UCHAR *property_name_ptr,
UINT property_name_length,
UINT status_code,
ULONG version,
const UCHAR *description_ptr,
UINT description_length);
```
**Description**
<p>This API should be used in response to an incoming writable property. More details can be found
here:
https://docs.microsoft.com/en-us/azure/iot-pnp/concepts-convention#writable-properties
The payload will be of the form:
<p>
**Without component**
```c
//{
// "<property_name>":{
// "ac": <status_code>,
// "av": <version>,
// "ad": "<description>",
// "value": <user_value>
// }
//}
```
<p>To send a status for a property belonging to a component, first call the
nx_azure_iot_hub_client_reported_property_status_begin() API to prefix the payload with the
necessary identification. The API call flow would look like the following with the listed JSON
payload being generated.<p>
**With component**
```c
nx_azure_iot_hub_client_reported_properties_component_begin()
nx_azure_iot_hub_client_reported_properties_status_begin()
// Append user value here (<user_value>)
nx_azure_iot_hub_client_reported_properties_status_end()
nx_azure_iot_hub_client_reported_properties_component_end()
//{
// "<component_name>": {
// "__t": "c",
// "<property_name>": {
// "ac": <status_code>,
// "av": <version>,
// "ad": "<description>",
// "value": <user_value>
// }
// }
//}
```
**Note** This API should be used in conjunction with
```c
nx_azure_iot_hub_client_reported_properties_status_end()
```
**Parameters**
| Name | Description |
| - |:-|
| hub_client_ptr [in] | A pointer to a `NX_AZURE_IOT_HUB_CLIENT`. |
| writer_ptr [in] | A pointer to a #NX_AZURE_IOT_JSON_WRITER. |
| property_name_ptr [in] | A pointer to property name. |
| property_name_length [in] | Length of `property_name_ptr`. |
| status_code [in] | The HTTP-like status code to respond with. |
| version [in] | The version of the property the application is acknowledging. |
| description_ptr [in] | An optional pointer to description detailing the context or any details about the acknowledgement. This can be empty string. |
| description_length [in] | Length of description_ptr. |
**Return Values**
* NX_AZURE_IOT_SUCCESS Successful appended JSON prefix.
**Allowed From**
Threads
**Example**
**See Also**
<div style="page-break-after: always;"></div>
**nx_azure_iot_hub_client_reported_properties_status_end**
***
<div style="text-align: right">End a property response payload with confirmation status.</div>
**Prototype**
```c
UINT nx_azure_iot_hub_client_reported_properties_status_end(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr,
NX_AZURE_IOT_JSON_WRITER *writer_ptr);
```
**Description**
<p>This routine ends the property response payload.</p>
**Note** This API should be used in conjunction with
```c
nx_azure_iot_hub_client_reported_properties_status_begin()
```
**Parameters**
| Name | Description |
| - |:-|
| hub_client_ptr [in] | A pointer to a `NX_AZURE_IOT_HUB_CLIENT`. |
| writer_ptr [in] | A pointer to a #NX_AZURE_IOT_JSON_WRITER. |
**Return Values**
* NX_AZURE_IOT_SUCCESS Successful appended JSON suffix.
**Allowed From**
Threads
**Example**
**See Also**
<div style="page-break-after: always;"></div>
**nx_azure_iot_hub_client_properties_version_get**
***
<div style="text-align: right">Get the property version</div>
**Prototype**
```c
UINT nx_azure_iot_hub_client_properties_version_get(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr,
NX_AZURE_IOT_JSON_READER *reader_ptr,
UINT message_type, ULONG *version_ptr);
```
**Description**
<p>This routine gets the property version.</p>
**Parameters**
| Name | Description |
| - |:-|
| hub_client_ptr [in] | A pointer to a `NX_AZURE_IOT_HUB_CLIENT`. |
| reader_ptr [in] | A pointer to a #NX_AZURE_IOT_JSON_READER containing properties document. |
| message_type [in] | Type of message repsonse, only valid value are NX_AZURE_IOT_HUB_PROPERTIES or NX_AZURE_IOT_HUB_WRITABLE_PROPERTIES. |
| version_ptr [out] | The numeric version of the properties in JSON payload. |
**Return Values**
* NX_AZURE_IOT_SUCCESS Successful if got the property version.
**Allowed From**
Threads
**Example**
**See Also**
<div style="page-break-after: always;"></div>
**nx_azure_iot_hub_client_properties_component_property_next_get**
***
<div style="text-align: right">Return the next desired or reported property in the property document passed.</div>
**Prototype**
```c
UINT nx_azure_iot_hub_client_properties_component_property_next_get(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr,
NX_AZURE_IOT_JSON_READER *reader_ptr,
UINT message_type, UINT property_type,
const UCHAR **component_name_pptr,
USHORT *component_name_length_ptr);
```
**Description**
<p>This routine gets the next writable or reported property in the properties document passed.</p>
**Note** that between calls, the UCHAR* pointed to by \p component_name_pptr shall not be modified, only checked and compared. Internally, the pointer is only changed if the component name changes in the JSON document and is not necessarily set every invocation of the function.
On success, the `reader_ptr` will be set on a valid property name. After checking the property name, the reader can be advanced to the property value by calling nx_azure_iot_json_reader_next_token(). Note that on the subsequent call to this API, it is expected that the json reader will be placed AFTER the read property name and value. That means that after reading the property value (including single values or complex objects), the user must call nx_azure_iot_json_reader_next_token().
Below is a code snippet which you can use as a starting point:
```c
while ((status = nx_azure_iot_hub_client_properties_component_property_next_get(&iothub_client,
&json_reader,
message_type,
NX_AZURE_IOT_HUB_CLIENT_PROPERTY_WRITABLE,
&component_name_ptr, &component_length)) == NX_AZURE_IOT_SUCCESS)
{
/* Check if property is of interest (substitute user_property for your own property name) */
if (nx_azure_iot_json_reader_token_is_text_equal(&json_reader, user_property, user_property_length))
{
nx_azure_iot_json_reader_next_token(&json_reader);
/* Get the property value here
Example: nx_azure_iot_json_reader_token_int32_get(&json_reader, &user_int); */
/* Skip to next property value */
nx_azure_iot_json_reader_next_token(&json_reader);
}
else
{
/* The JSON reader must be advanced regardless of whether the property
is of interest or not. */
nx_azure_iot_json_reader_next_token(&json_reader);
/* Skip children in case the property value is an object. */
nx_azure_iot_json_reader_skip_children(&json_reader);
nx_azure_iot_json_reader_next_token(&json_reader);
}
}
```
**Parameters**
| Name | Description |
| - |:-|
| hub_client_ptr [in] | A pointer to a `NX_AZURE_IOT_HUB_CLIENT`. |
| reader_ptr [in] | A pointer to a #NX_AZURE_IOT_JSON_READER containing properties document. |
| message_type [in] | Type of message repsonse, only valid value are NX_AZURE_IOT_HUB_PROPERTIES or NX_AZURE_IOT_HUB_WRITABLE_PROPERTIES. |
| property_type [in] | Type of property, only valid value are NX_AZURE_IOT_HUB_CLIENT_PROPERTY_REPORTED_FROM_DEVICE or NX_AZURE_IOT_HUB_CLIENT_PROPERTY_WRITABLE. |
| component_name_pptr [out] | A pointer to component name for the property returned using reader_ptr. |
| component_name_length_ptr [out] | Length of the component name. |
**Return Values**
* NX_AZURE_IOT_SUCCESS Successful if next property is found.
**Allowed From**
Threads
**Example**
**See Also**
<div style="page-break-after: always;"></div>
|