Skip to content

Instantly share code, notes, and snippets.

@Ozsie
Last active January 8, 2018 19:25
Show Gist options
  • Save Ozsie/b1da23acf19ebf4c9f9e44160f61b2d6 to your computer and use it in GitHub Desktop.
Save Ozsie/b1da23acf19ebf4c9f9e44160f61b2d6 to your computer and use it in GitHub Desktop.
Configuration server
#include "wifitemp.h"
void setupServer() {
delay(1000);
Serial.println();
Serial.print("Configuring access point...");
const char *ssid = "wifi-temp";
const char *password = "wifi-temp";
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
Serial.print("Sensor ID: ");
Serial.println(ESP.getChipId());
Serial.println("HTTP server started. Configure with below HTTP request.");
Serial.print("GET ");
Serial.print(myIP);
Serial.println("/?ssid=<SSID>&password=<PASSWORD>");
server.on("/", handleConfig);
server.begin();
}
void handleConfig() {
handleStringConfig("ssid").toCharArray(conf.wifiSsid, sizeof(conf.wifiSsid) - 1);
handleStringConfig("password").toCharArray(conf.wifiPassword, sizeof(conf.wifiPassword) - 1);
server.send(200, "text/html", "<h1>OK!</h1>");
storeEeprom();
}
String handleStringConfig(String param) {
if (server.arg(param) == "") {
server.send(200, "text/html", "<h1>Missing parameter: " + param + "</h1>");
return "";
} else {
return server.arg(param);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment