ESP8266 Will Not Connect to WIFI

Hello, I'm at my wits' end. I can not figure out how to get an ESP8266 device to connect to my WIFI network.

My router is from Xfinity, my network "jonas" is broadcast both in stunning 2.4Ghz and 5Ghz.

I have verified the SSID and passphrase are correct. And able to connect to my WIFI network using an UNO R4 WIFI with no issues. I also have a number of ESP8266 consumer electronic devices that are happily connected to my WIFI network (pet feeder, smart plugs)

I have run the WIFIScan.ino sketch and my network (jonas) is found.

  01: [CH 01] [9A:9D:5D:88:CE:BA] -27dBm * H 802.11g/n       
  02: [CH 01] [9A:9D:5D:88:CE:BD] -27dBm * V 802.11g/n       jonas
  03: [CH 01] [72:5B:F0:BC:7E:1B] -86dBm   H 802.11g/n   WPS 
  04: [CH 01] [8C:5B:F0:BC:7E:1E] -85dBm * V 802.11g/n   WPS XFSETUP-7E23
  05: [CH 01] [6E:3C:7C:07:F2:61] -65dBm * V 802.11g/n   WPS DIRECT-iU61-TR4700series

My sketch is very basic.

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "jonas"
#define STAPSK "*******"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);

  // We start by connecting to a WiFi network

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

  // WiFi.enableInsecureWEP(true);  // tried with true and false
  WiFi.mode(WIFI_STA);
  WiFi.setPhyMode(WIFI_PHY_MODE_11G); // tried both WIFI_PHY_MODE_11G and WIFI_PHY_MODE_11N
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(250);
    digitalWrite(LED_BUILTIN, LOW);
    delay(250);
    Serial.println("nope");
    Serial.println(WiFi.status());
    WiFi.printDiag(Serial);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(2000);

  Serial.println("connected");
  WiFi.printDiag(Serial);
}

The following is output repeatedly from the loop.

nope
7
Mode: STA
PHY mode: G
Channel: 1
AP id: 0
Status: 1
Auto connect: 1
SSID (5): jonas
Passphrase (10): *******
BSSID set: 0

The 7, I believe, represents WL_DISCONNECTED. The correct channel seems to be found but no connection is made.

This is a cheap device I got off AliExpress so it could just be broken, but the fact my wifi network is found gives me hope.

I have followed the suggestions in this post:

I thought this might be a power issue and have tried powering the device from a wall wart and my computer. No luck.

Any help/ideas/thoughts would be appreciated. Thank you for your time.

Show us the device. Usually they work just fine.
In most codes there is no need to actually get the whole diagnosis.

while (WiFi.status() != WL_CONNECTED) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(250);
    digitalWrite(LED_BUILTIN, LOW);
    delay(250);
    Serial.print(".");
  }
Serial.println();

just some dots until connection is successful.

WiFi.mode(WIFI_STA);
  //WiFi.setPhyMode(WIFI_PHY_MODE_11G); // comment this out, there is no need and may cause issues 
  WiFi.begin(ssid, password);                              // don't actually know what it does.

Now i am suspecting you got this correct, but it would be at least 8 characters long normally

#define STAPSK "*******"  // and now it's 7

The ESP will only connect to the 2.4GHz, i don't know how many devices you have connected to it over time, but it could be that it is out of free assignable DHCP ip addresses. Unplug the power wait 30 seconds and plug it back in to free all not connected IP addresses may help.

WiFi STA connection is the peak power demand from the board, but if there is an onboard 5v to 3.3v regulator you can assume that it ill provide sufficient power when connected to USB. Again show us the specific board you have.

1 Like

try WiFi.disconnect() once

1 Like

Thank you for your reply! I have attached a photo of the device. The chip is labelled ESP8266EX.

The extra debugging info was me trying to figure out what is not working. I was exploring the code/library trying to determine what other configuration options were available.

I don't think IPs are an issue (they may be eventually muhahaha), nevertheless I restarted the router and still no luck connecting.

I have a bunch of ESP8266MOD devices (see below), just waiting for a USB serial programmer to arrive.

Once again thank you for your reply and suggestions.

I added this line immediately before the begin and the device is still unable to connect

Is there where you would recommend calling disconnect?

  WiFi.enableInsecureWEP(false);
  WiFi.mode(WIFI_STA);
  WiFi.setPhyMode(WIFI_PHY_MODE_11G);

  WiFi.disconnect();
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
    Serial.println("nope");
    // Serial.println(WiFi.status());
    WiFi.printDiag(Serial);
  }

Thank you for your reply and suggestion!

I know this sounds basic but try moving closer to the modem if possible.

My router/modem is less than a meter away :frowning:

Thanks for the suggestion though!

I have had problems with wireless connection before too its a pain sometimes all the time.

I need to stop buying stuff from AliExpresss. :rofl: But everything is sooooo cheap :heart_eyes:

