Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty reply from server / no data found for resource with given identifier #8646

Closed
mofada opened this issue Jul 21, 2022 · 13 comments · Fixed by #8598
Closed

Empty reply from server / no data found for resource with given identifier #8646

mofada opened this issue Jul 21, 2022 · 13 comments · Fixed by #8598

Comments

@mofada
Copy link

mofada commented Jul 21, 2022

Platform

  • Hardware: [ESP-12|ESP-01|ESP-07|ESP8285 device|other]
  • Core Version: [latest git hash or date]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Wemos D1 mini r2]
  • 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: [80Mhz|160MHz]
  • Upload Using: [OTA|SERIAL]
  • Upload Speed: [115200|other] (serial upload only)

Problem Description

expected

I wrote a piece of code to connect to WiFi via http and when I enter the correct ssid and password everything works as expected.

{"message":"connect success!","code":0,"data":{"ssid":"fada","password":"fada-8888","rssi":-62,"localIP":192.168.0.103,"deviceId":6303019}}

fail

When I pass in a non-existing ssid, or a wrong password
chrome no data found for resource with given identifier

C:\Users\fada>curl http://192.168.4.1/wifi?ssid=fada1
curl: (52) Empty reply from server`

My expected return:
{"message":"wifi password wrong!","code":203}

code

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

ESP8266WebServer esp8266_server(80);

void setup()
{
  Serial.begin(9600);

  WiFi.mode(WIFI_STA);
  WiFi.softAP("khc-" + String(ESP.getChipId()), "88888888");

  // start server
  esp8266_server.begin();
  esp8266_server.keepAlive(true);
  esp8266_server.on("/wifi", HTTP_GET, handlePutWifi);

  WiFi.printDiag(Serial);
  Serial.setDebugOutput(true);
}

void loop()
{
  esp8266_server.handleClient();
}

/**
   @brief connect wifi

*/
void handlePutWifi()
{
  if (!esp8266_server.hasArg("ssid"))
  {
    // check params
    esp8266_server.send(200, "application/json;charset=utf-8", "{\"message\":\"message is required\",\"code\":-1}");
    return;
  }

  // get params
  String ssid = esp8266_server.arg("ssid");
  String password = esp8266_server.arg("password");
  // set not connect
  WiFi.setAutoReconnect(false);
  // connect wifi
  WiFi.begin(ssid.c_str(), password.c_str());
  // timeout  15s
  int8_t status = WiFi.waitForConnectResult(15 * 1000L);

  if (status == WL_CONNECTED)
  {
    // success return ip/deviceId
    esp8266_server.send(200, "application/json;charset=utf-8", "{\"message\":\"connect success!\",\"code\":0,\"data\":{\"ssid\":\"" + WiFi.SSID() + "\",\"password\":\"" + WiFi.psk() + "\",\"rssi\":" + WiFi.RSSI() + ",\"localIP\":" + WiFi.localIP().toString() + ",\"deviceId\":" + ESP.getChipId() + "}}");
  }
  else if (status == WL_NO_SSID_AVAIL)
  {
    esp8266_server.send(200, "application/json;charset=utf-8", "{\"message\":\"wifi ssid not avail!\",\"code\":202}");
  }
  else if (status == WL_WRONG_PASSWORD)
  {
    esp8266_server.send(200, "application/json;charset=utf-8", "{\"message\":\"wifi password wrong!\",\"code\":203}");
  }
  else
  {
    esp8266_server.send(200, "application/json;charset=utf-8", "{\"message\":\"connect fail!\",\"code\":204}");
  }
}

Debug Messages

station: 08:1f:71:ac join, AID = 1
scandone
scandone
switch to channel 6
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 
state: 5 -> 0 (2)
rm 0
@enjoyneering
Copy link

enjoyneering commented Jul 21, 2022

Looks like the "waitForConnectResult()" returns -1 insted of actual status. By the way default timeout is 60sec.

@mofada
Copy link
Author

mofada commented Jul 21, 2022

Looks like the "waitForConnectResult()" returns -1 insted of actual status. By the way default timeout is 60sec.

If -1 is returned, the last else will be hit, and then return
{"message":"connect fail!","code":204}

@mofada
Copy link
Author

mofada commented Jul 21, 2022

WiFi.waitForConnectResult(15 * 1000L)

I passed in a timeoutWiFi.waitForConnectResult(15 * 1000L)

@enjoyneering
Copy link

enjoyneering commented Jul 21, 2022

If -1 is returned, the last else will be hit, and then return
{"message":"connect fail!","code":204}

no, because esp is not connected to netwok :)

@mofada
Copy link
Author

mofada commented Jul 21, 2022

Ah? Then it should also hit the send,and will the station mode be turned off?

image

@mofada
Copy link
Author

mofada commented Jul 22, 2022

If the wifi ssid and password are correct, the request duration 25s will still be returned

image

{"message":"connect success!","code":0,"data":{"ssid":"LLWW","password":"LLWW123123","rssi":-75,"localIP":192.168.9.181,"deviceId":3707097}}

@mofada
Copy link
Author

mofada commented Jul 22, 2022

If the password is wrong, 12s ends the request and no message is returned
image

image

@mofada
Copy link
Author

mofada commented Jul 30, 2022

@enjoyneering can anyone help me?

@mofada
Copy link
Author

mofada commented Jul 30, 2022

e6786ba7fa1e5ee00a13ac4dbbdcfc1

The client appears to be lost halfway through the connection

262307b8e02ebbd840d25bff8c2a11f

@mcspr
Copy link
Collaborator

mcspr commented Jul 30, 2022

The client appears to be lost halfway through the connection

try removing this line in your Core installation folder, usually at %LOCALAPPDATA%\Arduino15\packages\esp8266\hardware\...

@mofada
Copy link
Author

mofada commented Jul 31, 2022

The client appears to be lost halfway through the connection

try removing this line in your Core installation folder, usually at %LOCALAPPDATA%\Arduino15\packages\esp8266\hardware\...

Solved my problem, which has been bothering me for a long time, thanks a lot

image

@mofada
Copy link
Author

mofada commented Jul 31, 2022

The client appears to be lost halfway through the connection

try removing this line in your Core installation folder, usually at %LOCALAPPDATA%\Arduino15\packages\esp8266\hardware\...

My problem was solved by modifying the source code, is there any other solution without modifying the source code? Such a solution does not seem to be the optimal solution

@mcspr
Copy link
Collaborator

mcspr commented Jul 31, 2022

My problem was solved by modifying the source code, is there any other solution without modifying the source code? Such a solution does not seem to be the optimal solution

Next release will no longer include the code in question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants