public MainPage()
        {
            this.InitializeComponent();

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += Timer_Tick;

            device = Microsoft.Azure.Devices.Client.DeviceClient.CreateFromConnectionString(DeviceConnectionString);

            InitThings();

            this.Unloaded += MainPage_Unloaded;
        }
Esempio n. 2
0
        public async Task UpdateReportedTwinAsync(string deviceId, string twinName, int twinValue)
        {
            try
            {
                Microsoft.Azure.Devices.Client.DeviceClient device = Microsoft.Azure.Devices.Client.DeviceClient.CreateFromConnectionString(this.Configuration.IoTHubConnectionString, deviceId);
                var twinCollection = new TwinCollection();
                twinCollection[twinName] = twinValue;
                await device.UpdateReportedPropertiesAsync(twinCollection);

                device.Dispose();
            }
            catch (System.InvalidOperationException)
            {
            }
        }
        private async void buttonOpen_Click(object sender, RoutedEventArgs e)
        {
            deviceClient = Microsoft.Azure.Devices.Client.DeviceClient.CreateFromConnectionString(tbConnectionString.Text, Microsoft.Azure.Devices.Client.TransportType.Amqp);
            try
            {
                await deviceClient.OpenAsync();

                tbMessage.Text = "Connected";
                ReceiveC2DMessages();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception : " + ex.Message);
            }
        }