Web server on NodeMCU can only be reached by one PC

I have a NodeMCU running a web server - adapted from this tutorial

It sits on my network at 192.168.1.31

and produces a display in a browser window.

However when I try to access it from another PC I get

The server at 192.168.1.31 is taking too long to respond.

If I close the first window it appears on the other PC. Seems it can olnly serve one client at a tiime.

Any ideas?

Depending on the software implementing the server, it may not be written to support multiple client connections, or if you’re lucky, within the initialisation code there might be a value that allows you to set the maximum number of simultaneous connections.

The reason may be either be to contain memory usage, or just to simplify the server code.

Sorry I forgot to include the code. The ESP8266WebServer library is a total mystery to me so if it has limitations - or settings that can be changed - I'd be lost.

#include <ESP8266WebServer.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;

float temperature, humidity, pressure, altitude;

/*Put your SSID & Password*/
const char* ssid = "YourNetworkName";  // Enter SSID here
const char* password = "YourPassword";  //Enter Password here

ESP8266WebServer server(80);              
 
void setup() {
  Serial.begin(115200);
  delay(100);
  
  bme.begin(0x76);   

  Serial.println("Connecting to ");
  Serial.println(ssid);

  //connect to your local wi-fi network
  WiFi.begin(ssid, password);

  //check wi-fi is connected to wi-fi network
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected..!");
  Serial.print("Got IP: ");  Serial.println(WiFi.localIP());

  server.on("/", handle_OnConnect);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");

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

void handle_OnConnect() {
  temperature = bme.readTemperature();
  humidity = bme.readHumidity();
  pressure = bme.readPressure() / 100.0F;
  altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  server.send(200, "text/html", SendHTML(temperature,humidity,pressure,altitude)); 
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

That's odd. Can you look at the page source on the PC and check whether there's any meta tag causing the page to be continuously refreshed?

Try using the async web server. It allows more than one connection at a time.

Using asynchronous network means that you can handle more than one connection at the same time

Its only refreshing once a second. I could easily reduce that if that is the problem.
@DaveE I have a spare ESP32 WROOM 32 DEVKIT C - I'll try the AsyncServer on that.

//AJAX code to do the refresh
  ptr += "<script>\n";
  ptr += "setInterval(loadDoc,1000);\n";
  ptr += "function loadDoc() {\n";
  ptr += "var xhttp = new XMLHttpRequest();\n";
  ptr += "xhttp.onreadystatechange = function() {\n";
  ptr += "if (this.readyState == 4 && this.status == 200) {\n";
  ptr += "document.body.innerHTML =this.responseText}\n";
  ptr += "};\n";
  ptr += "xhttp.open(\"GET\", \"/\", true);\n";
  ptr += "xhttp.send();\n";
  ptr += "}\n";
  ptr += "</script>\n";

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.