Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <DNSServer.h>
DNSServer dnsServer;
ESP8266WebServer webServer(80);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//The SSID must be >8 characters and <64 characters
//I'm adding the chip ID onto the end to get a unique (ish) name
String ssid = "ESP8266 " + String(ESP.getChipId(), HEX);
//The password must be <64 characters and can be left blank for no password
String pass = "password";
Serial.printf("WiFiSSID: '%s'\n", ssid.c_str());
Serial.printf("Password: '%s'\n", pass.c_str());
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid.c_str(), pass.c_str());
Serial.println(WiFi.softAPIP());
webServer.on("/", [](){
webServer.send(200, "text/plain", "Hello World");
});
// Redirect all unknown traffic back to the homepage
webServer.onNotFound([](){
webServer.sendHeader("Location","/");
webServer.send(303);
});
MDNS.begin("esp");
dnsServer.start(53, "*", WiFi.softAPIP());
webServer.begin();
}
void loop() {
// put your main code here, to run repeatedly:
dnsServer.processNextRequest();
webServer.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment