This is a quick tutorial with the steps to query Individual Enrollmens from the Microsoft Azure IoT Hub Device Provisioning Service using the C SDK.
-
Clone the C SDK repository
-
Compile the C SDK as shown here, using the
-Duse_prov_client=ON
flag. -
Edit
prov_sc_bulk_query_sample.c
to add your provisioning service information:-
Replace the
[Connection String]
with the Provisioning Connection String copied from your Device Provisiong Service on the Portal.const char* connectionString = "[Connection String]";
-
This sample assumes there are already Individual Enrollments on your Device Provisioning Service. See the prov_sc_individual_enrollment_sample for instructions on how to create some.
-
This sample uses Individual Enrollments, however query supports Enrollment Groups and Device Registration Statuses as well.
-
In order to use Enrollment Groups:
-
Use the
prov_sc_query_enrollment_group
function instead ofprov_sc_query_individual_enrollment
.prov_sc_query_enrollment_group(prov_sc, &query_spec, &cont_token, &query_resp);
-
When accessing results, use the
eg
part of theresponse_arr
union type instead ofie
, where the elements will be of typeENROLLMENT_GROUP_HANDLE
:ENROLLMENT_GROUP_HANDLE eg = query_resp->response_arr.eg[i];
-
-
In order to use Device Registration Statuses:
-
Instead of setting the
query_spec.query_string
field, set thequery_spec.registration_id
field to the registration ID of the Enrollment Group you would like to query for Device Registration Statuses.query_spec.registration_id = "[Registration Id]";
-
Use the
prov_sc_query_device_registration_status
function instead ofprov_sc_query_individual_enrollment
.prov_sc_query_device_registration_state(prov_sc, &query_spec, &cont_token, &query_resp)
-
When accessing results, use the
drs
part of theresponse_arr
union type instead ofie
, where the elements will be of typeDEVICE_REGISTRATION_STATE_HANDLE
:DEVICE_REGISTRATION_STATE_HANDLE drs = query_resp->response_arr.drs[i];
-
-
-
-
Build as shown here and run the sample.