You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to show an HTML file on AP mode. Sometimes it works, sometimes it doesn't (when I reload the page it gets stuck and the board stops to respond the ping request).
My code is just "WiFiAccessPoint" + "FSBrowser" examples.
It is easy to replicate this error if you reload the page fast many times (sometimes it get stuck on the first attempt) or if, in my case, the page has many js and css to load like:
<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="jquery.mobile-1.4.5.min.css">
<!-- Include the jQuery library -->
<script src="jquery-1.12.2.min.js"></script>
<!-- Include the jQuery Mobile library -->
<script src="jquery.mobile-1.4.5.min.js"></script>
<!-- jQuery-Clock-Plugin -->
<link rel="stylesheet" type="text/css" href="jqClock.css" />
<script type="text/javascript" src="jqClock.min.js"></script>
Settings in IDE
Module: NodeMCU 1.0 (ESP-12E Module)
Flash Size: 4MB (3M SPIFFS
CPU Frequency: 160Mhz
Upload Using: SERIAL
Sketch
#include<ESP8266WiFi.h>
#include<WiFiClient.h>
#include<ESP8266WebServer.h>
#include<FS.h>/* Set these to your desired credentials. */constchar *ssid = "ESPap";
constchar *password = "thereisnospoon";
ESP8266WebServer server(80);
String formatBytes(size_t bytes)
{
if (bytes < 1024) {
returnString(bytes)+"B";
} elseif (bytes < (1024 * 1024)) {
returnString(bytes/1024.0)+"KB";
} elseif (bytes < (1024 * 1024 * 1024)) {
returnString(bytes/1024.0/1024.0)+"MB";
} else {
returnString(bytes/1024.0/1024.0/1024.0)+"GB";
}
}
String getContentType(String filename)
{
if (server.hasArg("download")) return"application/octet-stream";
elseif (filename.endsWith(".htm")) return"text/html";
elseif (filename.endsWith(".html")) return"text/html";
elseif (filename.endsWith(".css")) return"text/css";
elseif (filename.endsWith(".js")) return"application/javascript";
elseif (filename.endsWith(".png")) return"image/png";
elseif (filename.endsWith(".gif")) return"image/gif";
elseif (filename.endsWith(".jpg")) return"image/jpeg";
elseif (filename.endsWith(".ico")) return"image/x-icon";
elseif (filename.endsWith(".xml")) return"text/xml";
elseif (filename.endsWith(".pdf")) return"application/x-pdf";
elseif (filename.endsWith(".zip")) return"application/x-zip";
elseif (filename.endsWith(".gz")) return"application/x-gzip";
return"text/plain";
}
boolhandleFileRead(String path)
{
Serial.println("handleFileRead: " + path);
if (path.endsWith("/")) path += "index.html";
String contentType = getContentType(path);
String pathWithGz = path + ".gz";
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path))
{
if (SPIFFS.exists(pathWithGz))
path += ".gz";
File file = SPIFFS.open(path, "r");
size_t sent = server.streamFile(file, contentType);
file.close();
returntrue;
}
returnfalse;
}
voidhandleRoot() {
server.send(200, "text/html", "<h1>You are connected</h1>");
}
voidsetup() {
delay(1000);
Serial.begin(115200);
Serial.println();
SPIFFS.begin();
{
Dir dir = SPIFFS.openDir("/");
while (dir.next())
{
String fileName = dir.fileName();
size_t fileSize = dir.fileSize();
Serial.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
}
Serial.printf("\n");
}
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
// SERVER INIT
server.on("/", HTTP_GET, []() {
if (!handleFileRead("/index.htm")) server.send(404, "text/plain", "FileNotFound");
});
//called when the url is not defined here//use it to load content from SPIFFS
server.onNotFound([](){
if(!handleFileRead(server.uri()))
server.send(404, "text/plain", "FileNotFound");
});
server.begin();
Serial.println("HTTP server started");
}
voidloop() {
server.handleClient();
}
64 bytes from 192.168.4.1: icmp_seq=7644 ttl=255 time=2.663 ms
64 bytes from 192.168.4.1: icmp_seq=7645 ttl=255 time=3.952 ms
64 bytes from 192.168.4.1: icmp_seq=7646 ttl=255 time=2.958 ms
64 bytes from 192.168.4.1: icmp_seq=7647 ttl=255 time=3.862 ms
64 bytes from 192.168.4.1: icmp_seq=7648 ttl=255 time=2.954 ms
64 bytes from 192.168.4.1: icmp_seq=7649 ttl=255 time=8.292 ms
Request timeout for icmp_seq 7650
Request timeout for icmp_seq 7651
Request timeout for icmp_seq 7652
Request timeout for icmp_seq 7653
Request timeout for icmp_seq 7654
Request timeout for icmp_seq 7655
Request timeout for icmp_seq 7656
64 bytes from 192.168.4.1: icmp_seq=7657 ttl=255 time=12.436 ms
64 bytes from 192.168.4.1: icmp_seq=7658 ttl=255 time=4.029 ms
64 bytes from 192.168.4.1: icmp_seq=7659 ttl=255 time=1.707 ms
64 bytes from 192.168.4.1: icmp_seq=7660 ttl=255 time=3.380 ms
The text was updated successfully, but these errors were encountered:
Make sure you add WiFi.mode(WIFI_AP) if you aren't using STA interface. Otherwise it might happen that STA interface is trying to connect to some AP, and fails constantly, which interrupts SoftAP connection.
See comments in Espressif SDK docs: #119 (comment)
Basic Infos
Hardware
Hardware: NodeMCU ESP-12E
Core Version: 2.1.0
Description
I'm trying to show an HTML file on AP mode. Sometimes it works, sometimes it doesn't (when I reload the page it gets stuck and the board stops to respond the ping request).
My code is just "WiFiAccessPoint" + "FSBrowser" examples.
It is easy to replicate this error if you reload the page fast many times (sometimes it get stuck on the first attempt) or if, in my case, the page has many js and css to load like:
Settings in IDE
Module: NodeMCU 1.0 (ESP-12E Module)
Flash Size: 4MB (3M SPIFFS
CPU Frequency: 160Mhz
Upload Using: SERIAL
Sketch
Debug Messages
Ping Test
The text was updated successfully, but these errors were encountered: