//More information at: https://www.aeq-web.com/esp32-wifi-http-webserver-und-wlan-scanner/?ref=arduinoide #include // Set your Network Name and Password const char* ssid = "NETWORK-NAME"; const char* password = "PASSWORD"; WiFiServer server(80); char linebuf[80]; int charcount = 0; void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); //connect to Wifi network: while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); } void loop() { // listen for incoming clients WiFiClient client = server.available(); if (client) { Serial.println("New client"); long rssi = WiFi.RSSI(); memset(linebuf, 0, sizeof(linebuf)); charcount = 0; boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); //read char by char HTTP request linebuf[charcount] = c; if (charcount < sizeof(linebuf) - 1) charcount++; if (c == '\n' && currentLineIsBlank) { // send a standard http response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println(); client.println(""); client.println(""); client.println("

ESP32 WiFi HTTP Server

"); client.print("

RSSI: "); client.print(rssi); client.println(" dBm

"); client.print("

Local MAC: "); getMacAddress(client); client.println("

"); client.print("

Neighborhood networks:

"); getNetworks(client); client.println(""); client.println(""); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; memset(linebuf, 0, sizeof(linebuf)); charcount = 0; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive data delay(1); // close the connection client.stop(); Serial.println("client disconnected"); } } void getMacAddress(WiFiClient client) { byte mac[6]; WiFi.macAddress(mac); client.print(mac[5], HEX); client.print(":"); client.print(mac[4], HEX); client.print(":"); client.print(mac[3], HEX); client.print(":"); client.print(mac[2], HEX); client.print(":"); client.print(mac[1], HEX); client.print(":"); client.println(mac[0], HEX); } void getNetworks(WiFiClient client) { int numSsid = WiFi.scanNetworks(); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); for (int thisNet = 0; thisNet < numSsid; thisNet++) { client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); } client.println("
NRNamedBm
"); client.print(thisNet); client.println(""); client.print(WiFi.SSID(thisNet)); client.println(""); client.print(WiFi.RSSI(thisNet)); client.println("
"); }