Пример #1
0
        // This method will be called by the application framework when the page is first loaded
        protected override async void OnNavigatedTo(NavigationEventArgs navArgs)
        {
            try
            {
                _BME280 = new BME280Sensor(_localSeaLevelPressure); // Create a new object for our sensor class
                await _BME280.InitializeDevice();                   // Initialize the sensor

                if (_BME280.init)
                {
                    // If all goes well, our BME280 is initialized and we can set up
                    // a timer which will take a reading and send data to the cloud
                    _weatherDataSender = new EventHubDataSender(_eventHubConnectionString);
                    _timer             = new DispatcherTimer
                    {
                        Interval = TimeSpan.FromMilliseconds(_timerInterval)
                    };
                    _timer.Tick += TakeReadingAsync; // Register this method to the dispatcher so that it is called every tick
                    _timer.Start();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }