/** * @brief Asynchronous chart update procedure with * data obtained from IoT server responses. * @param ip IoT server IP address. */ private async void UpdatePlotWithServerResponseTemp() { #if CLIENT #if GET string responseText = await Server.GETwithClient(); #else string responseText = await Server.POSTwithClient(); #endif #else #if GET string responseText = await Server.GETwithRequest(); #else string responseText = await Server.POSTwithRequest(); #endif #endif try { #if DYNAMIC dynamic responseJson = JArray.Parse(responseText); UpdatePlotTemp(timeStamp / 1000.0, (double)responseJson[0].data); #else ServerData responseJson = JsonConvert.DeserializeObject <ServerData>(responseText); UpdatePlotTemp(timeStamp / 1000.0, responseJson[0].data); #endif } catch (Exception e) { Debug.WriteLine("JSON DATA ERROR"); Debug.WriteLine(responseText); Debug.WriteLine(e); } timeStamp += config.SampleTime; }
/** * @brief Asynchronous chart update procedure with * data obtained from IoT server responses. * @param ip IoT server IP address. */ private async void UpdatePlotWithServerResponse() { #if CLIENT #if GET string responseText = await Server.GETwithClient(); #else string responseText_IMU = await Server.POSTwithClient("rpy"); string responseText_ENV = await Server.POSTwithClient("env"); #endif #else #if GET string responseText = await Server.GETwithRequest(); #else string responseText = await Server.POSTwithRequest(); #endif #endif try { #if DYNAMIC App.Current.Dispatcher.Invoke((System.Action) delegate { JArray measurementsJsonArray = JArray.Parse(responseText_ENV.Replace(']', ',') + responseText_IMU.TrimStart('[')); var measurementsList = measurementsJsonArray.ToObject <List <MeasurementModel> >(); measurementsList.RemoveAt(3); measurementsList.RemoveAt(6); if (Measurements.Count < measurementsList.Count) { foreach (var m in measurementsList) { Measurements.Add(new MeasurementViewModel(m)); } } // Update existing elements in collection else { for (int i = 0; i < Measurements.Count; i++) { Measurements[i].UpdateWithModel(measurementsList[i]); } } }); JArray array_IMU = JArray.Parse(responseText_IMU); JArray array_ENV = JArray.Parse(responseText_ENV); foreach (JObject obj in array_IMU.Children <JObject>()) { foreach (JProperty singleProp in obj.Properties()) { if (singleProp.Path == "[0].value") { string x = singleProp.Value.ToString(); double result = Convert.ToDouble(x); if (result > 180) { result -= 360; } Roll_read = result.ToString("N1"); UpdatePlot_IMU(timeStamp / 1000.0, result, 0); } if (singleProp.Path == "[1].value") { string x = singleProp.Value.ToString(); double result = Convert.ToDouble(x); if (result > 180) { result -= 360; } Pitch_read = result.ToString("N1"); UpdatePlot_IMU(timeStamp / 1000.0, result, 1); } if (singleProp.Path == "[2].value") { string x = singleProp.Value.ToString(); double result = Convert.ToDouble(x); if (result > 180) { result -= 360; } Yaw_read = result.ToString("N1"); UpdatePlot_IMU(timeStamp / 1000.0, result, 2); } } } foreach (JObject obj in array_ENV.Children <JObject>()) { foreach (JProperty singleProp in obj.Properties()) { if (singleProp.Path == "[0].value") { string x = singleProp.Value.ToString(); double result = Convert.ToDouble(x); Temp_read = result.ToString("N2"); UpdatePlot_temp(timeStamp / 1000.0, result); } if (singleProp.Path == "[1].value") { string x = singleProp.Value.ToString(); double result = Convert.ToDouble(x); Press_read = result.ToString("N2"); UpdatePlot_press(timeStamp / 1000.0, result); } if (singleProp.Path == "[2].value") { string x = singleProp.Value.ToString(); double result = Convert.ToDouble(x); Humid_read = result.ToString("N2"); UpdatePlot_humid(timeStamp / 1000.0, result); } } } #else ServerData resposneJson = JsonConvert.DeserializeObject <ServerData>(responseText); UpdatePlot(timeStamp / 1000.0, resposneJson.data); #endif } catch (Exception e) { Debug.WriteLine("JSON DATA ERROR"); Debug.WriteLine(responseText_IMU); Debug.WriteLine(e); } timeStamp += config.SampleTime; }