Ejemplo n.º 1
0
        private static async Task RunDeviceConnectivitySupplyChain()
        {
            using (var iotCompany = new IoTCompany(
                       RuntimeConfig,
                       ProvisioningService))
            {
                // ******** Azure IoT Hub DPS Service ********
                // 1. Create a Enrollment Group if not exists
                Console.Write($"\nCreating a new Enrollment Group: {RuntimeConfig.AzureDPSEnrollmentGroup}...");

                await iotCompany.CleanUpAndCreateEnrollmentGroupAsync().ConfigureAwait(false);

                Console.Write($"OK!\n");

                // 2. Go over the PoP
                await iotCompany.KickoffPoPAsync().ConfigureAwait(false);

                // ******** Azure IoT Hub DPS Service ********
                // 3. Supply Chain with Device Provisioning
                Console.Write("\nMaking and provisioning a new IoT Device to IoT Hub...");

                var brandNewIoTDevice = await iotCompany.MakeDeviceAsync().ConfigureAwait(false);

                Console.Write($"OK!\n");

                // 4. Start sending telemetry
                Console.Write($"\nAuthenticating {brandNewIoTDevice.DeviceID} and send telemetry sample message...");

                await brandNewIoTDevice.AuthNAndSendTelemetryAsync().ConfigureAwait(false);

                Console.Write($"OK!\n");

                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey();
            }
        }