ESP8266/wemos cannot connect via wifi

I am new to ESP8266 but the wemos seem to be an easy way to get started.

I have created a webserver with the LED-On/Off example and tried both DHCP and Static IP (192.168.6.24) and both options work fine when using the cable-connected network router IP (192.168.6.1) and access point.

When I use a phone or the laptop wifi to connect to the webserver the browser just times out.

Now it gets weird as I have another Arduino webserver on that same cable-network IP (192.168.6.20) and using a phone or laptop wifi I can connect fine.

What do I need to do to see the wemos webserver on the phone or laptop wifi.

#include <ESP8266WiFi.h>
const char* ssid = "SSID";
const char* password = "password";
int ledPin = D5;
WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
   // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  IPAddress ip(192,168,6,24);
  IPAddress subnet(255,255,255,0);
  IPAddress gateway(192,168,6,1);
  WiFi.config(ip,gateway,subnet); 
  WiFi.begin(ssid, password);
   while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
   // Start the server
  server.begin();
  Serial.println("Server started");
   // Print the IP address
  //Serial.print("Use this URL : ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 }

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  } else 
  if (request.indexOf("/LED=OFF") != -1) {
    digitalWrite(ledPin, LOW);
    value = LOW;
  } else {
    Serial.println("unknown command");
  }
 
 
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.print("Led pin is now: ");
 
  if(value == HIGH) {
    client.print("On");  
  } else {
    client.print("Off");
  }
  client.println("

");
  client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on pin 5 ON
");
  client.println("Click <a href=\"/LED=OFF\">here</a> turn the LED on pin 5 OFF
");
  client.println("</html>");
 
  delay(1);
  Serial.println("Client disconnected");
  Serial.println("");
}

Where is your loop? If you don't handle the server's client connections, the browser will timeout.
Please post all of your code.

Pieter

PieterP:
Please post all of your code.

I have added the Loop to OP code. Thanks but I really don't think that is at issue. Let me try a simple example.

Laptop connected with RJ45 (wifi off) I can see 192.168.6.20 and 192.168.6.24 and turn LEDs off/on
Laptop wifi (RJ45 disconnected) I can see 192.168.6.20 but not 192.168.6.24 and it times out.

I am not sure, but I think that I solved this issue by having the WiFiClient client static. Try it. My hypothesis is that when the object is not destroyed at the end of the function, it helps the library to handle it.

  static NetClient client = webServer.available();

  if (!client) {
    client = webServer.available();
  }

my WebServer

Juraj:
I am not sure, but I think that I solved this issue by having the WiFiClient client static. Try it.

Stopped working completely with that. I do not believe it is a code issue as it works fine with the RJ45 connection.

I have created a webserver with the LED-On/Off example and tried both DHCP and Static IP (192.168.6.24) and both options work fine when using the cable-connected network router IP (192.168.6.1) and access point.
When I use a phone or the laptop wifi to connect to the webserver the browser just times out.

I can not confirm your issue. I can connect my Wemos D1 to my phone using your code and my router numbers with a designated ip address and my ssid, password.

If your router is at 192.168.6.1 then this code looks correct.

IPAddress ip(192,168,6,24);
IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,6,1);
WiFi.config(ip,gateway,subnet);

If you comment out the above code, and let the router assign the address what do you get? Can you connect the phone to that address?

Your code works for me with both methods with an Android phone and Chrome browser. I used the built in led on pin 2 and inverted the HIGH/LOW for on and off to match my D1.