private static void Main() { Console.WriteLine("Simulated device\n"); DeviceClient deviceClient = null; try { deviceClient = DeviceClient.CreateFromConnectionString(AzureIoTHub.GetConnectionString(), TransportType.Mqtt); ExcuteDirectMethod(deviceClient); } catch (AggregateException ex) { foreach (var exception in ex.InnerExceptions) { Console.WriteLine(); Console.WriteLine("Error in sample: {0}", exception); } } catch (Exception) { //Some code here } RemoveMethodHandler(deviceClient); Console.ReadLine(); }
private static void Main() { Console.WriteLine("Simulated device\n"); try { var deviceClient = DeviceClient.CreateFromConnectionString(AzureIoTHub.GetConnectionString(), TransportType.Mqtt); new DeviceSimulator(deviceClient).SendDeviceToCloudMessagesAsync(AzureIoTHub.deviceId); /* */ // UN-comment the code you want to execute new FileUploads().InitFileUpload(); UpdateFirmware(AzureIoTHub.deviceId); Console.ReadLine(); } catch (AggregateException ex) { foreach (var exception in ex.InnerExceptions) { Console.WriteLine(); Console.WriteLine("Error in sample: {0}", exception); } } catch (Exception) { //Some code here } }
/// <summary> /// /// </summary> /// <param name="targetDevice"></param> /// <returns></returns> public async void StartFirmwareUpdate(string targetDevice) { // assign the URL of Blob from where the latest firmware can be downloaded String bloburl = ""; _client = ServiceClient.CreateFromConnectionString(AzureIoTHub.GetConnectionString()); CloudToDeviceMethod method = new CloudToDeviceMethod("firmwareUpdate"); method.ResponseTimeout = TimeSpan.FromSeconds(30); method.SetPayloadJson(@"{fwPackageUri : '" + bloburl + "'}"); await _client.InvokeDeviceMethodAsync(targetDevice, method); Console.WriteLine("firmware update on device is Successful."); }
private static async void ProcessFileUpload() { var serviceClient = ServiceClient.CreateFromConnectionString(AzureIoTHub.GetConnectionString()); await new FileUploads().ReceiveFileUploadNotificationAsync(serviceClient); }
public DeviceIdentity() { // initialize to default values _connectionString = AzureIoTHub.GetConnectionString(); _registryManager = RegistryManager.CreateFromConnectionString(_connectionString); }
public ReadDeviceToCloudMessages() { _eventHubClient = EventHubClient.CreateFromConnectionString(AzureIoTHub.GetConnectionString(), iotHubD2cEndpoint); }