I have a nodeMCU with esp8266.
I am trying to connect it to home wifi network but it fails unless I make a temporary change on my wifi settings. It is a little strange; I will try to be more specific.
I read on another thread that esp8266 can not connect to the wifi if auto mode is enabled.
I have an Asus RT-AX88U and an Asus mesh with wifi 6 enabled.
Both 2.4Ghz and 5Ghz is open with WPA
Now , if I turn on guest network , wifi process is restarted on the router and just after that if I connect the esp8266 it connects successfully. And after that it can connect without an issue (even if the guest network is disabled) until the router is restarted.
So as a summary:
Router restart -> esp8266 does not connect (FAIL)
Enable guest wifi , try esp8266 connect -> esp8266 connects (SUCCESS)
disable guest wifi , try esp8266 connect -> esp8266 connects (SUCCESS)
turn off /on esp8266 -> esp8266 connects (SUCCESS)
turn off / on router / restart router -> esp8266 does not connect (FAIL)
I am using the following code to connect. Is there a tweak to make it connect easily ?
What else can I do ?
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266mDNS.h>
ESP8266WiFiMulti wifiMulti;
void setup(void){
Serial.begin(115200); // Start the Serial communication to send messages to the computer
wifiMulti.addAP("network", "12345678"); // add Wi-Fi networks you want to connect to
Serial.println("Connecting ...");
int i = 0;
while (wifiMulti.run() != WL_CONNECTED) { // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
delay(250);
Serial.print('.');
}
Serial.println('\n');
Serial.print("Connected to ");
Serial.println(WiFi.SSID()); // Tell us what network we're connected to
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
}
void loop(void){
}
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
// Demo-Code connect an ESP8266 to a WiFi-network using stationmode STA
// stationmode is simply join the WiFi-network as your computer or smartphone does it
// the code has three useful functions one for easy identifiying the code in the flash
// one for non-blocking timing
// a heartbeat-blinker function for indicating the state the code is in
// the code is written with two programming rules:
// 1. put EACH functionality into its OWN function
// 2. give EACH function a SELF-explaining name what the function does
// you should follow these programming rules
#include <ESP8266WiFi.h>
const char *ssid = "your SSID";
const char *password = "your password";
void PrintFileNameDateTime() {
Serial.println( F("Code running comes from file ") );
Serial.println( F(__FILE__));
Serial.print( F(" compiled ") );
Serial.print(F(__DATE__));
Serial.print( F(" ") );
Serial.println(F(__TIME__));
}
boolean TimePeriodIsOver (unsigned long &periodStartTime, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - periodStartTime >= TimePeriod )
{
periodStartTime = currentMillis; // set new expireTime
return true; // more time than TimePeriod) has elapsed since last time if-condition was true
}
else return false; // not expired
}
unsigned long MyTestTimer = 0; // variables MUST be of type unsigned long
const byte OnBoard_LED = 2;
void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
static unsigned long MyBlinkTimer;
pinMode(IO_Pin, OUTPUT);
if ( TimePeriodIsOver(MyBlinkTimer, BlinkPeriod) ) {
digitalWrite(IO_Pin, !digitalRead(IO_Pin) );
}
}
void ConnectToWiFi() {
WiFi.mode(WIFI_STA);
Serial.println("WiFi.mode(WIFI_STA)");
int myCount = 0;
Serial.print("trying to connect to #");
Serial.print(ssid);
Serial.println("#");
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED && myCount < 61) {
yield();
BlinkHeartBeatLED(OnBoard_LED, 50); // blink LED fast during attempt to connect
if ( TimePeriodIsOver(MyTestTimer, 500) ) { // once every 500 miliseconds
Serial.print("."); // print a dot
myCount++;
if (myCount > 60) { // after 30 dots = 15 seconds restart
Serial.println();
Serial.print("not yet connected");
}
}
}
if (WiFi.status() == WL_CONNECTED ) {
Serial.println("");
Serial.print("Connected to #");
Serial.print(ssid);
Serial.print("# IP address: ");
Serial.println(WiFi.localIP());
}
}
void printWiFiModeAndIP() {
Serial.println("\n\nWiFi parameters:");
Serial.print("Mode: ");
Serial.println(WiFi.getMode() == WIFI_AP ? "Station" : "Client");
Serial.print("IP address: ");
Serial.println(WiFi.getMode() == WIFI_AP ? WiFi.softAPIP() : WiFi.localIP());
}
void setup() {
delay(1000);
Serial.begin(115200);
delay(1000);
Serial.println( F("Setup-Start") );
PrintFileNameDateTime();
ConnectToWiFi();
printWiFiModeAndIP();
}
void PrintHelloMsg() {
Serial.print( F("Hi there I'm the demo-code my IP address is: ") );
Serial.println(WiFi.localIP());
}
void loop() {
BlinkHeartBeatLED(OnBoard_LED, 500); // change blinking to a lower frequency indicating beeing connected
if ( TimePeriodIsOver(MyTestTimer, 1000) ) {
PrintHelloMsg();
}
}
/*
most ESP8266 boards have a blue LED connected to GPIO-pin 2
This blue LED is used to indicate state connecting to WiFi by blinking fast
state beeing connected to Wifi by blinking with 1 Hz
If the WiFi-connection is successfully established the serial monitor shows
08:44:02.915 -> Setup-Start
08:44:02.915 -> Code running comes from file
08:44:02.915 -> your-path\yourfilename.ino
08:44:02.915 -> compiled date/time of compiling
08:44:02.971 -> WiFi.mode(WIFI_STA)
08:44:02.971 -> trying to connect to #Your SSID#
08:44:03.362 -> ....
08:44:04.215 -> Connected to #Your SSID# IP address: given IP-adress NNN.NNN.NNN.NNN
08:44:04.865 -> Hi there I'm the demo-code my IP address is: NNN.NNN.NNN.NNN
*/
thanks. I will try that after I restart my router. But I don't see how it is more basic ?
my code is shorter. It just uses the wifimulti client as a difference.
the wifi is listed after a restart.
static IP does not help.
I tried setting 2.4Ghz mode to "legacy" instead of "Auto"
when set to legacy it can connect.
But then my devices won't be able to connect with 802.11N right ?
I noticed that if I shutdown the closest mesh node, esp8266 connects to the main router with no issues.
SO is this a mesh problem ?
Might it be that the esp looks for the specific access point mac address ?
how can I make it connect to any mesh node ? (multi mac address )
- Fast connect to previous WiFi network at startup
- Registering multiple networks (at least 1)
- Connect to WiFi with strongest signal (RSSI)
- Fall back to connect to next WiFi when a connection failed or lost
- Fall back to connect to hidden SSID's which are not reported by WiFi scan
my initial code (shared above in OP) has wifimulti client but it is for multiple ssid.
In my case all 4 mesh nodes broadcast the same ssid. I need something to connect to multiple mac addresses.