diff --git a/.gitignore b/.gitignore index 69107a2..4de822f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json .vscode/launch.json -.vscode/ipch \ No newline at end of file +.vscode/ipch +.DS_Store diff --git a/data/configure.css b/data/app.css similarity index 90% rename from data/configure.css rename to data/app.css index c2e401e..87c5117 100644 --- a/data/configure.css +++ b/data/app.css @@ -1,3 +1,6 @@ +body { + background-color: rgb(226, 226, 226); +} .dashboard{ text-align: center; } diff --git a/data/configure.html b/data/configure.html deleted file mode 100644 index 588a004..0000000 --- a/data/configure.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - -
- -
-
- -
- 24ºC -
-
- Temperature -
-
-
- -
-
-
- 22% -
-
- Humidity -
-
-
-
- \ No newline at end of file diff --git a/data/index.html b/data/index.html new file mode 100644 index 0000000..5e61eff --- /dev/null +++ b/data/index.html @@ -0,0 +1,36 @@ + + + + + + + +
+ +

paperdash.io

+ +
+
+ +
+ 24ºC +
+
+ Temperature +
+
+
+ +
+
+
+ 22% +
+
+ Humidity +
+
+
+
+ + \ No newline at end of file diff --git a/include/wlan.h b/include/wlan.h index 44e1943..a3bb42c 100644 --- a/include/wlan.h +++ b/include/wlan.h @@ -4,6 +4,6 @@ #include void setupWlan(); -bool wlan_isAPMode(); +bool wlan_isConnected(); #endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 0b44a9e..8c4f194 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,16 +2,16 @@ platform = espressif32 board = lolin32 framework = arduino +monitor_speed = 115200 ;upload_port = 192.168.178.60 # lolin32 -upload_speed = 921600 -monitor_speed = 115200 +;upload_speed = 921600 # lolin32 lite -;upload_speed = 115200 -;upload_port = /dev/cu.wchusbserial1460 +upload_speed = 115200 +upload_port = /dev/cu.wchusbserial1460 lib_deps = GxEPD2@~1.2.4 diff --git a/src/configure.cpp b/src/configure.cpp index f48c8a5..02d50bb 100644 --- a/src/configure.cpp +++ b/src/configure.cpp @@ -1,5 +1,4 @@ #include "configure.h" -#include "wlan.h" #include "SPIFFS.h" #include "ESPAsyncWebServer.h" @@ -8,36 +7,33 @@ AsyncWebServer server(80); + void setupConfigure() { - if (wlan_isAPMode()) - { - if (!SPIFFS.begin()) { - Serial.println("An Error has occurred while mounting SPIFFS"); - return; - } - - server.on("/dashboard", HTTP_GET, [](AsyncWebServerRequest *request){ - request->send(SPIFFS, "/dashboard.html", "text/html"); - }); - - server.on("/dashboard.css", HTTP_GET, [](AsyncWebServerRequest *request){ - request->send(SPIFFS, "/dashboard.css", "text/css"); - }); - - server.begin(); + Serial.println("setup configure"); + + if (!SPIFFS.begin()) { + Serial.println("An Error has occurred while mounting SPIFFS"); + return; } + + server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { + Serial.println("/"); + request->send(SPIFFS, "/index.html", "text/html"); + }); + + server.on("/app.css", HTTP_GET, [](AsyncWebServerRequest *request) { + Serial.println("/app.css"); + request->send(SPIFFS, "/app.css", "text/css"); + }); + + server.begin(); + + Serial.println("setup configure - done"); } void loopConfigure() { - if (wlan_isAPMode()) - { - // ap mode - } - else - { - // connected to wifi - } + } \ No newline at end of file diff --git a/src/device.cpp b/src/device.cpp index b0c5158..64447fc 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -16,10 +16,10 @@ String getWakeupReason(); void setupDevice() { // increment boot number and print it every reboot - //bootCount++; + bootCount++; - // config wakeup timer - deviceSetSleepInterval(300); + // TODO muss in der cloud passieren? config wakeup timer + //deviceSetSleepInterval(300); } diff --git a/src/main.cpp b/src/main.cpp index 61e21d6..bbaeb3d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,23 +24,29 @@ void setup() setupDisplay(); setupSettings(); - // setup hardware - //setupConfig(); - //setupDeepSleep(); setupDevice(); setupWlan(); - setupCloud(); + + if (wlan_isConnected()) + { + //setupCloud(); + } + + setupConfigure(); Serial.println(); - Serial.println("setup... done"); + Serial.println("setup - done"); } void loop() { // put your main code here, to run repeatedly: - loopCloud(); + if (wlan_isConnected()) + { + //loopCloud(); + } + loopDevice(); loopConfigure(); - } \ No newline at end of file diff --git a/src/wlan.cpp b/src/wlan.cpp index 25d3ea0..a598c9f 100644 --- a/src/wlan.cpp +++ b/src/wlan.cpp @@ -1,6 +1,8 @@ #include "wlan.h" #include "settings.h" +const char *deviceName = "paperdash-display"; +RTC_DATA_ATTR int wifiFailedCount = 0; void initClientMode(const char *ssid, const char *password); void initAPMode(); @@ -9,14 +11,18 @@ void initAPMode(); void setupWlan() { Serial.println("setup Wlan"); - WiFi.setHostname("paperdash-display"); + WiFi.setHostname(deviceName); + + //NVS.setString("wifi_ssid", "xd-design.info"); + //NVS.setString("wifi_password", "SonicHome"); // load wifi settings - String ssid = NVS.getString("wlan_ssid"); - String password = NVS.getString("wlan_password"); + String ssid = NVS.getString("wifi_ssid"); + String password = NVS.getString("wifi_password"); - if (true) + // TODO count failed connecting wifiFailedCount <=3 + if (!ssid.isEmpty() && !password.isEmpty()) // && wifiFailedCount <=3 { // client mode initClientMode(ssid.c_str(), password.c_str()); @@ -26,6 +32,8 @@ void setupWlan() // ap mode initAPMode(); } + + Serial.println("setup Wlan - done"); } @@ -33,49 +41,47 @@ void initClientMode(const char *ssid, const char *password) { long startMills = millis(); - WiFi.mode(WIFI_STA); + Serial.print(" Connecting to: "); + Serial.print(ssid); - Serial.print("Connecting to "); - Serial.println(ssid); + // print try count + Serial.print(" ("); + Serial.print(wifiFailedCount); + Serial.print("x)"); + // connecting + WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); - Serial.println(millis() - startMills); - - while (WiFi.waitForConnectResult() != WL_CONNECTED) { - // TODO count failed connecting - // on x failed, auto start AP mode + wifiFailedCount++; Serial.println("Connection Failed! Rebooting..."); delay(100); ESP.restart(); } - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); + Serial.println(" ...connected"); + Serial.print(" IP address: "); Serial.println(WiFi.localIP()); - Serial.print("connected in: "); + Serial.print(" connected in: "); Serial.println(millis() - startMills); - } void initAPMode() { + Serial.println(" init AP (Access Point)"); -} + WiFi.softAP(deviceName); - -bool wlan_isAPMode() -{ - return false; + IPAddress IP = WiFi.softAPIP(); + Serial.print(" AP IP address: "); + Serial.println(IP); } -void disableWlan() +bool wlan_isConnected() { - Serial.println("disable Wlan"); - //esp_wifi_stop(); + return WiFi.isConnected(); } \ No newline at end of file