53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
#include <ESP8266WebServer.h>
|
|
#include <ESP8266WiFi.h>
|
|
#include <WiFiClient.h>
|
|
//#include <ESP8266HTTPClient.h>
|
|
#include <FS.h>
|
|
|
|
void setup_mode() {
|
|
WiFi.mode(WIFI_STA);
|
|
WiFi.hostname("flash-httpd");
|
|
WiFi.begin("WEMOS", "SNAPWIRE");
|
|
// Wait until we're connected.
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
Serial.print(".");
|
|
}
|
|
Serial.println("WiFi connected");
|
|
// Print the IP address
|
|
Serial.print("Use this URL to connect: ");
|
|
Serial.print("http://");
|
|
Serial.print(WiFi.localIP());
|
|
Serial.println("/");
|
|
}
|
|
|
|
void startup() {
|
|
File f = SPIFFS.open("/index.html", "r");
|
|
while (f.available()) {
|
|
// Lets read line by line from the file
|
|
String line = f.readStringUntil('\n');
|
|
Serial.println(line);
|
|
}
|
|
|
|
f = SPIFFS.open("/config.txt", "r");
|
|
if (!f.available()) {
|
|
Serial.println("Launching in access point mode.");
|
|
return;
|
|
}
|
|
Serial.println("Reading existing config.");
|
|
|
|
while (f.available()) {
|
|
// Lets read line by line from the file
|
|
String line = f.readStringUntil('\n');
|
|
Serial.println(line);
|
|
}
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
SPIFFS.begin();
|
|
startup();
|
|
}
|
|
|
|
void loop() { delay(2000); }
|