private static void SendMessagesToIotHub(FlexAsset myAsset, List <Message> messages) { Console.Write("Send messages to IoT hub..."); IAuthenticationMethod auth = new DeviceAuthenticationWithRegistrySymmetricKey(myAsset.deviceId, myAsset.primaryKey); using var client = Microsoft.Azure.Devices.Client.DeviceClient.Create(myAsset.asignedHub, auth, TransportType.Mqtt); client.SendEventBatchAsync(messages).GetAwaiter().GetResult(); Console.WriteLine(" successfully sent!"); }
private static void ProvisionDevice(FlexAsset myAsset, string deviceFile) { // The device need to be provisioned before first time usage. if (myAsset.provisioned) { return; } myAsset.asignedHub = ProvisionDevice(myAsset.scopeId, myAsset.deviceId, myAsset.primaryKey); myAsset.provisioned = true; File.WriteAllText(deviceFile, JsonConvert.SerializeObject(myAsset)); }