ESP8266 WifiClient/WifiServer fail to consistently connect to home network

I have three ESP8266 programmed using the ESP8266 core. Two are programmed with the WifiClient code and one with the WifiServer code. Two are WESMOS and the other is similar.

If only one is plugged into the serial I can see the debug information telling me its connected to the home network on 192.168.1.220, .221 and .222 respectively.

When more than one is plugged into the serial at least one fails to get an external ip address and comes up with 192.168.4.1, .2 or .3 which is the ip given when it starts as an access point.

Occasionally I get two running with correct ip addresses and on the rare occasion I have even had all three. No code changes between tests.

What is going on? What sort of tests should I try to untangle this. What further information would anyone want to help me with this.

Cheers Alan

I'm wondering if it could be a power problem. Do you have them all connected to an unpowered USB hub?

Yes, they are.

I'll try and source a powered one and also try plugging at least one into another PC/laptop.

So is it your expectation that if there isn't enough power then the fall-back condition would be to setup as an AP or at least take on the IP as if it had?

My expectation would be if it failed to connect to a network it would return an error code.

There is another library for the ESP8266 I have downloaded but yet to try successfully. It has many files exactly the same but some are significantly different. I have not experimented much with replacing the ones in c:...\packages... which I assume is being used when I have the ESP8266 core loaded. I didn't even know such as fie system existed until last week or even the concept of cores...

My simple attempts to remove the libraries by renaming it in the packages directory and placing the new ones into the arduino libraries path failed on account of #defines being absent during the compile process.

Ho hum.

Well I just know it takes a lot of current to run the WiFi radio so if it's not getting enough the process of connecting to the network could fail. Starting an AP won't require much current because it's not actually using the radio for this until something connects to the AP. If you're using a compliant unpowered hub then you only have 100 mA for each of them and I've seen reports of a single ESP8266 peaking at 500 mA or more while using the radio. If you're using a non-compliant hub then you still only have 500 mA total to share between the ESP8266s and the hub circuitry.

I bought a powered hub and no difference. If one connects to the home network the others 95% of the time don't.

I put one of the ESP8266s onto another PC and still the same problem.

It seems once one is on and looping its loop then the others don't get a look in. Stop the 'good' one and restart the one that went on 192.168.4.? and it then connects to the home network.

Doesn't seem to make any difference whether its running as a server or a client. It's in the setup() which is essentially the same for both. see server below. The loop runs with a 1 second delay to stop it thrashing about.

WiFiServer server(80);

void setup() {

  Serial.begin(115200);
  delay(10);


  Serial.print("Server connecting to ");
  Serial.println(ssid);


  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

It has also been observed that occasionally the ESP8266 will simply stop in its loop randomly and on occasion it runs but will report that its IP address is 0.0.0.0

What the ho hum is going on?

Left on ESP8266 on soak test. Here's the output. first number is millis() second is local IP

5314708 IP address: 192.168.1.222
5315708 IP address: 192.168.1.222
5316708 IP address: 192.168.1.222
5317709 IP address: 192.168.1.222
5318709 IP address: 192.168.1.222
5319709 IP address: 192.168.1.222
5320709 IP address: 192.168.1.222
5321709 IP address: 0.0.0.0
5322709 IP address: 0.0.0.0
5323710 IP address: 0.0.0.0
5324710 IP address: 192.168.1.222
5325710 IP address: 192.168.1.222
5326710 IP address: 192.168.1.222
5327711 IP address: 192.168.1.222
5328711 IP address: 192.168.1.222
5329711 IP address: 192.168.1.222
5330712 IP address: 192.168.1.222
5331712 IP address: 192.168.1.222
5332712 IP address: 192.168.1.222
5333712 IP address: 192.168.1.222
5334712 IP address: 192.168.1.222
5335712 IP address: 192.168.1.222

Ho hum

Slowly turning into a bad dream....

ESP2866 x2 currently running on one PC with 'correct' IP adressess for home network. Another PC with a single ESP8266 trying to connect in another room but failing to connect at all or coming back with the AP address.

Unplug the first two ESP8266s and the lone wolf in the other room connects straight away with a home network address.

I think these devices don't like sharing the airwaves....

acboother:
Slowly turning into a bad dream....

ESP2866 x2 currently running on one PC with 'correct' IP adressess for home network. Another PC with a single ESP8266 trying to connect in another room but failing to connect at all or coming back with the AP address.

Unplug the first two ESP8266s and the lone wolf in the other room connects straight away with a home network address.

I think these devices don't like sharing the airwaves....

What happens when you give them a fixed ip adress?

// Static IP details put this above the setup.
IPAddress ip(192, 168, 1, 222); //Replace with the ip you want to give
IPAddress gateway(192, 168, 1, 249); // replace with your router
IPAddress subnet(255, 255, 255, 0); // leave it
IPAddress dns(192, 168, 1, 249); //replace with router or alternative dns.

// Put this in the setup .
WiFi.config(ip, dns, gateway, subnet); //If you need Internet Access You should Add DNS also...
WiFi.begin(ssid, password);

For reference:

I'll give the static IP address a try when I get home.

Another oddity that has happened is when I loaded the scan sketch onto one of them and plain old blink onto the others.

One of the blink ESP8266s was identifying itself on network settings with the same name as the wifi extender! I now had the extender address twice to choose from on my laptop.

When this happened my laptop (I think) connected to the ESP8266 one automatically and I lost connection to the outside world (no internet connection).

Switching the ESP8266 off and the extra network name disappeared and the laptop reconnected to the outside world.

I am not very happy with what is going on with these devices :frowning:

acboother:
I’ll give the static IP address a try when I get home.

Another oddity that has happened is when I loaded the scan sketch onto one of them and plain old blink onto the others.

One of the blink ESP8266s was identifying itself on network settings with the same name as the wifi extender! I now had the extender address twice to choose from on my laptop.

When this happened my laptop (I think) connected to the ESP8266 one automatically and I lost connection to the outside world (no internet connection).

Switching the ESP8266 off and the extra network name disappeared and the laptop reconnected to the outside world.

I am not very happy with what is going on with these devices :frowning:

You are sure that your DHCP server at home is working properly? Since the ESP gets the IP adress from your router. A decent working DHCP server would never give the same ip adress that is already used to the ESP. Don’t rule a problem with your DHCP server out.

In fact I suspect that’s the cause of your problems and not the ESP.

I’ve not had any other issues with the router or the extender and have had these for years.

I think it’s what the two blinking ESPs think “they are called” as blink doesn’t attempt to do anything but set a port on/off.

There is no explicit wifi initialisation in the sketch itself - is something hidden away somewhere else? I was even surprised that they were found/seen during scan.

I will try and replicate some of this in a completely fresh environment but this will not be for some days

acboother:
There is no explicit wifi initialisation in the sketch itself - is something hidden away somewhere else? I was even surprised that they were found/seen during scan.

ESP8266 is tricky like that. It stores your settings in flash and automatically uses ones you set in a previous sketch even when you don't tell it to. You have to specifically tell it not to do that in your code.

pert:
ESP8266 is tricky like that. It stores your settings in flash and automatically uses ones you set in a previous sketch even when you don't tell it to. You have to specifically tell it not to do that in your code.

Kinda clever and kinda irritating...