Exemplo n.º 1
0
 public static void GetMeasurements(HttpRequest.ResponseHandler responseHandler)
 {
     var getRequest = WebHelper.CreateGetRequest("/Measurements");
     WebHelper.AddAuthorizationHeaders(getRequest);
     getRequest.ResponseReceived += responseHandler;
     getRequest.SendRequest();
 }
Exemplo n.º 2
0
        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            sensorState = (sensorState.Equals("0")) ? "1" : "0";
            Debug.Print(sensorState);
            PUTContent emptyPut = new PUTContent();

            Gadgeteer.Networking.HttpRequest req = HttpHelper.CreateHttpPutRequest("http://" + rpi + ":9090/gadgeteer/state/" + sensorState + "/", emptyPut, null);
            req.SendRequest();
        }
Exemplo n.º 3
0
        void pollState()
        {
            while (true)
            {
                String newState = (pir.SensorStillActive) ? "1" : "0";

                if (!newState.Equals(sensorState))
                {
                    sensorState = newState;
                    Debug.Print(sensorState);
                    PUTContent emptyPut = new PUTContent();
                    Gadgeteer.Networking.HttpRequest req = HttpHelper.CreateHttpPutRequest("http://" + rpi + ":9090/gadgeteer/state/" + sensorState + "/", emptyPut, null);
                    req.SendRequest();
                }
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 4
0
 void pollLight()
 {
     while (true)
     {
         double lightPercent = lightSensor.ReadLightSensorPercentage();
         Debug.Print(lightPercent.ToString());
         String newState = (lightPercent >= 50) ? "1" : "0";
         Debug.Print(newState);
         if (!sensorState.Equals(newState))
         {
             sensorState = newState;
             Debug.Print(sensorState);
             PUTContent emptyPut = new PUTContent();
             Gadgeteer.Networking.HttpRequest req = HttpHelper.CreateHttpPutRequest("http://" + rpi + ":9090/gadgeteer/state/" + sensorState + "/", emptyPut, null);
             req.SendRequest();
         }
         Thread.Sleep(1000);
     }
 }
 void DownloadUpdate()
 {
     //this method for downloading updated app, make sure your board is connected to the network
     Gadgeteer.Networking.HttpRequest wc = WebClient.GetFromWeb("http://yourweb.com/firmware.hex");
     wc.ResponseReceived += new HttpRequest.ResponseHandler(wc_ResponseReceived);
 }
Exemplo n.º 6
0
 private static void ResponseReceived(HttpRequest sender, HttpResponse response)
 {
     Debug.Print("Network Response");
     Debug.Print("Status Code: " + response.StatusCode);
     //Debug.Print("Text: " + response.Text);
 }
Exemplo n.º 7
0
 private static void AddAuthorizationHeaders(HttpRequest getRequest)
 {
     var headerValue = GetAuthHeaderValue(UserName, Password);
     getRequest.AddHeaderField("Authorization", headerValue);
 }
Exemplo n.º 8
0
        private void ServerResponseCallback(HttpRequest sender, HttpResponse response)
        {
            Debug.Print("Event: received response from server.");
            Debug.Print("Status code: " + response.StatusCode);
            Debug.Print("Content: " + response.Text);

            if (response.StatusCode != "200")
                return;

            var hashtable = JsonSerializer.DeserializeString(response.Text) as Hashtable;
            int status;
            int person;
            try
            {
                Debug.Print("Order to take care of ? " + hashtable["CurrentStatus"]);
                Debug.Print("Customer: " + hashtable["Person"]);
                status = Int32.Parse(hashtable["CurrentStatus"].ToString());
                person = Int32.Parse(hashtable["Person"].ToString());
            }
            catch (System.NullReferenceException ex)
            {
                Debug.Print("Invalid JSON response");
                return;
            }

            switch (status)
            {
                case (int)CurrentStatus.Idle:
                    Debug.Print("No order");
                    break;
                case (int)CurrentStatus.Busy:
                    switch (person)
                    {
                        case (int)People.Toby:
                            Debug.Print("Go to Toby");
                            train.Go(Stations.TobyStation);
                            break;
                        case (int)People.Tristram:
                            Debug.Print("Go to Tristram");
                            train.Go(Stations.TristramStation);
                            break;
                    }
                    break;
            }
        }
        void StatusPostsReceived(HttpRequest sender, HttpResponse response)
        {
            Debug.Print("Status Posts Recieved: ");
            Debug.Print(response.StatusCode);

            // Blank out the "Updating" message
            _loggerDisplay.ShowMessage("", 10, StatusYPosition);

            if (response.StatusCode == "200")
            {
                Debug.Print("OK");
                Debug.Print(response.Text);

                var statusPosts = Json.NETMF.JsonSerializer.DeserializeString(response.Text) as ArrayList;
                if (statusPosts != null)
                {
                    ProcessStatusMessages(statusPosts);
                }
            }
        }
Exemplo n.º 10
0
        void request_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            switch (opcion)
            {
                case "tiempo":
                    textotemp.Text = "Esperando ...";
                    timer.Start();
                    respuesta = response.Text;
                    Double horaLocal = 0;
                    String horaStr = "";
                    XmlReader xmL = XmlReader.Create(response.Stream);
                    while (xmL.Read())
                    {
                        if ((xmL.NodeType == XmlNodeType.Element) && (xmL.Name == "timestamp"))
                        {

                            horaStr = xmL.ReadElementString();
                            horaLocal = Double.Parse(horaStr);
                            horaStr = UnixTimeStampToDateTime(horaLocal);

                        }

                    }
                    respuesta = horaStr;
                    String[] res = respuesta.Split(' ');
                    tiempo = horaLocal;
                    fechatext.Text = res[0];
                    textotemp.Text = res[1];

                    break;
                case "temperatura":

                    int celsius = 0;
                    Double C;
                    String celsiusStr = "";
                    String clima = "";
                    XmlReader xmLtemp = XmlReader.Create(response.Stream);
                    while (xmLtemp.Read())
                    {
                        if ((xmLtemp.NodeType == XmlNodeType.Element) && ((xmLtemp.Name == "temperature") || (xmLtemp.Name == "weather")))
                        {
                            if (xmLtemp.HasAttributes)
                            {
                                if (xmLtemp.Name == "temperature")
                                {
                                    celsiusStr = xmLtemp.GetAttribute("value");
                                    C = Double.Parse(celsiusStr);
                                    celsius = (int)(C - 273.15);
                                }
                                else if (xmLtemp.Name == "weather")
                                {
                                    clima = xmLtemp.GetAttribute("value");
                                }

                            }
                        }

                    }
                    temp.Text = celsius.ToString();
                    msm.Text = clima;

                    break;
                case "noticias":

                    XmlReader rssXmlDoc = XmlReader.Create(response.Stream);
                    while (rssXmlDoc.Read())
                    {
                        if ((rssXmlDoc.NodeType == XmlNodeType.Element) && (rssXmlDoc.Name == "item"))
                        {
                            intnoticias=0;
                            ix = 0;
                            while (rssXmlDoc.Read())
                            {

                                if ((rssXmlDoc.NodeType == XmlNodeType.Element) && (rssXmlDoc.Name == "title"))
                                {
                                    if (ix < 10)
                                    {
                                        s2[ix] = rssXmlDoc.ReadElementString();

                                        ix++;
                                    }
                                }

                            }

                        }

                    }
                    Debug.Print(removerAcentos(s2[intnoticias]));
                    n1.Text = removerAcentos(s2[intnoticias]);
                    n2.Text = removerAcentos(s2[intnoticias+1]);

                    break;
                default:
                    break;

            }
        }
Exemplo n.º 11
0
        private void handshake_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            websocketConnectionUp = false;
            Debug.Print("got response:");
            Debug.Print(response.Text);
            string[] parts = (response.Text).Split(':');
            if (parts.Length < 4)
            {
                throw new Exception("Error in socket.io handshake - wrong number of arguments received!");
            }
            else
            {
                session_id = parts[0];
                Debug.Print("Session ID: " + session_id);

                // updates the new session id to the uri
                update_socketio_uri();

                // sends connect through ws
                websocketConnectionUp = true;
                send_connect();
            }
        }
