2 Replies Latest reply on Apr 8, 2015 7:42 AM by noris1

    Sending bits to 000host via HTTP GET

    noris1

      hello people :) !

      i'm working on controling my Arduino Galileo via   server.

      My goal is to communicate between Android App and my Arduino via a server.

      I succede to connect to my server , and i'm trying send Get requests and resecive an answer from it.


      the code:

       

       

      #include <Ethernet.h>

      #include <SPI.h>

      char r;

      int led = 13;

      //-------------

      byte mac[] = { 0x98, 0x4F, 0xEE, 0x00, 0x2A, 0xC7 };

      EthernetClient googleClient;

      void setup()

      {

      pinMode(led,OUTPUT);

      system("/etc/init.d/networking restart");

       

      Serial.begin(9600);

      delay(2000);

      Serial.println("connecting...");

       

      if (googleClient.connect("www.eeproject.site50.net", 80)) {

         Serial.println("connected");

          digitalWrite(led, HIGH);

          // Make HTTP request

      googleClient.println("GET /hello.php?val=7 HTTP/1.0");   

      googleClient.println("HOST: www.eeproject.site50.net");

      googleClient.println();

      }

      else {

         Serial.println("connection failed");

          digitalWrite(led, LOW);

      }


      }

        void con(){

         if (googleClient.available()) {

         char c = googleClient.read();

         Serial.print(c);

      }

       

      if (!googleClient.connected()) {

         Serial.println();

         Serial.println("disconnecting.");

         googleClient.stop();

         for(;;)

           ;

      }

      }

      void loop()

      {

         con();

      }


      /---------------------------

      this is what i recive :connecting...

      connected

      HTTP/1.1 200 OK

      Date: Mon, 06 Apr 2015 21:30:00 GMT

      Server: Apache

      X-Powered-By: PHP/5.2.17

      Content-Length: 164

      Connection: close

      Content-Type: text/html

       

      7it works!

      <!-- Hosting24 Analytics Code -->

      <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>

      <!-- End Of Analytics Code -->

       

       

      /- ---------------------------------------------------------------

       

      but when i try menualy send GET requests via serial monitor i get this:


      the new code:

       

       

      #include <Ethernet.h>

      #include <SPI.h>

      char r;

      int led = 13;

      byte mac[] = { 0x98, 0x4F, 0xEE, 0x00, 0x2A, 0xC7 };

      EthernetClient googleClient;

      void setup()

      {

      pinMode(led,OUTPUT);

      system("/etc/init.d/networking restart");

      Serial.begin(9600);

      delay(2000);

      Serial.println("connecting...");

       

      if (googleClient.connect("www.eeproject.site50.net", 80)) {

         Serial.println("connected");

          digitalWrite(led, HIGH);

          // Make HTTP request

      googleClient.println("GET /hello.php HTTP/1.0");   

      googleClient.println("HOST: www.eeproject.site50.net");

      googleClient.println();

      }

      else {

         Serial.println("connection failed");

          digitalWrite(led, LOW);

      }

      }

      void send(int a){ // send GET request

      googleClient.println("GET /hello.php?val=a HTTP/1.0");   

      googleClient.println("HOST: www.eeproject.site50.net");

      googleClient.println();

      Serial.print("Sent the http request with  ");

      Serial.println(a);

      }

      void con(){

         if (googleClient.available()) {

         char c = googleClient.read();

         Serial.print(c);

      }

       

      if (!googleClient.connected()) {

         Serial.println();

         Serial.println("disconnecting.");

         googleClient.stop();

         for(;;)

           ;

      }

      }

      void loop()

      {

      con();

      if(Serial.available() > 0){

         r=Serial.read();

        send(r);

      delay(1000);

        con();

      }

      }


       

      i enter the numbet 7 so i can send GET and recive an answer and i get this:

       

      connecting...

      connected

      HTTP/1.1 200 OK

      Date: Mon, 06 Apr 2015 21:35:45 GMT

      Server: Apache

      X-Powered-By: PHP/5.2.17

      Content-Length: 163

      Connection: close

      Content-Type: text/html

       

      it works!

      <!-- Hosting24 Analytics Code -->

      <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>

      <!-- End Of Analytics Code -->

      Sent the http request with  7

      Sent the http request with 

       

      Sent the http request with 

       

      /-----------------------------------------------------------------------------------

      there is a way to send GET requests after the first connection,so i dont to connect and disconnect to the server?

      or sending GET requests via serial monitor is wrong?

       

      /---------------------- php code

       


      <?php

      echo $_GET["val"];
      echo
      "it works!";

      ?>


      many tanks