protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _bme280 = new BuildAzure.IoT.Adafruit.BME280.BME280Sensor();
            await _bme280.Initialize();

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromSeconds(30);
            _timer.Tick    += _timer_Tick;

            _timer.Start();
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var dis = await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector());

            var i2cDevice = await I2cDevice.FromIdAsync(dis[0].Id, new I2cConnectionSettings(0x55)); // exception thro

            _bme280 = new BuildAzure.IoT.Adafruit.BME280.BME280Sensor();
            await _bme280.Initialize();

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromSeconds(5);
            _timer.Tick    += _timer_Tick;

            _timer.Start();
        }
Beispiel #3
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Debug.WriteLine("OnNavigatedTo");
            base.OnNavigatedTo(e);

            _bme280 = new BuildAzure.IoT.Adafruit.BME280.BME280Sensor();
            await _bme280.Initialize();

            Debug.WriteLine("BME280Sensor is initialized");

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMinutes(30);
            _timer.Tick    += CheckWeather;

            _timer.Start();

            CheckWeather(this, null);
        }
Beispiel #4
0
        private async void DeviceToCloudMessage()
        {
            await bME280.Initialize();

            double temp  = 0.00d;
            float  hum   = 0.00f;
            float  press = 0.00f;

            while (true)
            {
                temp = await bME280.ReadTemperature();

                hum = await bME280.ReadHumidity();

                press = await bME280.ReadPressure() / 100;

                var telemetryDataPoint = new
                {
                    messageId   = messageId++,
                    deviceId    = deviceID,
                    dateTime    = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"),
                    temperature = temp,
                    humidity    = hum,
                    pressure    = press
                };
                var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
                var message       = new Message(Encoding.ASCII.GetBytes(messageString));

                try
                {
                    await DeviceClient.SendEventAsync(message);

                    Debug.WriteLine("Ended sending ");
                }
                catch (HttpRequestException e)
                {
                    Debug.WriteLine("Error Message: {0}", e.InnerException.Message);
                }
                Debug.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);

                Task.Delay(15000).Wait();
            }
        }