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("");
}