{"action":"opened","issue":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/4394","repository_url":"https://api.github.com/repos/esp8266/Arduino","labels_url":"https://api.github.com/repos/esp8266/Arduino/issues/4394/labels{/name}","comments_url":"https://api.github.com/repos/esp8266/Arduino/issues/4394/comments","events_url":"https://api.github.com/repos/esp8266/Arduino/issues/4394/events","html_url":"https://github.com/esp8266/Arduino/issues/4394","id":298412823,"number":4394,"title":"Hang w/2.2 SDK and  WiFi.scanNetworks in AP mode with TCP in-flight","user":{"login":"earlephilhower","id":11875,"avatar_url":"https://avatars0.githubusercontent.com/u/11875?v=4","gravatar_id":"","url":"https://api.github.com/users/earlephilhower","html_url":"https://github.com/earlephilhower","followers_url":"https://api.github.com/users/earlephilhower/followers","following_url":"https://api.github.com/users/earlephilhower/following{/other_user}","gists_url":"https://api.github.com/users/earlephilhower/gists{/gist_id}","starred_url":"https://api.github.com/users/earlephilhower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/earlephilhower/subscriptions","organizations_url":"https://api.github.com/users/earlephilhower/orgs","repos_url":"https://api.github.com/users/earlephilhower/repos","events_url":"https://api.github.com/users/earlephilhower/events{/privacy}","received_events_url":"https://api.github.com/users/earlephilhower/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-19T22:03:38Z","updated_at":"2018-02-19T22:03:38Z","closed_at":null,"author_association":"COLLABORATOR","body":"### Basic Infos\r\n\r\nWiFi.scanNetworks in SDK 2.2 never returns to the main app under certain conditions when in AP mode.\r\n\r\nNo WDT or stack dump is produced, the ESP simply never returns from the call, no data is sent over WiFi, and a reset is required to regain operation.\r\n\r\n#### Hardware\r\nHardware:   WeMos D1 mini\r\nCore Version:     Failing: GIT head ; passing:  GIT (f9ac524b13348e18a1ceb00261d947d6c1e0f9b5).\r\n\r\n### Description\r\n\r\nDiscovered this while rebuilding my app PsychoPlug (https://github.com/earlephilhower/psychoplug) with latest GIT head.  Sample code below reproduces the failure using the HTTPSServer example code + a bit of my own stuff that produced the web page.\r\n\r\nESP initializes and goes into AP mode and has a SSL (443) server to allow a cell phone or laptop to connect and set the configuration of the app.  The setup.html page is generated and sent line-by-line using client.print()s to a WiFiClientSecure object.\r\n\r\nHeaders are sent, the HTML prefixes, and some intro form fields.  \r\n\r\nThen WiFi.scanNetworks() is called to generate a popup menu on the page to allow the user to select which AP to connect to in operational mode.\r\n\r\nUnder SDK 2.2, this call to wifi.scannetworks() never returns.  Under the commit right before SDK2.2 it operates as expected.\r\n\r\nReplacing the call in the sample script with\r\n````\r\nint cnt = 0; // int cnt = WiFi.scanNetworks();\r\n````\r\nalso works properly.  Erasing the flash settings area (and the entire chip) has no effect.\r\n\r\n### To Reproduce\r\n\r\nRun script, connect to \"testap\" (no password) and go to https://192.168.1.4/ .  On 2.1 you'll get a header and a popup menu of detected APs, as well as serial output showing\r\n````\r\n....\r\nnew client\r\n+SentSetupHTML   (started the page xmission)\r\ndone\r\n-SendSetupHTML   (ended page xmission)\r\n````\r\n\r\nWhen it hangs the \"-SendSetupHTML\" line never comes and no WDT fires, the ESP just hangs forever.\r\n\r\n### Settings in IDE\r\n\r\nModule:  \t\t\tWemos D1 Mini\r\nFlash Size: \t\t4MB\r\nCPU Frequency:\t\t160Mhz\r\nLWIP:\t\tv2 (lo mem & hi BW show same behavior)\r\n\r\n\r\n### Sketch\r\n\r\n````\r\n#include <ESP8266WiFi.h>\r\n\r\n// The certificate is stored in PMEM \r\nstatic const uint8_t x509[] PROGMEM = {\r\n  0x30, 0x82, 0x01, 0x3d, 0x30, 0x81, 0xe8, 0x02, 0x09, 0x00, 0xfe, 0x56,\r\n  0x46, 0xf2, 0x78, 0xc6, 0x51, 0x17, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,\r\n  0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x26, 0x31,\r\n  0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x45, 0x53,\r\n  0x50, 0x38, 0x32, 0x36, 0x36, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55,\r\n  0x04, 0x03, 0x0c, 0x09, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e,\r\n  0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x37, 0x30, 0x33, 0x31, 0x38, 0x31,\r\n  0x34, 0x34, 0x39, 0x31, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x30, 0x31, 0x31,\r\n  0x32, 0x35, 0x31, 0x34, 0x34, 0x39, 0x31, 0x38, 0x5a, 0x30, 0x26, 0x31,\r\n  0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x45, 0x53,\r\n  0x50, 0x38, 0x32, 0x36, 0x36, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55,\r\n  0x04, 0x03, 0x0c, 0x09, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e,\r\n  0x31, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,\r\n  0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02,\r\n  0x41, 0x00, 0xc6, 0x72, 0x6c, 0x12, 0xe1, 0x20, 0x4d, 0x10, 0x0c, 0xf7,\r\n  0x3a, 0x2a, 0x5a, 0x49, 0xe2, 0x2d, 0xc9, 0x7a, 0x63, 0x1d, 0xef, 0xc6,\r\n  0xbb, 0xa3, 0xd6, 0x6f, 0x59, 0xcb, 0xd5, 0xf6, 0xbe, 0x34, 0x83, 0x33,\r\n  0x50, 0x80, 0xec, 0x49, 0x63, 0xbf, 0xee, 0x59, 0x94, 0x67, 0x8b, 0x8d,\r\n  0x81, 0x85, 0x23, 0x24, 0x06, 0x52, 0x76, 0x55, 0x9d, 0x18, 0x09, 0xb3,\r\n  0x3c, 0x10, 0x40, 0x05, 0x01, 0xf3, 0x02, 0x03, 0x01, 0x00, 0x01, 0x30,\r\n  0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,\r\n  0x05, 0x00, 0x03, 0x41, 0x00, 0x69, 0xdc, 0x6c, 0x9b, 0xa7, 0x62, 0x57,\r\n  0x7e, 0x03, 0x01, 0x45, 0xad, 0x9a, 0x83, 0x90, 0x3a, 0xe7, 0xdf, 0xe8,\r\n  0x8f, 0x46, 0x00, 0xd3, 0x5f, 0x2b, 0x0a, 0xde, 0x92, 0x1b, 0xc5, 0x04,\r\n  0xc5, 0xc0, 0x76, 0xf4, 0xf6, 0x08, 0x36, 0x97, 0x27, 0x82, 0xf1, 0x60,\r\n  0x76, 0xc2, 0xcd, 0x67, 0x6c, 0x4b, 0x6c, 0xca, 0xfd, 0x97, 0xfd, 0x33,\r\n  0x9e, 0x12, 0x67, 0x6b, 0x98, 0x7e, 0xd5, 0x80, 0x8f\r\n};\r\n\r\n// And so is the key.  These could also be in DRAM\r\nstatic const uint8_t rsakey[] PROGMEM = {\r\n  0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xc6, 0x72,\r\n  0x6c, 0x12, 0xe1, 0x20, 0x4d, 0x10, 0x0c, 0xf7, 0x3a, 0x2a, 0x5a, 0x49,\r\n  0xe2, 0x2d, 0xc9, 0x7a, 0x63, 0x1d, 0xef, 0xc6, 0xbb, 0xa3, 0xd6, 0x6f,\r\n  0x59, 0xcb, 0xd5, 0xf6, 0xbe, 0x34, 0x83, 0x33, 0x50, 0x80, 0xec, 0x49,\r\n  0x63, 0xbf, 0xee, 0x59, 0x94, 0x67, 0x8b, 0x8d, 0x81, 0x85, 0x23, 0x24,\r\n  0x06, 0x52, 0x76, 0x55, 0x9d, 0x18, 0x09, 0xb3, 0x3c, 0x10, 0x40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x2e, 0x91, 0x99, 0xec, 0xb7, 0x02, 0x20,\r\n  0x4b, 0x9d, 0x46, 0xd7, 0x3c, 0x01, 0x4c, 0x5d, 0x2a, 0xb0, 0xd4, 0xaa,\r\n  0xc6, 0x03, 0xca, 0xa0, 0xc5, 0xac, 0x2c, 0xe0, 0x3f, 0x4d, 0x98, 0x71,\r\n  0xd3, 0xbd, 0x97, 0xe5, 0x55, 0x9c, 0xb8, 0x41, 0x02, 0x20, 0x02, 0x42,\r\n  0x9f, 0xd1, 0x06, 0x35, 0x3b, 0x42, 0xf5, 0x64, 0xaf, 0x6d, 0xbf, 0xcd,\r\n  0x2c, 0x3a, 0xcd, 0x0a, 0x9a, 0x4d, 0x7c, 0xad, 0x29, 0xd6, 0x36, 0x57,\r\n  0xd5, 0xdf, 0x34, 0xeb, 0x26, 0x03\r\n};\r\n \r\n\r\nWiFiServerSecure server(443);\r\nstatic IPAddress setupIP = {192, 168, 4, 1};\r\nstatic IPAddress setupMask = {255, 255, 255, 0};\r\nstatic const char *ssid = \"testap\";\r\n#define DOCTYPE \"<!DOCTYPE HTML PUBLIC \\\"-//W3C//DTD HTML 4.01 Transitional//EN\\\" \\\"http://www.w3.org/TR/html4/loose.dtd\\\">\"\r\n#define ENCODING \"<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=utf-8\\\"/>\\n\"\r\n#define WebPrintf(c, fmt, ...) { char webBuff[192]; snprintf_P(webBuff, sizeof(webBuff), PSTR(fmt), ## __VA_ARGS__); (c).print(webBuff); delay(10);}\r\n#define WebPrintfPSTR(c, fmt, ...) { char webBuff[192]; snprintf_P(webBuff, sizeof(webBuff), (fmt), ## __VA_ARGS__); (c).print(webBuff); delay(10);}\r\n\r\n\r\nvoid WebHeaders(WiFiClientSecure &client, PGM_P /*const char **/headers)\r\n{\r\n  WebPrintf(client, \"HTTP/1.1 200 OK\\r\\n\");\r\n  WebPrintf(client, \"Server: PsychoPlug\\r\\n\");\r\n  WebPrintf(client, \"Content-type: text/html\\r\\n\");\r\n  WebPrintf(client, \"Cache-Control: no-cache, no-store, must-revalidate\\r\\n\");\r\n  WebPrintf(client, \"Pragma: no-cache\\r\\n\");\r\n  WebPrintf(client, \"Connection: close\\r\\n\");\r\n  WebPrintf(client, \"Expires: 0\\r\\n\");\r\n  if (headers) {\r\n    WebPrintfPSTR(client, headers);\r\n  }\r\n  WebPrintf(client, \"\\r\\n\");\r\n}\r\n\r\nvoid WebFormText(WiFiClientSecure &client, /*const char **/ PGM_P label, const char *name, const char *value, bool enabled)\r\n{\r\n  WebPrintfPSTR(client, label);\r\n  WebPrintf(client, \": <input type=\\\"text\\\" name=\\\"%s\\\" id=\\\"%s\\\" value=\\\"%s\\\" %s><br>\\n\", name, name, value, !enabled?\"disabled\":\"\");\r\n}\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  delay(10);\r\n\r\n  // prepare GPIO2\r\n  pinMode(2, OUTPUT);\r\n  digitalWrite(2, 0);\r\n  \r\n  // Connect to WiFi network\r\n  Serial.println();\r\n  Serial.println();\r\n  Serial.print(\"Starting up SSID: \");\r\n  Serial.println(ssid);\r\n\r\n  WiFi.mode(WIFI_AP);\r\n  WiFi.softAPConfig(setupIP, setupIP, setupMask);\r\n  WiFi.softAP(ssid);\r\n\r\n  // Set the certificates from PMEM (if using DRAM remove the _P from the call)  \r\n  server.setServerKeyAndCert_P(rsakey, sizeof(rsakey), x509, sizeof(x509));\r\n\r\n  // Start the server\r\n  server.begin();\r\n  Serial.println(\"Server started\");\r\n  Serial.println(setupIP);\r\n}\r\n\r\nvoid loop() {\r\n  // Check if a client has connected\r\n  WiFiClientSecure client = server.available();\r\n  if (!client) {\r\n    return;\r\n  }\r\n  \r\n  // Wait until the client sends some data\r\n  Serial.println(\"new client\");\r\n  unsigned long timeout = millis() + 3000;\r\n  while(!client.available() && millis() < timeout){\r\n    delay(1);\r\n  }\r\n  if (millis() > timeout) {\r\n    Serial.println(\"timeout\");\r\n    client.flush();\r\n    client.stop();\r\n    return;\r\n  }\r\n\r\n  // Read the first line of the request\r\n//  String req = client.readStringUntil('\\r');\r\n//  Serial.println(req);\r\n//  client.flush();\r\n\r\n  Serial.printf(\"+SendSetupHTML\\n\");\r\n  WebHeaders(client, NULL);\r\n  WebPrintf(client, DOCTYPE);\r\n  WebPrintf(client, \"<html><head><title>PsychoPlug Setup</title>\" ENCODING \"</head>\\n\");\r\n  WebPrintf(client, \"<body><h1>PsychoPlug Setup</h1>\\n\");\r\n  WebPrintf(client, \"<form action=\\\"config.html\\\" method=\\\"POST\\\">\\n\");\r\n\r\n  WebPrintf(client, \"<br><h1>WiFi Network</h1>\\n\");\r\n  WebFormText(client, PSTR(\"SSID\"), \"ssid\", ssid, true);\r\n  int cnt = WiFi.scanNetworks();\r\n  if (cnt==0) {\r\n    WebPrintf(client, \"Discovered networks: No WIFI networks detected.<br>\\n\");\r\n  } else {\r\n    WebPrintf(client, \"Discovered networks: <select onchange=\\\"setval(this)\\\">\");\r\n    WebPrintf(client, \"<option></option>\");\r\n    for (byte i=0; i<cnt; i++) {\r\n      WebPrintf(client, \"<option>%s</option>\", WiFi.SSID(i).c_str());\r\n    }\r\n    WebPrintf(client, \"</select><br>\\n\");\r\n  }\r\n  Serial.printf(\"done\\n\");\r\n  WebPrintf(client, \"</form></body></html>\\n\");\r\n  Serial.printf(\"-SendSetupHTML\\n\");\r\n}\r\n\r\n````"}}
{"actor":{"display_login":"earlephilhower"}}