Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to send a URL over to ESP8266. Instead of sending the URL, I receive the entire webpage HTML and Javascript codes.

Here's my javascript code on my page:

jQuery(function($) {$("button").click(function(){
    newurl = '/index.php?btn='+ this.id; //I WANT THIS....
    sendHttpRequest(newurl);
    });
});

function sendHttpRequest(update){
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
          console.log(xhttp.responseText);
        }
    }
    xhttp.open("GET",update);
    xhttp.send(null);
}

And for my ESP8266 in my loop

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" + 
             "Connection: close\r\n\r\n");

  while(!client.available()){
    delay(10);
  }

  while(client.available()){
    String request = client.readStringUntil('\r');
    Serial.println(request);
  } 
  Serial.println("closing connection");
share|improve this question
    
Um... what? I really don't have a scooby what you are asking there. – Majenko Mar 20 at 18:44
    
I want the URL parameter that I am sending, not extracting the entire webpage. – user3232194 Mar 20 at 18:52
    
If you GET a web page you will get the web page. If you want your web page to send an unsolicited request to your ESP8266 (which I think is what you want) then you don't GET that request, you act as a web server and wait for the request to come in. – Majenko Mar 20 at 18:53
    
okay can you expand on that? Point me a direction where i should go? I want the parameter from the url. – user3232194 Mar 20 at 18:55
1  
Yes but then you were looking for the wrong thing. Now you know you need to look at the http server examples. – Majenko Mar 20 at 19:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.