Yeah these are made for use with external antennas, but there is also an antenna onboard, can you verify that that is actually connected. Most of them connect the ceramic (?) antenna by default and you need to remove a resistor before you use an external antenna and it does look like that is the case.

You have nothing else lying around you can do that with ?
All you need is an UNO or a board with 2 hwSerial ports and a few resistors.
The pulldown on GPIO 15 is on there already, have i seen that correctly and a 3.3v regulator as well ?

I'm new to the idea of programming without a breakout board with a direct USB connection.

Can you recommend a tutorial I can follow or terms to Google? I have an old UNO board as well as several NANOs collecting dust that could be repurposed as programmers.

There is an open source project called Tasmota that I think describes what you are talking about but recommends using a specific serial device. If an old UNO can be repurposed that would be great.

Just so you know the direction I'm heading. My end goal would be to flash a few commercial ESP8266/ESP32 devices and get them working with my own locally running MQTT broker.

I have an RP2040 Nano arriving soon that I want to experiment adding some rudimentary speech recognition functionality to control devices connected to my MQTT broker.

I would prefer to not use anyone else's code and use this project as learning how to build IoT devices etc.

Thank again for your response! I have an antenna somewhere which I'll try later tonight.

After a lot of troubleshooting this evening I think I might have found the issue.

Further inspecting my WIFI network it appears it is using WPA3 (even thought the Xfinity app says WPA2).

My current hunch is that the firmware on the ESP8266 devices I have is rather old, before WPA3 support was added.

Does updating the firmware seem like the next logical step?

What firmware will you be updating ? The sketch you upload to the ESP8266 is the firmware, the SDK is included in the core. The only other firmware you can upload is back to the AT-commands.

I do not even quite know the difference, i know that ESP's only work at 2.4GHz not at 5GHz.

Here is another suggestion for this board though, how about uploading a small test sketch that starts it out in AP mode and let's you connect to a simple webserver, or even in both modes, that way you can test the hardware.

Well no not directly, i have decided that it would actually be best if i write my own, since i get confronted with this question so often and there are many tutorials out there that i do not support and even the ones i do support get modified. Using a Nano never worked for me, i think the USB to TTL converter somehow doesn't work so well as the 16u2 that is on an UNO, but if you have an Original UNO, that should work just fine and should even be able to provide the 3.3v if you need it.

I have just assited someone this week in this thread and post #15 contains a lot of information. It became a rather lengthy discussion where the OP missed a few things initially and i had to repeat myself a few times, but until i have finished my own tutorial, this is what i can refer to. Basically, do use the 3x 1K voltage divider (not 3x 10K) on the RX line. Make sure that GPIO 0 is connected to GND at boot to make the ESP go into Flash mode, have an empty sketch on the UNO and all should work just fine.

How many characters has your wifi password?

WPA is the encryption algorithm used for WIFI router authentication. WPA2 has been the standard but WPA3 addresses some security vulnerabilities.

Re-reading the above threads it seems to be an issue with the Arduino ESP8266 libraries specifically.

I misread the first time through, I thought the network stack firmware could be flashed. It appears to be the difference between the official ESP8266 libraries and the Arduino libraries. I got confused because I was prompted by the UNO R4 WIFI board to update the firmware of the ESP32.

Here is another suggestion for this board though, how about uploading a small test sketch that starts it out in AP mode and let's you connect to a simple webserver, or even in both modes, that way you can test the hardware.

Brilliant idea! I actually found a second board. I just setup one in AP with a webserver and the second in station mode with a web client. The board in station mode successfully connected to the Access Point and making HTTP requests. What's curious is neither my phone or my mac sees the new network. The UNO R4 WIFI sees the new network when scanning but unable to connect.

So the hardware works, but doesn't seem to be compatible with other 802.11g/n radios.

Probably time to invest in ESP32s.

Thank you for all your help! Very much appreciated. Small win tonight. I will review the thread you mentioned about programming. Thanks again!

Hi,

I did’t restore the firmware of ESP01. I followed this link

https://tttapa.github.io/ESP8266/Chap07%20-%20Wi-Fi%20Connections.html

uploaded the code to the module and it works. I received the response:

image001.gif

I do not believe it will work with WPA3. I created a second network for me on WPA1 WPA2 will also work to connect to wifi.

The antenna select shunt is positioned for using the onboard antenna.
image

Yeah that is a completely different matter.

I have never had issues connecting to ESP8266's or ESP32's for that matter.

You should be able to connect to it. Is your password 8 character or longer ? or not existing which will make the access point open (preferred choice for testing)

That link does not restore the at-command firmware but sets up a simple connection in station mode.

Try this:
My previous router is ancient and does not support WPA. As of ESP8266WiFi library Version 2.5.0, WPA is is the default mode. The solution was to get a better router, or add
WiFi.enableInsecureWEP();
before calling WiFi.begin().