auto generated AP name

pretty buttons
This commit is contained in:
Alex Tudorache
2015-11-10 11:04:01 +02:00
parent 87911808ab
commit e55057f686
4 changed files with 13 additions and 4 deletions
+5
View File
@@ -33,6 +33,11 @@ WiFiManager wifi;
```
//parameter is name of access point
wifi.autoConnect("AP-NAME");
```
or if you want to use and auto generated name from 'ESP' and the esp's Chip ID use
```
wifi.autoConnect();
```
After you write your sketch and start the ESP, it will try to connect to WiFi. If it fails it starts in Access Point mode.
+3 -2
View File
@@ -62,7 +62,8 @@ void WiFiManager::begin(char const *apName) {
}
boolean WiFiManager::autoConnect() {
return autoConnect("NoNetESP");
String ssid = "ESP" + String(ESP.getChipId());
return autoConnect(ssid.c_str());
}
boolean WiFiManager::autoConnect(char const *apName) {
@@ -283,7 +284,7 @@ void WiFiManager::handleRoot() {
server.sendContent(HTTP_HEAD_END);
server.sendContent(
"<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form>"
"<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/>"
);
server.sendContent(
"<form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form>"
+2 -2
View File
@@ -65,11 +65,11 @@ private:
const String HTTP_404 = "HTTP/1.1 404 Not Found\r\n\r\n";
const String HTTP_200 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
const String HTTP_STYLE = "<style>div,input {margin-bottom: 5px;}body{width:200px;display:block;margin-left:auto;margin-right:auto;}</style>";
const String HTTP_STYLE = "<style>div,input {margin-bottom: 5px;} body{width:200px;display:block;margin-left:auto;margin-right:auto;} button{padding:0.75rem 1rem;border:0;border-radius:0.317rem;background-color:#1fa3ec;color:#fff;line-height:1.5;cursor:pointer;}</style>";
const String HTTP_SCRIPT = "<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>";
const String HTTP_HEAD_END = "</head><body>";
const String HTTP_ITEM = "<div><a href='#' onclick='c(this)'>{v}</a></div>";
const String HTTP_FORM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><input id='p' name='p' length=64 placeholder='password'><br/><input type='submit'></form>";
const String HTTP_FORM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><input id='p' name='p' length=64 placeholder='password'><br/><button type='submit'>save</button></form>";
const String HTTP_SAVED = "<div>Credentials Saved<br />Node will reboot in 5 seconds.</div>";
const String HTTP_END = "</body></html>";
//const char HTTP_END[] PROGMEM = R"=====(
+3
View File
@@ -25,6 +25,9 @@ void setup() {
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
wifi.autoConnect("AutoConnectAP");
//or use this for auto generated name ESP + ChipID
//wifi.autoConnect();
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");