private async Task <WeatherData> ReadWeatherData() { WeatherData wd = null; try { if (BMP280 == null) { //Create a new object for our barometric sensor class BMP280 = new BMP280(); //Initialize the sensor await BMP280.Initialize(); } //Create variables to store the sensor data: temperature, pressure and altitude. //Initialize them to 0. float temp = 0; float pressure = 0; float altitude = 0; //Create a constant for pressure at sea level. //This is based on your local sea level pressure (Unit: Hectopascal) const float seaLevelPressure = 1018.34f; temp = await BMP280.ReadTemperature(); temp = ConvertUnits.ConvertCelsiusToFahrenheit(temp); pressure = await BMP280.ReadPreasure(); pressure = ConvertUnits.ConvertPascalToMillibar(pressure); altitude = await BMP280.ReadAltitude(seaLevelPressure); altitude = ConvertUnits.ConvertMeterToFoot(altitude); wd = new WeatherData(); wd.Created = DateTime.Now; wd.TemperatureinF = temp; wd.Pressureinmb = pressure; } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(wd); }
private async Task<WeatherData> ReadWeatherData() { WeatherData wd = null; try { if (BMP280 == null) { //Create a new object for our barometric sensor class BMP280 = new BMP280(); //Initialize the sensor await BMP280.Initialize(); } //Create variables to store the sensor data: temperature, pressure and altitude. //Initialize them to 0. float temp = 0; float pressure = 0; float altitude = 0; //Create a constant for pressure at sea level. //This is based on your local sea level pressure (Unit: Hectopascal) const float seaLevelPressure = 1018.34f; temp = await BMP280.ReadTemperature(); temp = ConvertUnits.ConvertCelsiusToFahrenheit(temp); pressure = await BMP280.ReadPreasure(); pressure = ConvertUnits.ConvertPascalToMillibar(pressure); altitude = await BMP280.ReadAltitude(seaLevelPressure); altitude = ConvertUnits.ConvertMeterToFoot(altitude); wd = new WeatherData(); wd.Created = DateTime.Now; wd.TemperatureinF = temp; wd.Pressureinmb = pressure; } catch (Exception ex) { Debug.WriteLine(ex.Message); } return wd; }