From 21d9c26993d70531a767fb38fdc760fe6aba2b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Miko=C4=8Devi=C4=87?= Date: Fri, 30 Aug 2024 13:18:02 +0200 Subject: [PATCH] SD card /config load settings insert SD card with new settings in /config file and power cycle to load or web call /espReset --- include/mywebserver.h | 8 ++++-- include/mywifi.h | 3 ++ include/variables.h | 6 ++-- platformio.ini | 10 ++----- src/MozzCam.cpp | 64 ++++++++++++++++++++++++++++-------------- src/asyncWebServer.cpp | 8 +++--- src/prusa.cpp | 14 ++++++--- src/wifi.cpp | 4 +-- 8 files changed, 73 insertions(+), 44 deletions(-) diff --git a/include/mywebserver.h b/include/mywebserver.h index 8730181..053013d 100644 --- a/include/mywebserver.h +++ b/include/mywebserver.h @@ -28,6 +28,7 @@ esp_err_t loadFromSDCard( AsyncWebServerRequest* ); void initAsyncWebServer( void ); void doSnapSavePhoto( void ); extern String photoSendPrusaConnect( void ); +extern bool prusaPrinterOnline; String getHTMLRootText( void ); String getHTMLStatisticsText( void ); @@ -36,12 +37,15 @@ String getHTMLFullSetupText( void ); String getMetricsText( void ); String getCameraStatus( void ); -void fnElapsedStr( char* ); -void initSDCard( void ); +extern void fnElapsedStr( char* ); +extern void initSDCard( void ); extern bool SDCardOK; extern int tickerCounter; extern void reconfigureCamera( void ); extern void fnSetFrameSize( String ); +extern String httpUsernameStr; +extern String httpPasswordStr; + #endif diff --git a/include/mywifi.h b/include/mywifi.h index 35dfb92..673034b 100644 --- a/include/mywifi.h +++ b/include/mywifi.h @@ -25,4 +25,7 @@ void WiFiStationDisconnected( WiFiEvent_t, WiFiEventInfo_t ); void initWiFi( void ); void initOTA( void ); +extern String wifiSSIDStr; +extern String wifiPasswordStr; + #endif diff --git a/include/variables.h b/include/variables.h index 83e9105..4cf9c7d 100644 --- a/include/variables.h +++ b/include/variables.h @@ -3,11 +3,11 @@ #include -#define SW_VERSION "0.33.4" +#define SW_VERSION "0.33.5" #define HAVE_CAMERA #define ESP_CAM_HOSTNAME "mozz-cam" -#define CAM_SERIAL "1" +#define CAM_SERIAL "2" #define FLASH_ENABLED false @@ -19,7 +19,7 @@ #define SEALEVELPRESSURE_HPA (1013.25) #undef PRUSA_CONNECT -#define PRUSA_CONNECT_INTERVAL 75 +#define PRUSA_CONNECT_INTERVAL 72 #define PRUSA_PRINTER_IP "192.168.1.72" // your printer IP address extern String cameraNameSuffix; diff --git a/platformio.ini b/platformio.ini index a0156cb..7eab233 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,13 +14,7 @@ src_dir = src [env] framework = arduino -platform = - espressif32 -platform_packages = - ; framework-arduinoespressif32 - ; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.17 - framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.4 - framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.4/esp32-arduino-libs-3.0.4.zip +platform = espressif32 board_build.filesystem = littlefs lib_ldf_mode = chain+ lib_deps = @@ -42,7 +36,7 @@ build_flags = ; board_build.partitions = default.csv board_build.partitions = min_spiffs.csv ; board_build.partitions = partitions_custom.csv -upload_port = 192.168.1.161 +upload_port = 192.168.1.162 upload_protocol = espota ; upload_protocol = esptool ; upload_port = COM5 diff --git a/src/MozzCam.cpp b/src/MozzCam.cpp index 554b781..e614d9a 100644 --- a/src/MozzCam.cpp +++ b/src/MozzCam.cpp @@ -16,6 +16,11 @@ #include "mywebserver.h" #include "mywifi.h" +String httpUsernameStr; +String httpPasswordStr; +String wifiSSIDStr; +String wifiPasswordStr; + long timeZone = 1; byte daySaveTime = 1; struct tm startTime; @@ -38,6 +43,8 @@ bool bme280Found; bool prusaConnectActive = false; String prusaHTMLResponse; String prusaResponseCode; +String prusaTokenStr; +String camFingerPrintStr; Ticker tickerCam, tickerBME, tickerPrusa; boolean tickerCamFired, tickerBMEFired, tickerPrusaFired; @@ -158,9 +165,15 @@ esp_err_t loadConfigFromSD( void ) { return ESP_FAIL; } - // json {"http_username":"x","http_password":"y","wifi_ssid":"x","wifi_password":"y" \ - // ,"camera_name":"1","flash":"off","timelapse":"off","prusa_connect":"off"} + // json {"http_username":"x","http_password":"y","wifi_ssid":"x","wifi_password":"y", \ + // "camera_name":"cam_1","flash":"off","timelapse":"off", \ + // "prusa_connect":"off","prusa_token":"xx","camera_fingerprint":"uuigen"} + configParam = String( cameraConfig["camera_name"] ); + if( configParam != "" ) { + log_i( "Config %s", configParam ); + cameraNameSuffix = configParam; + } configParam = String( cameraConfig["flash"] ); if( configParam != "" ) { log_i( "Config %s", configParam ); @@ -185,30 +198,35 @@ esp_err_t loadConfigFromSD( void ) { else prusaConnectActive = false; } - configParam = String( cameraConfig["prusaToken"] ); + configParam = String( cameraConfig["prusa_token"] ); if( configParam != "" ) { log_i( "Config %s", configParam ); -// prusaToken = configParam; // String -> const *char + prusaTokenStr = configParam; } - configParam = String( cameraConfig["camFingerPrint"] ); + configParam = String( cameraConfig["camera_fingerprint"] ); if( configParam != "" ) { log_i( "Config %s", configParam ); -// camFingerPrint = configParam; + camFingerPrintStr = configParam; } - configParam = String( cameraConfig["camera_name"] ); + configParam = String( cameraConfig["wifi_ssid"] ); if( configParam != "" ) { log_i( "Config %s", configParam ); - cameraNameSuffix = configParam; + wifiSSIDStr = configParam; } - configParam = String( cameraConfig["wifi_ssid"] ); + configParam = String( cameraConfig["wifi_password"] ); if( configParam != "" ) { log_i( "Config %s", configParam ); - // ssid = configParam; // needs static space + wifiPasswordStr = configParam; } - configParam = String( cameraConfig["wifi_password"] ); + configParam = String( cameraConfig["http_username"] ); + if( configParam != "" ) { + log_i( "Config %s", configParam ); + httpUsernameStr = configParam; + } + configParam = String( cameraConfig["http_password"] ); if( configParam != "" ) { log_i( "Config %s", configParam ); - // password = configParam; // needs static space + httpPasswordStr = configParam; } return ESP_OK; @@ -329,15 +347,6 @@ void setup() { neopixelWrite( FLASH_LED, 0, RGB_BRIGHTNESS, 0 ); #endif - log_d( "Before initWiFi!" ); - initWiFi(); - log_d( "Before NTP!" ); - getNTPTime(); - -#ifdef CAMERA_MODEL_ESP32S3_CAM - neopixelWrite( FLASH_LED, 0, 0, 0 ); -#endif - #ifdef HAVE_CAMERA log_d( "Before initCam!" ); initCam(); // *HAS* to be *after* initSDCard() if board has SDCard ! @@ -347,12 +356,25 @@ void setup() { flashEnabled = false; #endif + log_d( "Before initWiFi!" ); + wifiSSIDStr = "" + String( wifi_ssid );; + wifiPasswordStr = "" + String( wifi_password );; + initWiFi(); + log_d( "Before NTP!" ); + getNTPTime(); + +#ifdef CAMERA_MODEL_ESP32S3_CAM + neopixelWrite( FLASH_LED, 0, 0, 0 ); +#endif + #ifdef HAVE_BME280 log_d( "Before initBME!" ); initBME(); // *HAS* to be *after* initSDCard() if board has SDCard ! Hmm, maybe not before #endif log_d( "Before initAsyncWebServer!" ); + httpUsernameStr = "" + String( http_username ); + httpPasswordStr = "" + String( http_password ); initAsyncWebServer(); log_d( "Before initOTA!" ); initOTA(); diff --git a/src/asyncWebServer.cpp b/src/asyncWebServer.cpp index 93ff1c6..3517457 100644 --- a/src/asyncWebServer.cpp +++ b/src/asyncWebServer.cpp @@ -23,7 +23,7 @@ extern bool timeLapse; bool checkWebAuth( AsyncWebServerRequest *request ) { - if( !request->authenticate( http_username, http_password ) ) { + if( !request->authenticate( httpUsernameStr.c_str(), httpPasswordStr.c_str() ) ) { request->send( 200, "text/html", NOT_AUTHORIZED ); log_d("auth-false"); return false; @@ -100,16 +100,16 @@ void asyncHandleLogin( AsyncWebServerRequest *request ) { if( request->hasParam( "user" ) ) { AsyncWebParameter* arg = request->getParam( "user" ); value = arg->value().c_str(); - if( value != http_username ) { + if( value != httpUsernameStr ) { } } if( request->hasParam( "password" ) ) { AsyncWebParameter* arg = request->getParam( "password" ); value = arg->value().c_str(); - if( value != http_password ) { + if( value != httpPasswordStr ) { } } - if( !request->authenticate( http_username, http_password ) ) + if( !request->authenticate( httpUsernameStr.c_str(), httpPasswordStr.c_str() ) ) return request->requestAuthentication(); // Hm? Double-check this return .. request->send( 200, "text/html", LOGIN_SUCCESS ); diff --git a/src/prusa.cpp b/src/prusa.cpp index d9d64a8..fe6e925 100644 --- a/src/prusa.cpp +++ b/src/prusa.cpp @@ -10,6 +10,9 @@ #define SEND_BLOCK_SIZE 1024 extern String photoFrameLength; +extern String prusaTokenStr; +extern String camFingerPrintStr; + bool prusaPrinterOnline; String photoSendPrusaConnect( void ) { @@ -22,6 +25,9 @@ String photoSendPrusaConnect( void ) { return "Printer OFFline!"; } + prusaTokenStr = "" + String( prusa_token ); + camFingerPrintStr = "" + String( camera_fingerprint ); + WiFiClientSecure prusa; prusa.setCACert( root_CAs ); @@ -35,10 +41,10 @@ String photoSendPrusaConnect( void ) { // camFingerPrint += String( ESP.getEfuseMac() ); - prusa.println( "fingerprint: " + String( camFingerPrint ) ); - log_v( "fingerprint: %s", String( camFingerPrint ).c_str() ); - prusa.println( "token: " + String( prusaToken ) ); - log_v( "token: %s", String( prusaToken ).c_str() ); + prusa.println( "fingerprint: " + camFingerPrintStr ); + log_v( "fingerprint: %s", camFingerPrintStr.c_str() ); + prusa.println( "token: " + prusaTokenStr ); + log_v( "token: %s", prusaTokenStr.c_str() ); prusa.println( "Content-Type: image/jpeg" ); uint32_t photoFrameLength = photoFrame.length(); prusa.println( "Content-Length: " + String( photoFrameLength ) ); diff --git a/src/wifi.cpp b/src/wifi.cpp index 93801c2..8dcc894 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -46,7 +46,7 @@ void WiFiStationDisconnected( WiFiEvent_t event, WiFiEventInfo_t info ) { log_i( "Reconnecting .." ); // WiFi.disconnect( ); // vTaskDelay( 4000 ); - WiFi.begin( wifi_ssid, wifi_password ); + WiFi.begin( wifiSSIDStr, wifiPasswordStr ); } @@ -124,7 +124,7 @@ void initWiFi( void ) { WiFi.onEvent( WiFiGotIP, ARDUINO_EVENT_WIFI_STA_GOT_IP ); WiFi.onEvent( WiFiStationDisconnected, ARDUINO_EVENT_WIFI_STA_DISCONNECTED ); WiFi.setHostname( ESP_CAM_HOSTNAME ); - WiFi.begin( wifi_ssid, wifi_password ); + WiFi.begin( wifiSSIDStr, wifiPasswordStr ); WiFi.setSleep( false ); WiFi.scanNetworks( true );