I have a Wifi router connected to the internet on my computer. My PC is connected to the network by a wireless interface. I am confused about what the SSID is for the network. There seem to be two similar names being used, "HOME-8DC2-2.4" and "HOME-8DC2-2.4 3". I am programming aWemos D1 R2 (ESP8266) with builtin WiFi via the E-12 I believe. I am running the example Webserver program loaded from the library installed "ESP8266 by ESP Community". The changed the code:
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password
to char ssid[] = "HOME-8DC2-2.4"; // your network SSID (name)
and entered my password on the second line. The program compiled and loaded correctly. The Serial monitor shows Connecting to WiFi .................
and never seems to actually connect. I tried the second version of SSID with same result.
I have been able to create a WiFi access point, and had a WebSocket working a few days ago using the same SSID and password, but it will not connect today.
The WebSocket program generated an index.html file that I double clicked on to open the web page. Any suggestions on what I am doing wrong?
My network image is below.
That is a lot of confusing information. First step is to turn off the computer and any ESP8266 devices, then using a mobile phone do a scan for WiFi access points.
Do you see a "HOME-8DC2-2.4" or "HOME-8DC2-2.4 3"?
Turn on the computer and let it connect to the internet. What SSID did it choose?
I'm guessing that the 2.4 at the end of the SSID indicates 2.4GHz. The ESP8266 can connect to 2.4GHz networks not, however, 5GHz networks. Most routers support both frequencies.
You are correct. I have both 2.4 and 5 GHz set up on my WiFi router. I can connect the computer to either since I have a wireless WiFi adapter that accepts both. The Arduino server example does not connect to anything when I compile and load the code. It loads correctly, but my serial monitor shows it is searching for a connection and not finding it.
Post the example code you are using so it is clear that it is appropriate for this use case, which appears to be joining an existing WiFi network.
Your WiFi router was supplied by your Internet service provider?
Your PC does not have a built-in wireless adapter so you are using an external one ?
You may be able to load on to the esp8266 a scanner such as the following to see what Ssids are available: Arduino/WiFiScan.ino at master · esp8266/Arduino · GitHub
I see HOME-8DC2-2.4 and -8DC2-5. The first is a 2.4 GHz network, the second is a 5GHz network. I can connect the computer to either since it has a wireless adapter that will connect to either frequency. Normally I connect the computer to the 2.4 GHz network.
#include <ESP8266WiFi.h>
// Network SSID and Password
const char* ssid = "HOME-8DC2-2.4";
const char* password = "my-password";
int ledPin = D0;
int potPin = A0;
// Start WiFi Server on port 80
WiFiServer ESPserver(80);
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin,LOW);
// Connect WiFi
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
Serial.println(password);
WiFi.hostname("Name");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("."); // a "dot" is added until connection is established
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); // local IP address
ESPserver.begin();
Serial.println("Server started");
}
The serial monitor shows
Connecting to HOME-8DC2-2.4
my-password
.......................................................................
since it is not connecting.
The code looks OK. Try loading the scanner mentioned in post #5 onto the esp8266 to see what wifi networks it finds. Note that SSIDs are case sensitive.
Here is an image of the network scan results. Some scans find different networks and not the one I want. Is it possible the decimal point in the name (2.4) is causing a problem?
Do I need to change my channel to an unused one? Most of the other networks belong to neighbors and I have no control over them. It turns out the network name and channel are selected by my ISP (Xfinity) and I may not be able to change then either.
I think I am onto something. It seems Windows or maybe my firewall is blocking WiFi. When I run the Windows Network Diagnostics I get "Either the Peer Name Resolution Protocol service or the Peer Networking Identity Manager service is not running." Also the "Peer Networking Grouping service isn't running". The troubleshooter cannot fix these, and I cannot seem to start either. I am running Windows7 Home Ultimate and it does not include Local Security Policy. At times during attempts to fix this, the WiFi does seem to connect briefly, but it will not reconnect reliably later. I tried turning firewall off, but it did not help.
I don't understand what your Windows 7 PC has to do with this issue. I guess that even if the PC is switched off, the wireless network with the SSID HOME-8DC2-2.4 will still exist because this is created by the Xfinity managed router.
Have you got a smart phone or tablet on which you can test the WLAN independently of the PC ?
Yes, I will try it. I also have a Windows 10 PC, and the ESP8266 is able to connect with the router when I program it on that PC. Not sure why, but something in my firewall or maybe anti-virus is preventing if from connecting to the network. It just hangs up and refuses to connect, as shown on the Serial monitor.
OK. So it appears that the ESP8266 can connect to the router under some circumstances but, if the ESP8266 is physically connected to the Windows 7 PC, then something interferes with the connection. I can't imagine a firewall but I could imagine some sort of radio interference.
I guess you have the same version of the IDE on both the Windows 7 and Windows 10 PCs and you got no compiler warnings on either system when you compiled the code.
What I would do is alter the program on the ESP8266 so that it blinks a led say 3 times when the connection has been made then test it independently from any PC. Power it instead through say a USB charger.
I did get it to connect to a web server tutorial program by Rui Santos. On the Windows 7 computer it connects after about 5 minutes of trying. I cannot connect to the associated webpage however. I ran network diagnostics and there might be a problem with my wireless adapter, a Realtek unit. Internet and everything else works fine, just not ESP8266. Windows troubleshooter cannot fix the problem.
When connected to my Windows 10 computer it connects in a few seconds and I can connect to the associated webpage with no problem.
try the sketch from the examples, it definitely works!
/*
This sketch demonstrates how to set up a simple HTTP-like server.
The server will set a GPIO pin depending on the request
http://server_ip/gpio/0 will set the GPIO2 low,
http://server_ip/gpio/1 will set the GPIO2 high
server_ip is the IP address of the ESP8266 module, will be
printed to Serial when the module is connected.
*/
#include <ESP8266WiFi.h>
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
// prepare LED
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, 0);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(F("Connecting to "));
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println();
Serial.println(F("WiFi connected"));
// Start the server
server.begin();
Serial.println(F("Server started"));
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println(F("new client"));
client.setTimeout(5000); // default is 1000
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(F("request: "));
Serial.println(req);
// Match the request
int val;
if (req.indexOf(F("/gpio/0")) != -1) {
val = 0;
} else if (req.indexOf(F("/gpio/1")) != -1) {
val = 1;
} else {
Serial.println(F("invalid request"));
val = digitalRead(LED_BUILTIN);
}
// Set LED according to the request
digitalWrite(LED_BUILTIN, val);
// read/ignore the rest of the request
// do not client.flush(): it is for output only, see below
while (client.available()) {
// byte by byte is not very efficient
client.read();
}
// Send the response to the client
// it is OK for multiple small client.print/write,
// because nagle algorithm will group them into one single packet
client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now "));
client.print((val) ? F("high") : F("low"));
client.print(F("<br><br>Click <a href='http://"));
client.print(WiFi.localIP());
client.print(F("/gpio/1'>here</a> to switch LED GPIO on, or <a href='http://"));
client.print(WiFi.localIP());
client.print(F("/gpio/0'>here</a> to switch LED GPIO off.</html>"));
// The client will actually be *flushed* then disconnected
// when the function returns and 'client' object is destroyed (out-of-scope)
// flush = ensure written data are received by the other side
Serial.println(F("Disconnecting from client"));
}
OK. So it looks like you can join the wireless network HOME-8DC2-2.4 at least from the Windows 10 PC. Once you have done that, what is the ESP8266 then attempting to connect to ? A remote web server maybe like api.weather.com or a web server in your local network or what ?
The ESP8266 is trying to connect to my internet router located in another room of my house. Once connected to my network router, I want to connect through a web browser from either my PC or from my cell phone. I think perhaps the distance from the ESP8266 to my router is to far and I am getting a weak signal. Once programmed, I have tried moving the ESP8266 around the house and it seems to work fine some locations, but no others. There are walls and other obstructions that may be a factor.