public async void sendData(WeatherData wd) { // Create a client HttpClient httpClient = new HttpClient(); // Add a new Request Message HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://io.adafruit.com/api/groups/weather/send.json?temperature=" + wd.TemperatureinF + "&pressure=" + wd.Pressureinmb ); // Add our custom headers requestMessage.Headers.Add("X-AIO-Key", AIO); // Send the request to the server HttpResponseMessage response = await httpClient.SendAsync(requestMessage); // Just as an example I'm turning the response into a string here string responseAsString = await response.Content.ReadAsStringAsync(); //Debug.WriteLine(responseAsString); }
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; }