ESP8266 Won't find any networks

I've been trying to get a http server running on my Wemos D1 and it won't connect to any network. The network status code it returns indicates that it can't find the ssid I provided. I'm 100% sure it is typed correctly, but I even created a guest network on my router with the ssid "test" and it wouldn't connect to that either.

So after running a few test its seems like it really isn't finding my ssid. Or any ssid.

#include "ESP8266WiFi.h"

void setup()
{
  Serial.begin(115200);
  Serial.println();
}

void loop()
{
  int numberOfNetworks = WiFi.scanNetworks();

  Serial.print("Found ");
  Serial.print(numberOfNetworks);
  Serial.println(" Networks");
  for (int i = 0; i < numberOfNetworks; i++)
  {

    Serial.print("SSID: ");
    Serial.println(WiFi.SSID(i));
    Serial.print("Signal strength: ");
    Serial.println(WiFi.RSSI(i));
    Serial.println("-----------------------");
  }
  delay(2000);
}

This code constantly prints Found 0 Networks

My pc can see two 2.4ghz networks with strong signals.

I had an old router in my closet, so I set it up on my desk several inches from the arduino. Again, my pc sees the network, but the arduino does not.

Thinking that the wireless might not be working at all I found a sketch to turn the arduino into an access point. I uploaded this and instantly my pc could see the arduino's ssid. So the wifi works in at least some capacity.

Am I missing something or could this be as simple as a defective board?

Try adding this to setup and see if it makes any difference.

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

Didn't make any noticeable difference, unfortunately.

if I run the code of post 1 on a ESP8266 D1 Mini Pro I get

Found 3 Networks
SSID: TEG-020
Signal strength: -68
-----------------------
SSID: horace2017
Signal strength: -40
-----------------------
SSID: SKYF5A26
Signal strength: -81
-----------------------

do you require an external natenna?
sounds like you may have a damaged module

I've tried this code on 2 NodeMCU boards.

The code works fine on the "wide" "Lolin" board, but fails on the "narrow" board
yet both work fine on wifi in other ways.
So eg this code run on the narrow board gets the MAC address

#include <ESP8266WiFi.h>
void setup() {
  Serial.begin(115200);
  
}
void loop() {
delay(5000);
  Serial.print("MAC address: ");
  Serial.println(WiFi.macAddress());
}

tried it on 5 ESP8266 modules plus an ESP-01S all display the local SSIDs OK

I'm beginning to think there is something defective on this board.

I found that one can run MicroPython on this, so I had to install it just to play around and it doesn't connect either.

Oddly enough, scanning in micropython results in 2 networks found, but they return no ssid and their mac address doesn't match anything I have access to.

I'll just have to order another board and if it works I'll trash this one.

Edit: apparently I haven't had enough caffeine today and responded to the wrong person. Sorry about that.

I noticed that I had that same exact "narrow" board and decided to fire up your Wifi scan sketch on it.

As you'd expect, It worked fine.

Two things before you deep six the board:

  1. What board have you selected? I'm using esp8266:esp8266:nodemcuv2 (NodeMCU 1.0 (ESP-12E Module))

  2. I remembered the one time I had trouble with this board. Weird stuff: the sketch would start up, start printing some stuff... "go away" for awhile... print some garbage, then print the remainder of the scan. I scratched my head for quite a while before figuring out it was the cable. It appeared to work fine with other boards, but not with this one. I swapped cables and the code settled right down. Tossed that cable immediately. Figured the board was browning out due to higher than usual resistance in the cable/loose connection/gremlins.

This is interesting.

The cable I had been using for my D1 is fairly long, so I switched to another cable. No difference, still zero networks.

I switched to a 3rd cable and it found 2 networks!!! Both of these were the ad-hoc networks for my roku tvs (iirc their remotes operate via wifi) and it didn't see any of the 'real' networks available, but its progress.

I wouldn't think the power situation would be that finnicky, but apparently it made some kind of difference. I'm going to do more testing and plug the usb cable into the ports on the back of my pc instead of the front ports and use the shortest cable I can find. Idk if its resistance dropping the power enough to make it act up or just some other kind of interference, but I'll take any kind of progress I can get.

My feeling is that the WiFi on the "narrow" board is "weak" so maybe a small voltage difference could affect it.

I'm no expert, maybe someone could suggest code to investigate this issue further? I'd be interested to know why on these boards the scan fails but the "get MAC address" does (and operating as a client or server is "flaky")

If the issue is power-related you can connect a minimum 1000µF electrolytic capacitor as close as possible to the 5V and GND-pin

The ESP's cause short current-spikes.
And another thing adjusting the IDE with this options

Here is the code that I use for WiFi scanning

// 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

// if the code is unable to connect to a WiFi the code wil Scan for available WiFis
// and print a list of all found WiFis and theier signal strength
// the SSIDs start with a "#" and end with a "#"
// which means the characters inbetween the "#" signs show the complete name
// example #my SSID -# which has a SPACE inside the SSID and a minus-sign
// which might be overlooked without the embracing "#"

