esp8266 broadcasting unwanted open wifi network

I just noticed that many of my esp8266 web servers are broadcasting an unwanted and obviously undesirable open network. These web servers are configured to join my home wifi network and do that satisfactorily.

While doing a wifi scan on my cell phone I noticed two open networks in my home with very strong signal strength and I traced them to my esp8266 servers. The ssid of one of these networks is ESP_152ca5 and is unsecured by a password even though my home wifi network that this server joins is password secured.

I can access these servers by simply connecting to the unsecured network and by using the server IP address I can access them without restriction. This sounds like a big security risk.

This seems to happen with any wifi server including those in the examples folder. I don't see any configuration settings that enable these open networks.

Can anybody tell me how to eliminate these unwanted open networks?

Here is the code from the Ardurino esp8266 example "WiFiWebServer" sketch.

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

const char* ssid = ".........";
const char* password = "........";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  // prepare GPIO2
  pinMode(2, OUTPUT);
  digitalWrite(2, 0);
  
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Start the server
  server.begin();
  Serial.println("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;
  }
  
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
  
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio/1") != -1)
    val = 1;
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 according to the request
  digitalWrite(2, val);
  
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
  s += (val)?"high":"low";
  s += "</html>\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed
}

There are several issues filed in the github issues tracker like this.

The most useful one appears to be Stop AP server · Issue #549 · esp8266/Arduino · GitHub

Suggests calling WiFi.mode(WIFI_STA) AFTER WiFi.Begin()

Let me know if it works..

1 Like

rw950431:
There are several issues filed in the github issues tracker like this.

The most useful one appears to be Stop AP server · Issue #549 · esp8266/Arduino · GitHub

Suggests calling WiFi.mode(WIFI_STA) AFTER WiFi.Begin()

Let me know if it works..

Yes, that works although none of my sketches have the wifi.mode statement included. So I had to add it. Many of these sketches were copied from the Arduino examples library and modified to accomplish my needs. I know very little about the wifi statements myself so I just copy from other sketches.

Anyway simply adding the wifi.mode statement fixes the problem. And it doesn't seem to matter if it is before or after the wifi.begin statement. BTW, the exact statement I used was WiFi.mode(WIFI_STA).

Furthermore, once the problem is fixed reverting back to the original sketch without that statement doesn't make the subject broadcast problem recur. It seems once the problem is fixed it doesn't come back. I have several esp8266 chips and they all behaved the same way. Kinda strange.

So I am happy that my problem is solved...Thank you very much, I owe you one.

:slight_smile: Glad to hear that!

It seems, from the various issues filed in the github repo, that the default behaviour has flip-flopped between various firmware revisions so its probably best to explicitly set the mode to avoid future surprises.

rw950431:
It seems, from the various issues filed in the github repo, that the default behaviour has flip-flopped between various firmware revisions so its probably best to explicitly set the mode to avoid future surprises.

I had the same issues and I am now setting the mode before (where every reasonable person would expect it) and after (where it actually works) the Wifi.begin.

What helped me is that I had some library functions to take care of common tasks, like starting the wifi, catering the MQTT connection, starting the OTA Update functionality ... This helped a lot, so I just had to change this in one place and just recompile ant OTA update all my nodes after I finally figured it out.
This is what I use: GitHub - kvoit/ESPTools: Some functions to do standard jobs in my ESP8266 projects and here is how I use it: https://github.com/kvoit/MqttLight/blob/master/examples/MOSFETWithSavedState/MOSFETWithSavedState.ino
(Not recommenting to clone and use theESPTtools, it is a little hacky at some points and not a stable API. Just as an example for the direction. Also always wanted to incorporate AP functionality for configuration of network without reflash ...)