Skip to content

server.send send unexpected argument migrating from 2.4.x to 2.5.2 #6435

@Sparatutto

Description

@Sparatutto

Basic Infos

  • I have read the documentation at readthedocs and the issue is not addressed there.

  • I have searched the issue tracker for a similar issue.

Platform

  • Hardware: Amica NudeMCU
  • Core Version: 2.5.2 downloaded by Arduino board manager
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

attached picture
setting-

Problem Description

I have updated the Arduino IDE to 1.8.9 and the core to 2.5.2 using the board manager ( not the git).
Compiling my project that was working and running very stable with the core 2.4.x now I'm facing some issue related to the number of argument returned by the http communication.
In particular I see an extra argument named plain received by the AP, that was not present and transferred before.
So expected number of arguments (correct in the last compile with 2.4.x) in this example was 3, instead with the new core I get 4.
extraarg

And this is making me crazy because I have many pages and not sure what is happening.

Maybe it is a stupid error of mine but having it in conjunction to the switch to this new core, I try to write you for a check.
Thanks!

MCVE Sketch

#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>

#define BLUELED 02 

WiFiClient client;
ESP8266WebServer server(80);

void setup() 
{

	/*****************************/
	Serial.begin(115200);
	Serial.setDebugOutput(true);
	delay(10);

	Serial.println("Start! ....");

	Serial.println(F("Access point mode selected"));
	WiFi.mode(WIFI_AP);
	WiFi.softAPConfig(IPAddress(192,168,1,1),IPAddress(192,168,1,1),IPAddress(255,255,255,0));
	WiFi.softAP("MyAPN","12345678");
	Serial.println(F("Access point mode started"));
	IPAddress myIP = WiFi.softAPIP();
	Serial.print(F("AP IP address: "));
	Serial.print(myIP);
	Serial.println(F(" - PWD:12345678"));

	server.on("/", handleRoot);
	server.on("/setting",handleSetting);
	// Start the server
	server.begin(); //server.begin(sysSetting.httpPort);   //
}


void loop() 
{
	server.handleClient();
	digitalWrite(BLUELED,(digitalRead(BLUELED)?LOW:HIGH));
	delay(100);
	return;
}



/******************************************************************************
* Function: debugArgum
*
* Print to the serial the received arguments of the client/server http comm
*
* Parameters:                
*             header and argum set to 'y' means print to serial            
* Return:                 
*             none            
******************************************************************************/
void debugHeaderArgum(char header, char argu)
{
  String argum = "";
  int cnt;
  if(header =='y')
  {
    for (cnt = 0; cnt < server.headers(); cnt++) 
    {
      argum = "HeadArg: " +(String)cnt + " - " + server.headerName(cnt) + " - " + server.header(cnt);
      Serial.println(argum);
    }
  }
  if(argu =='y')
  {
    for (cnt = 0; cnt < server.args(); cnt++) 
    {
      argum = "Arg: " +(String)cnt + " - " + server.argName(cnt) + " - " + server.arg(cnt);
      Serial.println(argum);
    } 
  }
}

void handleRoot() 
{
	String argum = "";
	int cnt = 0;

	debugHeaderArgum('n','n'); //show header and argument

	Serial.println(F("APN - param page"));
	argum = F("HTTP/1.1 301 OK\r\nLocation: /setting\r\nCache-Control: no-cache\r\n\r\n");
	server.sendContent(argum);
	return;
}

