1

I am trying to open load a webpage from ESP8266 that displays temperature and humidity of my room if I only type root URL:192.168.1.89

GET / HTTP/1.1
Host: 192.168.1.89
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50
Accept-Language: en-us
DNT: 1
Accept-Encoding: gzip, deflate

to do that in my esp8266 sketch I am trying this logic:

bool readRequest(WiFiClient& client) {
  bool currentLineIsBlank = true;
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      if (c == "GET / HTTP/1.1"){
        Serial.println("Got root");
        client.println(handleRoot()); // where handle root contains web page
      }
      else{
        Serial.println("Did not got root.");
      }
      if (c == '\n' && currentLineIsBlank) {

        return true;
      } else if (c == '\n') {
        currentLineIsBlank = true;
      } else if (c != '\r') {
        currentLineIsBlank = false;
      }
    }
  }
  return false;
}

but the condition to check if it met GET / HTTP/1.1 never validates.

5
  • 2
    c is a char. You can't compare a char to a string. And c == "GET... is not how you compare string in C, anyway.
    – user31481
    Commented Nov 23, 2017 at 14:54
  • Just use a HTTP server library.
    – gre_gor
    Commented Nov 23, 2017 at 14:58
  • @gre_gor in a different project I am using ESP8266WebServer but I want ed to give a try to WiFiServer server(80); while sticking with ArduinoJson.h library as well. Commented Nov 23, 2017 at 15:06
  • 1
    This applies to networking as well as serial. Also this may be of use to you, along with this.
    – Majenko
    Commented Nov 23, 2017 at 15:30
  • @gre_gor I switched back to ESP8266WebServer.h however I cannot pass ArduinoJson.h's jsonObject to server.send(...) arduino.stackexchange.com/q/46961/27363 Commented Nov 23, 2017 at 16:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.