Exemplo n.º 12
0
 void request_ResponseReceived(HttpRequest sender, HttpResponse response)
 {
     var x = response.Text;
     Debug.Print(x);
     temp = (TextBlock)Glide.MainWindow.GetChildByName("texto_temperatura");
     temp.Text = x;
     sliderBar = (Slider)Glide.MainWindow.GetChildByName("slider");
     sliderBar.Value = Convert.ToDouble(x);
     Glide.MainWindow = temperatura;
 }
 void req_ResponseReceived(HttpRequest sender, HttpResponse response)
 {
     UserInterface.Instance.log(response.Text);
 }
Exemplo n.º 14
0
 public static void AddAuthorizationHeaders(HttpRequest getRequest)
 {
     var auth = GetAuthHeaderValue(Globals.UserName, Globals.Password);
     getRequest.AddHeaderField("Authorization", auth);
 }
Exemplo n.º 15
0
        void req_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            Debug.Print("SolarPulse - Data sent");

            lightTimer.Start();
        }
Exemplo n.º 16
0
 void request_ResponseReceived(HttpRequest sender, HttpResponse response)
 {
     respuesta = response.Text;
     Debug.Print(respuesta);
     // btn_inicio.Text = respuesta;
     textotemp.Text = respuesta;
     barra.Value = (int)Double.Parse(respuesta);
     Glide.MainWindow = pantallaTemperatura;
 }
Exemplo n.º 17
0
        void pedido_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            //if (response.StatusCode == "202")         {

                var resultado = response.Text;

                Debug.Print(resultado);

            /*
                String r = GetUrlFromJson(resultado.ToString());
                if (r != String.Empty && r.Length > 2 && r != "null")
                {
                    GHI.Glide.UI.TextBlock text = (GHI.Glide.UI.TextBlock)resultWindow.GetChildByName("TxtResult");
                    text.Text = r;
                    Glide.MainWindow = resultWindow;
                }
                else
                {
                    timerPictureCaptured.Start();
                }

            */
                //HttpRequest pedido = HttpHelper.CreateHttpGetRequest(GetUrlFromJson(resultado.ToString()));
                //pedido.ResponseReceived += pedido_ResponseReceived;
                //pedido.SendRequest();
                //Debug.Print(resultado);
                //Debug.Print("Enviando Url de QR");
            //}
        }
Exemplo n.º 18
0
 private void MeasurementPostCompleted(HttpRequest sender, HttpResponse response)
 {
     if (response.StatusCode == "201")
     {
         _loggerDisplay.ClearMessage(0, StatusYPosition);
         Debug.Print("Measurements send OK.");
     }
     else
     {
         _loggerDisplay.ShowErrorMessage("Error: " + response.StatusCode, 10, StatusYPosition);
         Debug.Print("HttpCode: " + response.StatusCode);
         Debug.Print("Error :" + response.Text);
     }
 }