// 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

#if defined(ESP32)
#include <WiFi.h>
char deviceType[] = " ESP32";
#else
#include <ESP8266WiFi.h>
char deviceType[] = " ESP8266";
#endif

const char *ssid     = "Android AP";
const char *password = "12345678";


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__));
  Serial.print("Code runs on device-type");
  Serial.println(deviceType);
}



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 ScanForWiFis() {
  WiFi.disconnect(); // disconnect from WiFi to enable promiscuitive WiFi-mode
  Serial.println("WiFi.disconnect(); done wait 1 second");
  delay(1000);

  Serial.println("start scanning for WiFi...");
  int numberOfNetworks = WiFi.scanNetworks();
  Serial.println("scanning finished");
  Serial.print("number of networks: ");
  Serial.println(numberOfNetworks);

  for (int i = 0; i < numberOfNetworks; i++) {

    Serial.print("Network name: #");
    Serial.print(WiFi.SSID(i));
    Serial.print("# Signal strength: ");
    Serial.println(WiFi.RSSI(i));
    Serial.println("---------------------- -");
  }
}


void ConnectToWiFi() {
  const byte maxCount = 60;

  WiFi.mode(WIFI_STA);
  Serial.println("set WiFi.mode(WIFI_STA) done");

  int myCount = 0;

  Serial.println("trying to connect to SSID ");
  Serial.print("#");
  Serial.print(ssid);
  Serial.print("#");
  Serial.print(" with password #");
  Serial.print(password);
  Serial.println("#");
  Serial.print("for ");
  Serial.print(maxCount / 2);
  Serial.println(" seconds");

  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED && myCount < maxCount) {
    BlinkHeartBeatLED(OnBoard_LED, 50); // blink LED fast during attempt to connect
    yield();
    if ( TimePeriodIsOver(MyTestTimer, 500) ) { // once every 500 miliseconds
      Serial.print(".");                        // print a dot
      myCount++;
    }

    if (myCount >= maxCount) { // after 60 dots = 30 seconds restart
      Serial.println();
      Serial.println("trying to connect to WiFi with SSID");
      Serial.print("#");
      Serial.print(ssid);
      Serial.println("# failed.");
      Serial.println("Are you sure that the SSID ");
      Serial.print("#");
      Serial.print(ssid);
      Serial.print("#");
      Serial.print(" with password ");
      Serial.print("#");
      Serial.print(password);
      Serial.println("#");
      Serial.println("are correct ? ");

      ScanForWiFis();
    }
  }

  if (WiFi.status() == WL_CONNECTED ) {
    Serial.println("");
    Serial.print("Connected to #");
    Serial.print(ssid);
    Serial.print("# IP address: ");
    Serial.println(WiFi.localIP());
  }
}

void setup() {
  delay(2000);
  Serial.begin(115200);
  while (!Serial);
  delay(2000);
  Serial.println( F("Setup-Start") );
  PrintFileNameDateTime();
  ConnectToWiFi();
}


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) ) {
    if (WiFi.status() == WL_CONNECTED ) {
      PrintHelloMsg();
    }
    else {
      // Serial.println("not connected to WiFi");
    }
  }
}


/*
  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
*/

best regards Stefan

Mine isn't the same board as yours, its one of these:

I have a 5v 2a power supply I used as well and that didn't seem to make a difference. I'm thinking the one time it found some networks was just random luck.

Its strange to me that it found the roku networks once because they don't even broadcast their ssid.

This whole thing makes very little sense to me.

To analyse it deeper you should activate the highest debugging-level in the compiler-options about WiFi
like described in the screenshots.

Is this a $3 alieexpress-board? Well could be a quality problem then.

my ESP8266 WeMos D1 looks identical to the photo
if I run @StefanL38 code of post 11 I get

...............................................
trying to connect to WiFi with SSID
#Android AP# failed.
Are you sure that the SSID 
#Android AP# with password #12345678#
are correct ? 
WiFi.disconnect(); done wait 1 second
start scanning for WiFi...
scanning finished
number of networks: 4
Network name: #TEG-020# Signal strength: -64
---------------------- -
Network name: #horace2017# Signal strength: -43
---------------------- -
Network name: #VodafoneMobileWiFi-74FAF2# Signal strength: -92
---------------------- -
Network name: #SKYF5A26# Signal strength: -87
---------------------- -

@StefanL38
Thanks for that Stefan, I rearranged your code so that it does the scan first, then the connect;
I've tested it on my "working" Lolin board and all good.
Of my two "narrow" boards (Amica, using the cp2102 interface) one wont wifi and the other wont even upload, so I've filed them under "junk". And ordered more Lolin boards.

NodeMCU 1.0 (ESP-12E Module)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.