Skip to content

website doesn't show up with core 2.4.2, neither 2.4.1 ... - but correctly with 2.3.0 and 2.4.0 though #5021

Closed
@dsyleixa

Description

@dsyleixa

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12E]
  • Core Version: [Board Manager 2.4.2]
  • Development Env: [Arduino IDE|]
  • Operating System: [Windows|

Settings in IDE

  • Module: [Nodemcu 1.0]
  • Flash Mode: [qio|dio|other]
  • Flash Size: [4MB]
  • lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mh
  • Upload Using: SERIAL]
  • Upload Speed: [115200|] (serial upload only)

Problem Description

the following function provides a website to login (username, password). It is called if the website url is loaded and a global variable "authorized" is still "false".
If login is correct, the global variable "authorized" is set to true, and the full website is displayed,
Admittedly surely not perfect, it actually works fine with core 2.3.0,
but now as I have changed to core 2.4.2 this website does not appear any more,
instead an error html website appears claiming the server is unreachable
("Error: Connection interrupted
The connection to the server was reset while the page was loading.")

Switching back to core 2.3.0 and recompiling, it's fine again.

What do I miss about the new core or the required new coding?

MCVE Sketch

// latest version: still faulty for 2.4.2, still fine with 2.4.0

void handleNotAuthorized() {
  String readString = "";
  char   strinput[MAXLEN], strupwd[TOKLEN], struname[TOKLEN] ;
  
  WiFiClient client = wifiserver.available();

  //---------------------------------------
  // debug
  // authorized=true;

  strcpy(strinput, "");
  strcpy(strupwd, "");
  strcpy(struname, "");

  while ( client.connected() ) {
    if (authorized) return;

    if ( client.available() ) {
      char c = client.read();

      //read char by request
      readString = "";
      while ( (readString.length() < TOKLEN) && (c != '\n') ) {
          readString += c;
          c = client.read();
      }

    readString.toCharArray(strinput, MAXLEN);
    // cstringarg( char* haystack, char* vname, char* sarg )
    // haystack pattern: &varname=1234abc,  delimiters &, \n, \0, SPACE, EOF
    cstringarg(strinput, "uname", struname);  // uname
    cstringarg(strinput, "upwd", strupwd);   // upwd

    // debug
    Serial.print("strupwd     >>>"); Serial.print(strupwd); Serial.println("<<<");
    Serial.print("website_upwd>>>"); Serial.print(website_upwd); Serial.println("<<<");
    Serial.print("readString>>>");Serial.println(readString);

    if ( (strlen(strupwd) == strlen(website_upwd)) && (strcmp(website_upwd, strupwd) == 0) )
    {
      authorized = true;
      //debug
      //Serial.print("check: authorized="); Serial.println(authorized);
      readString = "";
      return;
    }   
      
      //if HTTP request has ended
      if (c == '\n') {
         client.flush();  // <-- useless here, this empties the output buffer, not the input 

        //now output html data header
        String script = "";

        script += ("HTTP/1.1 401 Log-In Required");
        script += ("Content-Type: text/html \n");
        script += ("\n");  //  do not forget this one //????
        script += ("<!DOCTYPE html> \n");
        script += ("<html> \n");
        script += ("<head> \n");

        // utf-8 für "°" Zeichen
        script +=  "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n" ;
        script +=  "<title>" ;
        script +=  website_title ;
        script +=  "</title> \n" ;
        script +=  "</head> \n" ;
        script +=  "<body> \n" ;

        script += "<h1><p style=\"color:rgb(255,0,191);\"> " + (String)website_url ;
        script += (String)": &nbsp; <wbr> <wbr> " + "Not authorized !</p> </h1> \n" ;
        script += ("<h2><p style=\"color:rgb(255,0,191);\"> log in to proceed: </p> </h2> \n");

        script += ("<FORM ACTION='/' method=GET > \n");
        script += ("<h2>user name:  <INPUT TYPE=text NAME='uname' VALUE=''  MAXLENGTH='50'> </h2> \n");
        script += ("<h2>password :  <INPUT TYPE=PASSWORD NAME='upwd' VALUE='' MAXLENGTH='50'> </h2> \n");

        script += ("<h2><INPUT TYPE=SUBMIT></h2> \n");

        script += ("</FORM> \n");
        script += ("<BR> \n");
        script += ("</body> \n");
        script += ("</html> \n");

        client.print(script);

        //stopping client
        client.stop();
        delay(1);
      }
    }
    delay(1);
  }
}

Debug Messages

 core 2.4.2 error: 
 this website does not appear any more at all, 
instead an error html website appears claiming the server is unreachable
("Error: Connection interrupted
The connection to the server was reset while the page was loading.")

Switching back to core 2.3.0 and recompiling, it's fine again.

Metadata

Metadata

Assignees

Labels

waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions