private void sendData() { if (server_available && connected) { try { TempHumidSI70.Measurement th = tempHumidSI70.TakeMeasurement(); // Create the form values // var formValues = "password="******"armando"/* + "&time=" + DateTime.Now.ToString() */+ "&temp=" + th.Temperature.ToString() + "&humid=" + th.RelativeHumidity.ToString() + "&gas=" + gasSense.ReadProportion().ToString(); var reqStart = "<RequestData xmlns=\"http://www.cosacosacosa.com/cosa\"><details>"; var formValues = pwd + /*"|" +DateTime.Now.ToString()+*/ "|" + th.Temperature.ToString("F2") + "|" + th.RelativeHumidity.ToString("F2") + "|" + gasSense.ReadProportion().ToString("F2"); var reqEnd = "</details></RequestData>"; Debug.Print(reqStart + formValues + reqEnd); // Create POST content var content = Gadgeteer.Networking.POSTContent.CreateTextBasedContent(reqStart + formValues + reqEnd); // Create the request var request = Gadgeteer.Networking.HttpHelper.CreateHttpPostRequest( @"http://192.168.43.244:51417/Service1.svc/sendData" // the URL to post to // @"http://169.254.121.227:51417/Service1.svc/sendData" , content // the form values , "application/xml" // the mime type for an HTTP form ); // Post the form request.ResponseReceived += new HttpRequest.ResponseHandler(SendData_ResponseReceived); request.SendRequest(); while (!request.IsReceived) { ; } // Debug.Print("DEVO FINIRE ThREAD"); } catch (System.ApplicationException a) { DrawConnetorsAlarmWindow(); return; } catch (System.Exception) { DrawConnetorsAlarmWindow(); return; }/* //ingestibile * catch (Exception e) * { * Debug.Print("Trovato eccezione" + e.Message); * server_available = false; * timerRetryServer.Tick += RetryServer; * timerRetryServer.Start(); * return; * }*/ } return; }
private void timer_TakeMeasure(GT.Timer timer) { Debug.Print("Measuring conditions ... "); GT.Timer t = new GT.Timer(300); t.Tick += timer_blinkLed; t.Start(); TempHumidSI70.Measurement m = temp.TakeMeasurement(); double l = light.ReadProportion(); int mois = moisture.ReadMoisture(); Debug.Print("Measurement --- Light " + l + " - Temperature " + m.Temperature + " - Moisture " + mois); if (!NETWORK_UP) { Debug.Print("Network down... not sending data to server."); } else { Debug.Print("Sending data to server...."); Debug.Print("Attempt B1 - Sending data to server using just POST...."); POSTContent emptyPost = new POSTContent(); String pathA = httpPath + "SmartService.svc/web/Measurements/Create/" + m.Temperature.ToString().Substring(0, 4) + "/" + l.ToString().Substring(0, 4) + "/" + mois.ToString() + "/"; var reqA = HttpHelper.CreateHttpPostRequest(pathA, emptyPost, null); Debug.Print("HTTP request to server: " + pathA); reqA.ResponseReceived += new HttpRequest.ResponseHandler(req_ResponseReceived); reqA.SendRequest(); } Thread.Sleep(1000); t.Stop(); ledStrip.SetLed(MEASUREMENT_LED, false); if (AUTOPILOT && !IRRIGATING && checkIrrigationNecessary(m.Temperature, l, mois)) { irrigate(); } }
private void DrawMainWindow() { try { lock (myLock) { window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.MainWindow));//carico window da mostrare GlideTouch.Initialize(); //read sensors TempHumidSI70.Measurement temp = tempHumidSI70.TakeMeasurement(); double gas = gasSense.ReadProportion(); if (!noAlarm) { //check data on anomalia if (gas > 1 || temp.Temperature > 70 || temp.RelativeHumidity > 100) { //ALARM //n.b. Se durante attention message lui si connete/disconnette alla rete sara revisualizzato Main!!!! //mandare subito errore sendData(); timerMain.Tick -= DrawMainWindow; timerMain.Stop(); Thread.Sleep(navigation_delay); DrawAlarmWindow(temp.Temperature, temp.RelativeHumidity, gas); noAlarm = true; ResetNoAlarm.Tick += ActivateAlarm; ResetNoAlarm.Start(); return; } } //fill stuff TextBox temp_box = (TextBox)window.GetChildByName("tempvalue"); temp_box.Text = temp.Temperature.ToString("F2"); TextBox umid_box = (TextBox)window.GetChildByName("umidvalue"); umid_box.Text = temp.RelativeHumidity.ToString("F2"); TextBox gas_box = (TextBox)window.GetChildByName("gasvalue"); gas_box.Text = gas.ToString("F2"); //show connection type TextBlock conn_type = (TextBlock)window.GetChildByName("context"); if (connection) { conn_type.Text = "WiFi"; } else { conn_type.Text = "RJ45"; } //show connection status TextBlock conn_true = (TextBlock)window.GetChildByName("constatustrue"); TextBlock conn_false = (TextBlock)window.GetChildByName("constatusfalse"); if (connected) { conn_true.Visible = true; conn_false.Visible = false; } else { conn_true.Visible = false; conn_false.Visible = true;; } //show server status TextBlock server_true = (TextBlock)window.GetChildByName("serverstatustrue"); TextBlock server_false = (TextBlock)window.GetChildByName("serverstatusfalse"); if (server_available) { server_true.Visible = true; server_false.Visible = false; } else { server_true.Visible = false; server_false.Visible = true;; } //gas on off button gas_state = (CheckBox)window.GetChildByName("gasonoff"); gas_state.Checked = gasSense.HeatingElementEnabled; gas_state.TapEvent += gasonoff; //back to connections button back_to_con = (Button)window.GetChildByName("backtocon"); back_to_con.TapEvent += GoToConnections; //go to menu go_to_menu = (Button)window.GetChildByName("menu"); go_to_menu.TapEvent += GoToMenu; //if need to write ip of board use //string ip=wifiRS21.NetworkInterface.IPAddress; Glide.MainWindow = window; return; } } catch (System.ApplicationException) { DrawConnetorsAlarmWindow(); return; } catch (System.Exception) { DrawConnetorsAlarmWindow(); return; } }