/// <summary> /// Updates the data of the sensor with current data, received from the API /// </summary> /// <param name="sensor"></param> /// <returns></returns> public async Task UpdadeSensor(Sensor sensor) { try { ApiOutput apiOutput = await ApiConnector.getCurrentValue(sensorTypeForAPICall(sensor)); sensor.DataAsString = apiOutput.Value.ToString(); sensor.ConvertValueString(); } catch (Exception) { MessageBox.Show("Exception occured!"); } }
/// <summary> /// Gets the current value of a sensor with type "type", using the API /// </summary> /// <param name="type"></param> /// <returns></returns> public static async Task <ApiOutput> getCurrentValue(string type) { string url = API_BASE_PATH + type; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Add("auth-token", "8e4c46fe-5e1d-4382-b7fc-19541f7bf3b0"); HttpResponseMessage response = await client.GetAsync(url); if (response.IsSuccessStatusCode) { ApiOutput output = await response.Content.ReadAsAsync <ApiOutput>(); return(output); } } return(null); }