diff --git a/README.md b/README.md
index 8321ac4..2e37c7e 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
# Clock made out of 7 segment displays
This is a clock made out of many 7 segment displays driven by a MAX7219 driver IC.
-Some parts of the 7 segment displays are driven like pixels.
\ No newline at end of file
+Some parts of the 7 segment displays are driven like pixels.
+
+## Setup / Preparations
+In Platformio, use "Project Tasks -> Platform -> Upload Filesystem Image" to upload the content of the data folder to the flash of the esp.
\ No newline at end of file
diff --git a/data/index.html b/data/index.html
new file mode 100644
index 0000000..fb69c1b
--- /dev/null
+++ b/data/index.html
@@ -0,0 +1,25 @@
+
+
+TooManySevenSegmentsClock
+
+
+
+
+
TooManySevenSegmentsClock
+
+
Time:
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/platformio.ini b/platformio.ini
index 5ae12ff..d049c66 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -14,11 +14,10 @@ board = d1_mini
framework = arduino
monitor_speed = 115200
upload_port = /dev/ttyUSB0
-
+board_build.filesystem = littlefs
lib_deps =
wayoda/LedControl@^1.0.6
adafruit/RTClib@^1.13.0
- tzapu/WiFiManager@^0.16.0
- adafruit/Adafruit SSD1306@^2.4.6
- adafruit/Adafruit GFX Library@^1.10.10
- adafruit/Adafruit BusIO@^1.8.2
+ me-no-dev/ESPAsyncTCP@^1.2.2
+ me-no-dev/ESP Async WebServer@^1.2.3
+ alanswx/ESPAsyncWiFiManager@^0.30
diff --git a/src/main.cpp b/src/main.cpp
index bf6cf14..43374fe 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,14 +2,16 @@
#include "LedControl.h"
#include "RTClib.h" // RTC library
-#include //https://github.com/esp8266/Arduino
-#include
-#include "WiFiManager.h" //https://github.com/tzapu/WiFiManager
+#include
+#include
+
+#include
+#include
#include
#include
-#include
-#include
+#include // Use the SPIFFS library for the filesystem
+#include
#include "disp.h"
@@ -54,22 +56,59 @@ unsigned long delaytime = 500;
char str[24];
-void configModeCallback(WiFiManager *myWiFiManager);
-ESP8266WebServer server(80);
+void configModeCallback(AsyncWiFiManager *myWiFiManager);
+AsyncWebServer server(80);
+DNSServer dns;
void handleRoot(); // function prototypes for HTTP handlers
void handleNotFound();
void handleBody();
void reconnect();
-void setTime(char* timeStr);
+void setTime(char *timeStr);
String SendHTML();
+String processor(const String &var);
void setup()
{
Serial.begin(115200);
+
+ delay(100);
+ Serial.println("Starting...");
+
+ if (!rtc.begin())
+ {
+ Serial.println("Couldn't find RTC");
+ delay(200);
+ ESP.reset();
+ }
+ else
+ {
+ Serial.println("RTC ready.");
+ }
+
+ /* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */
+ for (int i = 0; i < lc.getDeviceCount(); i++)
+ {
+ lc.shutdown(i, false);
+ lc.setIntensity(i, 8);
+ }
+
+ for (int i = 0; i < 8; i++)
+ {
+ lc.setDigit(1, i, 8, true);
+ }
+ Serial.println("Display initialized.");
+
+ // Initialize SPIFFS
+ if (!LittleFS.begin())
+ {
+ Serial.println("An Error has occurred while mounting LittleFS");
+ return;
+ }
+
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
- WiFiManager wifiManager;
+ AsyncWiFiManager wifiManager(&server, &dns);
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wifiManager.setAPCallback(configModeCallback);
@@ -79,51 +118,58 @@ void setup()
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect())
{
- Serial.println("failed to connect and hit timeout");
+ Serial.println("failed to connect Wifi and hit timeout");
//reset and try again, or maybe put it to deep sleep
- ESP.reset();
- delay(1000);
+ //ESP.reset();
+ //delay(1000);
+ }
+ else
+ {
+ //if you get here you have connected to the WiFi
+ Serial.println("Wifi connected.");
}
- //if you get here you have connected to the WiFi
- Serial.println("connected...yeey :)");
-
- server.on("/", handleRoot);
- server.on("/set_time", handleBody);
- server.onNotFound(handleNotFound);
+ //server.on("/", handleRoot);
+
+ // Route for root / web page
+ server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
+ { request->send(LittleFS, "/index.html", String(), false, processor); });
+
+ server.on("/set_time", HTTP_POST, [](AsyncWebServerRequest *request)
+ {
+ //List all parameters
+ int params = request->params();
+ uint8_t hours = rtc.now().hour();
+ uint8_t minutes = rtc.now().minute();
+
+ for (int i = 0; i < params; i++)
+ {
+ AsyncWebParameter *p = request->getParam(i);
+ if (p->isPost())
+ {
+ Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
+ if (p->name() == "hours")
+ {
+ hours = atoi(p->value().c_str());
+ }
+ else if (p->name() == "minutes")
+ {
+ minutes = atoi(p->value().c_str());
+ }
+ }
+ }
+ DateTime now = rtc.now();
+ rtc.adjust(DateTime(2021, 9, 17, hours, minutes, 0));
+ request->redirect("/");
+ });
server.begin();
Serial.println("HTTP server started");
-
- /* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */
- for (int i=0;igetConfigPortalSSID());
}
-void printNumber(int v)
-{
- int ones;
- int tens;
- int hundreds;
- boolean negative;
-
- if (v < -999 || v > 999)
- return;
- if (v < 0)
- {
- negative = true;
- v = v * -1;
- }
- ones = v % 10;
- v = v / 10;
- tens = v % 10;
- v = v / 10;
- hundreds = v;
- if (negative)
- {
- //print character '-' in the leftmost column
- lc.setChar(0, 3, '-', false);
- }
- else
- {
- //print a blank in the sign column
- lc.setChar(0, 3, ' ', false);
- }
- //Now print the number digit by digit
- lc.setDigit(0, 2, (byte)hundreds, false);
- lc.setDigit(0, 1, (byte)tens, false);
- lc.setDigit(0, 0, (byte)ones, false);
-}
-
void loop()
{
-
- server.handleClient();
setTime(str);
printString(str, lc);
}
-void setTime(char* timeStr) {
+void setTime(char *timeStr)
+{
DateTime now = rtc.now();
sprintf(timeStr, "%02d:%02d", now.hour(), now.minute());
}
-
-void handleRoot()
+// Replaces placeholder with minutes and hours
+String processor(const String &var)
{
- server.send(200, "text/html", SendHTML());
+ if (var == "HOURS")
+ {
+ return String((int)rtc.now().hour());
+ }
+ else if (var == "MINUTES")
+ {
+ return String((int)rtc.now().minute());
+ }
}
-
-void handleBody() { //Handler for the body path
-
- if (server.hasArg("hours")== false || server.hasArg("minutes")==false){ //Check if body received
-
- server.send(200, "text/plain", "Body not received");
- return;
-
- }
-
- uint8_t hours = atoi(server.arg("hours").c_str());
- uint8_t minutes = atoi(server.arg("minutes").c_str());
-
- DateTime now = rtc.now();
- rtc.adjust(DateTime(2021, 9, 17, hours, minutes, 0));
-
- server.send(200, "text/html", SendHTML());
-
-
-}
-
-void handleNotFound()
-{
- server.send(404, "text/plain", "Not found");
-}
-
-String SendHTML()
-{
- setTime(str);
- String ptr = " \n";
- ptr += "\n";
- ptr += "TooManySevenSegmentsClock\n";
- ptr += "\n";
- ptr += "\n";
- ptr += "\n";
- ptr += "\n";
- ptr += "
TooManySevenSegmentsClock
\n";
-
- ptr += "
Time: ";
- ptr += "
";
-
- ptr += "
";
-
-
- ptr += "
\n";
- ptr += "\n";
- ptr += "\n";
- return ptr;
-}
\ No newline at end of file