/******************************************************************************
* Function: moduleInfo
*
* general module info usable in serial port and http.
*
* Parameters:                
*             httpmode: is true the {t] will be replaced with <DIV> and {-t} with </DIV> otherwise with \r\n             
* Return:                 
*             string containing the info            
******************************************************************************/
String moduleInfo(bool httpMode)
{
	byte mac[6];
	char tmpBuff[100];
	String retString = "\r\n{t}xxx Module: " +(String)ESP.getChipId() + "{-t}\r\n{t}Module ID: 10 - test {-t}\r\n";
	
    WiFi.macAddress(mac);
	sprintf(tmpBuff,"{t}MAC Address: %02X:%02X:%02X:%02X:%02X:%02X{-t}\r\n",mac[5],mac[4],mac[3],mac[2],mac[1],mac[0]);
	retString += (String)tmpBuff + "{t}Firmware version: x.x {-t}\r\n";
   
    // print the received signal strength:
    long rssi = WiFi.RSSI();
    retString += "{t}Signal strength (RSSI): " + (String)rssi + "dBm{-t}\r\n";
    
    uint32_t realSize = ESP.getFlashChipRealSize();
    uint32_t ideSize = ESP.getFlashChipSize();
    FlashMode_t ideMode = ESP.getFlashChipMode();
    sprintf(tmpBuff,"{t}Flash: Real size: %u - IDE Size: %u - IDE speed: %u{-t}\r\n", realSize, ideSize, ESP.getFlashChipSpeed());
	retString += (String)tmpBuff ;
    sprintf(tmpBuff,"{t}Flash IDE mode:  %s{-t}\r\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
	retString += (String)tmpBuff ;
	if(httpMode)
	{
		retString.replace("{t}","<DIV>");
		retString.replace("{-t}","</DIV>");
	}
	else
	{
		retString.replace("{t}","");
		retString.replace("{-t}","");
	}
	return retString;	
}



/******************************************************************************
* Function: handleSetting
*
* Handle the connection to the configuration page used in APN and normal operation
*
* Parameters:                
*             none            
* Return:                 
*             none            
******************************************************************************/
void handleSetting()
{
	
	String decodeDst = "";
	server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
	server.sendHeader("Pragma", "no-cache");
	server.sendHeader("Expires", "-1");
	server.sendHeader("Host", "192.168.1.1");
	server.setContentLength(CONTENT_LENGTH_UNKNOWN);
	
	String webApn = F("<!DOCTYPE HTML>\r\n<html>\r\n<head>\r\n<title>Dommy</title>\r\n");                      
	webApn += F("<style type=\"text/css\">\r\n body {background: white; color: black; text-align: center} ");
	webApn += F(" form { color: blue; text-align: center}\r\n div {color: black; text-align: left}\r\n");
	webApn += F(" h1 { color: green; font: 36px Helvetica, Arial, sans-serif;}\r\n</style>\r\n</head>\r\n");

	debugHeaderArgum('n','y');
	
	if(server.args()== 3)
	{

		Serial.println(server.arg("ARG1"));

		Serial.println(server.arg("ARG2"));

		Serial.println(server.arg("ARG3"));

		ESP.wdtFeed(); // to ensure the wdt doesn't trigger
		webApn += F("<body><DIV></DIV><DIV>Module updated.</DIV>\r\n<DIV>It is restarting.</DIV>");
		webApn += "<DIV> <a href='http://www.xxxxxxx.yyy:8080'> Return to the main page </a> </DIV></body>\r\n</html>\r\n"; 
		//server.send(200, "text/html",webApn);
		server.send(200, "text/html", ""); 
		server.sendContent(webApn);
		server.sendContent("");
		delay(500);
		ESP.restart();
		return;
	}
	else if(server.args()> 3)
	{
		Serial.println("Wrong arg number!!");
	}
 // String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html Cache-Control: no-cache\r\n\r\n";
 //   server.sendContent(header);
    

  webApn += F("<body>\r\n<form name='Setting' method='POST'>\r\n");      
  webApn += F("<table width='60%' border='0' cellspacing='5' cellpadding='5'>\r\n");
  webApn += F("<tr><td width='10%' valign='center'><h1>xxx Module Config</h1></td></tr>\r\n");
 
  webApn += "<tr><td width='10%' valign='center'>" + moduleInfo(true) + "</td></tr></table>\r\n";
  webApn += F("<table width='60%' border='0' cellspacing='5' cellpadding='5'>\r\n"); 
  webApn += F("<tr><td valign='center'>ARG1</td></tr>\r\n");  
  webApn += F("<tr><td valign='center'><input type='text' name='ARG1' size='2' maxlength='2' value='1'></td></tr>\r\n");  
  webApn += F("<tr><td valign='center'> ARG2 (no space but '_')</td></tr>\r\n");
  webApn += F("<tr><td valign='center'> \r\n<input type='text' name='ARG2' size='20' maxlength='20' value='2'><br></td>\r\n</tr>\r\n");
  
  webApn += F("<tr>\r\n<td valign='center'>ARG3 - max 25\r\n</td>\r\n</tr>\r\n");
  webApn += F("<tr>\r\n<td valign='center'>\r\n<input type='text' name='ARG3' size='25' maxlength='25' value='test'><br></td>\r\n</tr>\r\n");
   
  webApn += F("<tr>\r\n<td valign='center'>\r\n<input type=submit value='Update'>\r\n</td>\r\n</tr>\r\n</table>\r\n</form>\r\n</body>\r\n</html>"); 
  server.send(200, "text/html",webApn);
}

Debug Messages

Debug messages go here

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions