Skip to content

Instantly share code, notes, and snippets.

@msraynsford
Created February 8, 2018 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msraynsford/c0f09feb10d08844758b56a3a8ee45ba to your computer and use it in GitHub Desktop.
Save msraynsford/c0f09feb10d08844758b56a3a8ee45ba to your computer and use it in GitHub Desktop.
#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