ESP8266 – Create an AP and list other APs in range

See below for example code that allows you to create a wireless network. Upon joining the network, you can browse to the ESP8266 IP address and it will list other Wireless networks in range.

It also outputs debug information to the Serial console.

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

const char *ssid = "ESP";
const char *password = "yourpassword";

String html;
String APList;

ESP8266WebServer server(80);

void handleRoot() {
	server.send(200, "text/html", html + "</body></html>");
}

void getAPList() {
  html = "<html><head><style>body { padding:20px; font-size:14px; font-family: Arial; line-height:22px; }</style></head><body>";
  int n = WiFi.scanNetworks();
   if (n > 0) {
    APList = APList + "<select>";
     for (int i = 0; i < n; ++i) {
      APList = APList + "<option value=''>" + WiFi.SSID(i) + "</option>";
     }
    APList = APList +  "</select>";
  } else {
    APList = APList + "<p>No Access Points found.</p>";
  }
  html = html + "Access Point: ";
  html = html + APList;
  delay(1000);
}

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

  getAPList();
  
	WiFi.softAP(ssid, password);
	IPAddress myIP = WiFi.softAPIP();
 
	Serial.print("AP IP address: ");
	Serial.println(myIP);
 
	server.on("/", handleRoot);
	server.begin();
}

void loop() {
	server.handleClient();
}