So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Andu
#65263 I'm trying to compare every line of the HTTP response to change the state of a relay. I know it's not ideal and there are more elegant ways to do it but for the moment I just need a working prototype to test the module.

the code I have is this:
Code: Select all// Read the entire response and flush it to Serial output
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
    if(!strcmp(line.c_str(),"OFF")){
      Serial.println(" -> True");
    } else {
      Serial.println(" ->  False");
    }


-> False is returned for everything

Code: Select allRequest sent - waiting for reply...
HTTP/1.1 200 OK -> False

Content-Type: text/html; charset=UTF-8 -> False

Content-Length: 3 -> False

Date: Tue, 25 Apr 2017 18:02:28 GMT -> False

Accept-Ranges: bytes -> False

Server: LiteSpeed -> False

Connection: close -> False

 -> False

OFF -> False

Connection closed.
User avatar
By jeffas
#65387 That makes sense. Your client is send CR/LF to terminate lines (as is common in HTTP, indeed mandatory for headers), You are reading each line up to and including the CR, which leaves the NL still in the buffer to be read.