Esp8266 webserver connects ok remotely but not locally

Status
Not open for further replies.

dr pepper

Well-Known Member
Most Helpful Member
I have a wemos D1 operating as a webserver, it works, the page is set to auto refresh every 60 secs, I set the sever to appear on port 3389.
Using port forwarding and my wanip IP I can connect to it from anywhere with a internet connection, and it works reliably from a remote location.
However if I connect to it at home (same network), the connection is unrelaible, and just about every auto refresh fails, I've tried both the local Ip and the wanip Ip, both are the same.
 
with the wan ip working it indicates you forward ok... the local ip should be used when on the same network and local traffic shouldnt be getting blocked by firewalls ever, unless you are going through separate routers .... have you narrowed down to if its tx or rx on the server?

when i dont want to mess with port settings i turn on the DMZ and point it to my server device... this shuts off the firewall to that device completely

"serial wifi terminal" is a handy tcp terminal app on my android phone .. i used it for finding bad packets when i attempted my own server
 
I have a Nodemcu (same as wemos) doing a similar thing but only locally. It works most of the time but occasionally fails to send the complete file.
The routine that sends files from spiffs is,
Code:
bool loadFromSpiffsCard(String path){
  uint32_t serveTime;
  bool isAP = ipAPClient(server.client().remoteIP());
  if(isAP)
    Serial.println("Request via AP.");
  else
    Serial.print("Request via WiFi.\n");
  String dataType;// = "text/plain";
  if(path.endsWith("/")){
    path+=isAP?"connect.htm":"index.htm";
  }
  Serial.println(path);
  if(path.endsWith(".htm")) dataType = "text/html";
  else if(path.endsWith(".css")) dataType = "text/css";
  else if(path.endsWith(".js")) dataType = "application/javascript";
  else if(path.endsWith(".png")) dataType = "image/png";
  else if(path.endsWith(".gif")) dataType = "image/gif";
  else if(path.endsWith(".jpg")) dataType = "image/jpeg";
  else if(path.endsWith(".ico")) dataType = "image/x-icon";
  else if(path.endsWith(".xml")) dataType = "text/xml";
  else if(path.endsWith(".pdf")) dataType = "application/pdf";
  else if(path.endsWith(".zip")) dataType = "application/zip";
  serveTime=millis();
  File dataFile = SPIFFS.open(path.c_str(),"r");
  if (!dataFile)
    return false;
  uint32_t sent,len;
  sent=server.streamFile(dataFile, dataType);
  len=dataFile.size();
  if(sent!=len){
    Serial.print("Sent less data than expected! Sent = ");Serial.print(sent);Serial.print(" file length = ");Serial.println(len);
  }
  Serial.print("Time to serve = ");Serial.println(millis()-serveTime);
  Serial.print("Sent file ");
  Serial.println(path);
  dataFile.close();
  return true;
}
Sometimes it will work fine for days and then occasionally it will report via the serial monitor,
Request via WiFi.
/data.txt
Sent less data than expected! Sent = 1072 file length = 7140
Time to serve = 5654
Sent file /data.txt
Are you doing a similar thing? Or do you serve the files differently?

I'll be following this thread with interest.

Mike.
 
Dogz, yes might try turning on Dmz for an hour & see if it improves.
I've not seen wifi serial, must look into that, is that how you program an esp over wifi.

Poms, my code is much simpler, only one page, and that is served with client.print(), there are onlt 4 lines, a descriptor then a value on each line, just enough to be humanly readable with a browser, and simple enough to scrape with finder.find() in software.
Your code looks fairly standard server wise, you have a diffrent issue, yours works most of the time, mine works some of the time.
Apparently the esp32 has more 'advanced' and faster wifi & networking, maybe we should upgrade.

I'm at work now, my webservers page is open, and it hits every auto refresh, sometimes it takes a few secs to receive the data once requested but doesnt seem to fail, whereas last night using it at home on the same net it would only work after hitting refresh a couple of times.
 
Last edited:
because i bit bang esp on arduino using serial1 , the "serial wifi terminal" is just another data terminal but you can send the http get request from it and see what packets are being returned
.... also what does the web browser look like when it returns without a refresh?
.... also are you rebooting the esp when you switch from wan to lan?

but maybe check to see if the the get request is making it to the ESP with a led on the tx pin (i think it echoes to there if i recall)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…