@@ -194,76 +194,41 @@ UINT azure_iot_nx_client_entry(
194194
195195 if ((status = tx_event_flags_create (& azure_iot_flags , "Azure IoT flags" )))
196196 {
197- printf ("FAIL: Unable to create nx_client event flags (0x%04x )\r\n" , status );
197+ printf ("FAIL: Unable to create nx_client event flags (0x%08x )\r\n" , status );
198198 return status ;
199199 }
200200
201- #ifdef ENABLE_DPS
202- # ifdef ENABLE_X509
203- status = azure_iot_nx_client_dps_create (& azure_iot_nx_client ,
204- ip_ptr ,
205- pool_ptr ,
206- dns_ptr ,
207- unix_time_callback ,
208- IOT_DPS_ENDPOINT ,
209- IOT_DPS_ID_SCOPE ,
210- IOT_DPS_REGISTRATION_ID ,
211- "" ,
201+ status = azure_iot_nx_client_create (
202+ & azure_iot_nx_client , ip_ptr , pool_ptr , dns_ptr , unix_time_callback , IOT_MODEL_ID );
203+ if (status != NX_SUCCESS )
204+ {
205+ printf ("ERROR: azure_iot_nx_client_create failed (0x%08x)\r\n" , status );
206+ return status ;
207+ }
208+
209+ #ifdef ENABLE_X509
210+ status = azure_iot_nx_client_cert_set (& azure_iot_nx_client ,
212211 (UCHAR * )iot_x509_device_cert ,
213212 iot_x509_device_cert_len ,
214213 (UCHAR * )iot_x509_private_key ,
215- iot_x509_private_key_len ,
216- IOT_MODEL_ID );
217- # else
218- status = azure_iot_nx_client_dps_create (& azure_iot_nx_client ,
219- ip_ptr ,
220- pool_ptr ,
221- dns_ptr ,
222- unix_time_callback ,
223- IOT_DPS_ENDPOINT ,
224- IOT_DPS_ID_SCOPE ,
225- IOT_DPS_REGISTRATION_ID ,
226- IOT_PRIMARY_KEY ,
227- NULL ,
228- 0 ,
229- NULL ,
230- 0 ,
231- IOT_MODEL_ID );
232- # endif
214+ iot_x509_private_key_len );
233215#else
234- # ifdef ENABLE_X509
235- status = azure_iot_nx_client_create (& azure_iot_nx_client ,
236- ip_ptr ,
237- pool_ptr ,
238- dns_ptr ,
239- unix_time_callback ,
240- IOT_HUB_HOSTNAME ,
241- IOT_DEVICE_ID ,
242- "" ,
243- (UCHAR * )iot_x509_device_cert ,
244- iot_x509_device_cert_len ,
245- (UCHAR * )iot_x509_private_key ,
246- iot_x509_private_key_len ,
247- IOT_MODEL_ID );
248- # else
249- status = azure_iot_nx_client_create (& azure_iot_nx_client ,
250- ip_ptr ,
251- pool_ptr ,
252- dns_ptr ,
253- unix_time_callback ,
254- IOT_HUB_HOSTNAME ,
255- IOT_DEVICE_ID ,
256- IOT_PRIMARY_KEY ,
257- NULL ,
258- 0 ,
259- NULL ,
260- 0 ,
261- IOT_MODEL_ID );
262- # endif
216+ status = azure_iot_nx_client_sas_set (& azure_iot_nx_client , IOT_PRIMARY_KEY );
217+ #endif
218+ if (status != NX_SUCCESS )
219+ {
220+ printf ("ERROR: azure_iot_nx_client_[sas|cert]_set failed (0x%08x)\r\n" , status );
221+ return status ;
222+ }
223+
224+ #ifdef ENABLE_DPS
225+ azure_iot_nx_client_dps_create (& azure_iot_nx_client , IOT_DPS_ENDPOINT , IOT_DPS_ID_SCOPE , IOT_DPS_REGISTRATION_ID );
226+ #else
227+ azure_iot_nx_client_hub_create (& azure_iot_nx_client , IOT_HUB_HOSTNAME , IOT_DEVICE_ID );
263228#endif
264229 if (status != NX_SUCCESS )
265230 {
266- printf ("ERROR: failed to create iot client 0x%04x \r\n" , status );
231+ printf ("ERROR: azure_iot_nx_client_[hub|dps]_create failed ( 0x%08x) \r\n" , status );
267232 return status ;
268233 }
269234
0 commit comments