From 5ac98a773a5b0dc990467b86844cf829c0e5d717 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 03:15:33 +0200 Subject: [PATCH 01/36] exclude .vs/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 38fac82..13cd289 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .pio .vscode +.vs NerdMinerLog.txt bin/0x10000_firmware.bin logs From ad1dcda5a99f4579823b605a9a431dd25e5925bd Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 03:27:31 +0200 Subject: [PATCH 02/36] add board --- platformio.ini | 26 +++++++++++++++++++++++++- src/drivers/devices/esp32CAM.h | 9 +++++++++ src/drivers/drivers.h | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/drivers/devices/esp32CAM.h diff --git a/platformio.ini b/platformio.ini index dbf36b3..3a00bb0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [platformio] globallib_dir = lib -default_envs = NerminerV2, ESP32-devKitv1 +default_envs = NerminerV2, ESP32-devKitv1 [env:NerminerV2] platform = espressif32 @@ -137,3 +137,27 @@ lib_deps = arduino-libraries/NTPClient https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 https://github.com/FastLED/FastLED + +[env:esp32cam] +platform = espressif32 +board = esp32cam +framework = arduino +monitor_filters = + esp32_exception_decoder + time + log2file +board_build.arduino.memory_type = qio_opi +monitor_speed = 115200 +upload_speed = 230400 +board_build.partitions = huge_app.csv +build_flags = + -D ESP32_CAM + -D MONITOR_SPEED=${this.monitor_speed} + ;-D DEBUG_MINING=1 +lib_deps = + bblanchon/ArduinoJson@^6.21.2 + https://github.com/tzapu/WiFiManager.git + mathertel/OneButton @ ^2.0.3 + arduino-libraries/NTPClient +;lib_ignore = + ;TFT_eSPI diff --git a/src/drivers/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h new file mode 100644 index 0000000..08e0377 --- /dev/null +++ b/src/drivers/devices/esp32CAM.h @@ -0,0 +1,9 @@ +#ifndef _ESP32CAM_H_ +#define _ESP32CAM_H_ + +#define PIN_BUTTON_1 0 +#define LED_PIN 2 + +#define NO_DISPLAY + +#endif // _ESP32_CAM_H_ \ No newline at end of file diff --git a/src/drivers/drivers.h b/src/drivers/drivers.h index 6afbcc9..b2c1e46 100644 --- a/src/drivers/drivers.h +++ b/src/drivers/drivers.h @@ -11,6 +11,8 @@ #include "devices/lilygoS3Amoled.h" #elif defined(NERMINER_S3_DONGLE) #include "devices/lilygoS3Dongle.h" +#elif defined(ESP32_CAM) +#include "devices/esp32CAM.h" #else #error "No device defined" #endif From fa6f97d7c85f5aa3fb9254a73339e177473c79b8 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 04:00:18 +0200 Subject: [PATCH 03/36] update --- platformio.ini | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/platformio.ini b/platformio.ini index 3a00bb0..15f50de 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [platformio] globallib_dir = lib -default_envs = NerminerV2, ESP32-devKitv1 +default_envs = esp32cam ;NerminerV2, ESP32-devKitv1 [env:NerminerV2] platform = espressif32 @@ -146,18 +146,16 @@ monitor_filters = esp32_exception_decoder time log2file -board_build.arduino.memory_type = qio_opi monitor_speed = 115200 upload_speed = 230400 board_build.partitions = huge_app.csv build_flags = - -D ESP32_CAM + -D ESP32_CAM=1 -D MONITOR_SPEED=${this.monitor_speed} - ;-D DEBUG_MINING=1 lib_deps = bblanchon/ArduinoJson@^6.21.2 https://github.com/tzapu/WiFiManager.git mathertel/OneButton @ ^2.0.3 - arduino-libraries/NTPClient -;lib_ignore = - ;TFT_eSPI + arduino-libraries/NTPClient +lib_ignore = + TFT_eSPI From 5365ebf8ec894c796a726414281411cfdf9f5ced Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 04:06:01 +0200 Subject: [PATCH 04/36] baud rate set by build flag, if available --- src/NerdMinerV2.ino.cpp | 7 ++++++- src/wManager.cpp | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 94e802f..5c0e4a7 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -38,7 +38,12 @@ const char* ntpServer = "pool.ntp.org"; /********* INIT *****/ void setup() { - Serial.begin(115200); +#ifdef MONITOR_SPEED + Serial.begin(MONITOR_SPEED); +#else + Serial.begin(115200); +#endif //MONITOR_SPEED + Serial.setTimeout(0); delay(100); diff --git a/src/wManager.cpp b/src/wManager.cpp index 51b5d27..4248f05 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -135,7 +135,11 @@ void configModeCallback(WiFiManager *myWiFiManager) void init_WifiManager() { - Serial.begin(115200); +#ifdef MONITOR_SPEED + Serial.begin(MONITOR_SPEED); +#else + Serial.begin(115200); +#endif //MONITOR_SPEED //Serial.setTxTimeoutMs(10); //Init pin 15 to eneble 5V external power (LilyGo bug) From d5d0a1e63b44a01f8077e7725a3b9554ba6e826a Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 05:30:55 +0200 Subject: [PATCH 05/36] add header guards --- src/wManager.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wManager.h b/src/wManager.h index 870b435..7c8dc64 100644 --- a/src/wManager.h +++ b/src/wManager.h @@ -1,3 +1,8 @@ +#ifndef _WMANAGER_H +#define _WMANAGER_H + void init_WifiManager(); void wifiManagerProcess(); -void reset_configurations(); \ No newline at end of file +void reset_configurations(); + +#endif // _WMANAGER_H From 37ca603ed5958c7801fe384ffec26a42a46cfa80 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 09:26:28 +0200 Subject: [PATCH 06/36] separate spiffs --- src/drivers/SPIStorage/SPIStorage.h | 129 ++++++++ src/drivers/storage.h | 16 + src/mining.cpp | 16 +- src/monitor.cpp | 6 +- src/wManager.cpp | 450 ++++++++++++---------------- 5 files changed, 342 insertions(+), 275 deletions(-) create mode 100644 src/drivers/SPIStorage/SPIStorage.h create mode 100644 src/drivers/storage.h diff --git a/src/drivers/SPIStorage/SPIStorage.h b/src/drivers/SPIStorage/SPIStorage.h new file mode 100644 index 0000000..3a3ad35 --- /dev/null +++ b/src/drivers/SPIStorage/SPIStorage.h @@ -0,0 +1,129 @@ +#ifndef _SPISTORAGE_H_ +#define _SPISTORAGE_H_ + +#define ESP_DRD_USE_SPIFFS true + +#include +#include +#include + +#include + +#include "..\drivers.h" +#include "..\storage.h" + +// JSON configuration file +#define JSON_CONFIG_FILE "/config.json" + +class SPIStorage +{ +private: + bool SPIFFSInitialized_; +public: + SPIStorage() + { + SPIFFSInitialized_ = init(); + } + + ~SPIStorage() + { + SPIFFS.end(); + }; + + void saveConfigFile(TSettings*Settings) + { + // Save Config in JSON format + Serial.println(F("Saving configuration...")); + + // Create a JSON document + StaticJsonDocument<512> json; + json["poolString"] = Settings->PoolAddress; + json["portNumber"] = Settings->PoolPort; + json["btcString"] = Settings->BtcWallet; + json["gmtZone"] = Settings->Timezone; + + // Open config file + File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); + if (!configFile) + { + // Error, file did not open + Serial.println("failed to open config file for writing"); + } + + // Serialize JSON data to write to file + serializeJsonPretty(json, Serial); + if (serializeJson(json, configFile) == 0) + { + // Error writing file + Serial.println(F("Failed to write to file")); + } + // Close file + configFile.close(); + } + + bool init() + { + if (SPIFFSInitialized_) + return SPIFFSInitialized_; + return SPIFFS.begin(false) || SPIFFS.begin(true); + }; + + TSettings loadConfigFile() + { + // Load existing configuration file + // Uncomment if we need to format filesystem + // SPIFFS.format(); + + // Read configuration from FS json + Serial.println("Mounting File System..."); + TSettings Settings; + // May need to make it begin(true) first time you are using SPIFFS + if ((SPIFFSInitialized_)||(init())) + { + Serial.println("mounted file system"); + if (SPIFFS.exists(JSON_CONFIG_FILE)) + { + // The file exists, reading and loading + Serial.println("reading config file"); + File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); + if (configFile) + { + Serial.println("Opened configuration file"); + StaticJsonDocument<512> json; + DeserializationError error = deserializeJson(json, configFile); + configFile.close(); + serializeJsonPretty(json, Serial); + if (!error) + { + Serial.println("Parsing JSON"); + + strcpy(Settings.PoolAddress, json["poolString"]); + strcpy(Settings.BtcWallet, json["btcString"]); + Settings.PoolPort = json["portNumber"].as(); + Settings.Timezone = json["gmtZone"].as(); + Settings.holdsData = true; + } + else + { + // Error loading JSON data + Serial.println("Failed to load json config"); + } + } + } + } + else + { + // Error mounting file system + Serial.println("Failed to mount FS"); + } + return Settings; + } + + void deleteConfigFile() + { + Serial.println("Erasing config file.."); + SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero + } +}; + +#endif // _SPISTORAGE_H_ diff --git a/src/drivers/storage.h b/src/drivers/storage.h new file mode 100644 index 0000000..5fbd4b7 --- /dev/null +++ b/src/drivers/storage.h @@ -0,0 +1,16 @@ +#ifndef _STORAGE_H_ +#define _STORAGE_H_ + +class TSettings +{ +public: + char WifiSSID[80]{ "sA51" }; + char WifiPW[80]{ "0000" }; + char PoolAddress[80]{ "public-pool.io" }; + char BtcWallet[80]{ "yourBtcAddress" }; + uint32_t PoolPort{ 21496 }; + uint32_t Timezone{ 2 }; + bool holdsData{ false }; +}; + +#endif // _STORAGE_H_ \ No newline at end of file diff --git a/src/mining.cpp b/src/mining.cpp index 3d9d74b..454b4cf 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -9,6 +9,7 @@ #include "utils.h" #include "monitor.h" #include "drivers/display.h" +#include "drivers/storage.h" unsigned long templates = 0; unsigned long hashes= 0; @@ -23,9 +24,8 @@ unsigned int valids; // increased if blockhash <= target double best_diff = 0.0; // Variables to hold data from custom textboxes -extern char poolString[80]; -extern int portNumber; -extern char btcString[80]; +extern TSettings Settings; + IPAddress serverIP(1, 1, 1, 1); //Temporally save poolIPaddres //Global work data @@ -49,14 +49,14 @@ bool checkPoolConnection(void) { //Resolve first time pool DNS and save IP if(serverIP == IPAddress(1,1,1,1)) { - WiFi.hostByName(poolString, serverIP); + WiFi.hostByName(Settings.PoolAddress, serverIP); Serial.printf("Resolved DNS and save ip (first time) got: %s\n", serverIP.toString()); } //Try connecting pool IP - if (!client.connect(serverIP, portNumber)) { - Serial.println("Imposible to connect to : " + String(poolString)); - WiFi.hostByName(poolString, serverIP); + if (!client.connect(serverIP, Settings.PoolPort)) { + Serial.println("Imposible to connect to : " + String(Settings.PoolAddress)); + WiFi.hostByName(Settings.PoolAddress, serverIP); Serial.printf("Resolved DNS got: %s\n", serverIP.toString()); vTaskDelay(1000 / portTICK_PERIOD_MS); return false; @@ -156,7 +156,7 @@ void runStratumWorker(void *name) { continue; } - strcpy(mWorker.wName, btcString); + strcpy(mWorker.wName, Settings.BtcWallet); strcpy(mWorker.wPass, "x"); // STEP 2: Pool authorize work (Block Info) tx_mining_auth(client, mWorker.wName, mWorker.wPass); //Don't verifies authoritzation, TODO diff --git a/src/monitor.cpp b/src/monitor.cpp index a5c652e..c5bd398 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -7,8 +7,8 @@ #include "mining.h" #include "utils.h" #include "monitor.h" +#include "drivers/storage.h" -extern char poolString[80]; extern unsigned long templates; extern unsigned long hashes; extern unsigned long Mhashes; @@ -22,7 +22,7 @@ extern double best_diff; // track best diff extern monitor_data mMonitor; -extern int GMTzone; //Gotten from saved config +extern TSettings Settings; //Gotten from saved config WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); @@ -37,7 +37,7 @@ void setup_monitor(void){ // Adjust offset depending on your zone // GMT +2 in seconds (zona horaria de Europa Central) - timeClient.setTimeOffset(3600 * GMTzone); + timeClient.setTimeOffset(3600 * Settings.Timezone); Serial.println("TimeClient setup done"); } diff --git a/src/wManager.cpp b/src/wManager.cpp index 4248f05..3151e58 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -1,138 +1,68 @@ -#define ESP_DRD_USE_SPIFFS true // Include Libraries //#include ".h" #include -#include -#include #include -#include + #include "wManager.h" #include "monitor.h" #include "drivers/display.h" -// JSON configuration file -#define JSON_CONFIG_FILE "/config.json" +#include "drivers/SPIStorage/SPIStorage.h" +#include "drivers/storage.h" // Flag for saving data bool shouldSaveConfig = false; -// Variables to hold data from custom textboxes -char poolString[80] = "public-pool.io"; -int portNumber = 21496;//3333; -char btcString[80] = "yourBtcAddress"; -int GMTzone = 2; //Currently selected in spain - +DisplayDriver dongleDisplayDriver = {}; +TSettings Settings; +/* { + .BtcWallet = "", + .holdsData = false, + .PoolAddress = "", + .PoolPort = 0, + .Timezone = 0, + .WifiPW = "", + .WifiSSID = "" +} +*/ // Define WiFiManager Object WiFiManager wm; extern monitor_data mMonitor; -void saveConfigFile() -// Save Config in JSON format -{ - Serial.println(F("Saving configuration...")); - - // Create a JSON document - StaticJsonDocument<512> json; - json["poolString"] = poolString; - json["portNumber"] = portNumber; - json["btcString"] = btcString; - json["gmtZone"] = GMTzone; - - // Open config file - File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); - if (!configFile) - { - // Error, file did not open - Serial.println("failed to open config file for writing"); - } - - // Serialize JSON data to write to file - serializeJsonPretty(json, Serial); - if (serializeJson(json, configFile) == 0) - { - // Error writing file - Serial.println(F("Failed to write to file")); - } - // Close file - configFile.close(); -} - -bool loadConfigFile() -// Load existing configuration file -{ - // Uncomment if we need to format filesystem - // SPIFFS.format(); - - // Read configuration from FS json - Serial.println("Mounting File System..."); - - // May need to make it begin(true) first time you are using SPIFFS - if (SPIFFS.begin(false) || SPIFFS.begin(true)) - { - Serial.println("mounted file system"); - if (SPIFFS.exists(JSON_CONFIG_FILE)) - { - // The file exists, reading and loading - Serial.println("reading config file"); - File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); - if (configFile) - { - Serial.println("Opened configuration file"); - StaticJsonDocument<512> json; - DeserializationError error = deserializeJson(json, configFile); - configFile.close(); - serializeJsonPretty(json, Serial); - if (!error) - { - Serial.println("Parsing JSON"); - - strcpy(poolString, json["poolString"]); - strcpy(btcString, json["btcString"]); - portNumber = json["portNumber"].as(); - GMTzone = json["gmtZone"].as(); - return true; - } - else - { - // Error loading JSON data - Serial.println("Failed to load json config"); - } - } - } - } - else - { - // Error mounting file system - Serial.println("Failed to mount FS"); - } - - return false; -} - +SPIStorage SPIFS; void saveConfigCallback() // Callback notifying us of the need to save configuration { - Serial.println("Should save config"); - shouldSaveConfig = true; - //wm.setConfigPortalBlocking(false); + Serial.println("Should save config"); + shouldSaveConfig = true; + //wm.setConfigPortalBlocking(false); } -void configModeCallback(WiFiManager *myWiFiManager) +void configModeCallback(WiFiManager* myWiFiManager) // Called when config mode launched { - Serial.println("Entered Configuration Mode"); + Serial.println("Entered Configuration Mode"); - Serial.print("Config SSID: "); - Serial.println(myWiFiManager->getConfigPortalSSID()); + Serial.print("Config SSID: "); + Serial.println(myWiFiManager->getConfigPortalSSID()); - Serial.print("Config IP Address: "); - Serial.println(WiFi.softAPIP()); + Serial.print("Config IP Address: "); + Serial.println(WiFi.softAPIP()); } +void reset_configurations() +{ + Serial.println("Erasing Config, restarting"); + SPIFS.deleteConfigFile(); + wm.resetSettings(); + ESP.restart(); +} + + void init_WifiManager() { #ifdef MONITOR_SPEED @@ -140,186 +70,178 @@ void init_WifiManager() #else Serial.begin(115200); #endif //MONITOR_SPEED - //Serial.setTxTimeoutMs(10); + //Serial.setTxTimeoutMs(10); - //Init pin 15 to eneble 5V external power (LilyGo bug) - #ifdef PIN_ENABLE5V + //Init pin 15 to eneble 5V external power (LilyGo bug) +#ifdef PIN_ENABLE5V pinMode(PIN_ENABLE5V, OUTPUT); digitalWrite(PIN_ENABLE5V, HIGH); - #endif +#endif - // Change to true when testing to force configuration every time we run - bool forceConfig = false; + // Change to true when testing to force configuration every time we run + bool forceConfig = false; - #if defined(PIN_BUTTON_2) +#if defined(PIN_BUTTON_2) // Check if button2 is pressed to enter configMode with actual configuration - if(!digitalRead(PIN_BUTTON_2)){ - Serial.println(F("Button pressed to force start config mode")); - forceConfig = true; - wm.setBreakAfterConfig(true); //Set to detect config edition and save + if (!digitalRead(PIN_BUTTON_2)) { + Serial.println(F("Button pressed to force start config mode")); + resetConfig(); + forceConfig = true; + wm.setBreakAfterConfig(true); //Set to detect config edition and save } - #endif - - bool spiffsSetup = loadConfigFile(); - if (!spiffsSetup) - { - Serial.println(F("Forcing config mode as there is no saved config")); - forceConfig = true; - - } +#endif + // Explicitly set WiFi mode + WiFi.mode(WIFI_STA); - // Explicitly set WiFi mode - WiFi.mode(WIFI_STA); - - // Reset settings (only for development) - //wm.resetSettings(); - - //Set dark theme - //wm.setClass("invert"); // dark theme - - // Set config save notify callback - wm.setSaveConfigCallback(saveConfigCallback); - - // Set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode - wm.setAPCallback(configModeCallback); - - //Advanced settings - wm.setConfigPortalBlocking(false); //Hacemos que el portal no bloquee el firmware - wm.setConnectTimeout(50); // how long to try to connect for before continuing - //wm.setConfigPortalTimeout(30); // auto close configportal after n seconds - // wm.setCaptivePortalEnable(false); // disable captive portal redirection - // wm.setAPClientCheck(true); // avoid timeout if client connected to softap - //wm.setTimeout(120); - //wm.setConfigPortalTimeout(120); //seconds - - // Custom elements - - // Text box (String) - 80 characters maximum - WiFiManagerParameter pool_text_box("Poolurl", "Pool url", poolString, 80); - - // Need to convert numerical input to string to display the default value. - char convertedValue[6]; - sprintf(convertedValue, "%d", portNumber); - - // Text box (Number) - 7 characters maximum - WiFiManagerParameter port_text_box_num("Poolport", "Pool port", convertedValue, 7); - - // Text box (String) - 80 characters maximum - WiFiManagerParameter addr_text_box("btcAddress", "Your BTC address", btcString, 80); - - // Text box (Number) - 2 characters maximum - char charZone[6]; - sprintf(charZone, "%d", GMTzone); - WiFiManagerParameter time_text_box_num("TimeZone", "TimeZone fromUTC (-12/+12)", charZone, 3); - - // Add all defined parameters - wm.addParameter(&pool_text_box); - wm.addParameter(&port_text_box_num); - wm.addParameter(&addr_text_box); - wm.addParameter(&time_text_box_num); - - Serial.println("AllDone: "); - if (forceConfig) - // Run if we need a configuration - { - //No configuramos timeout al modulo - wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware - drawSetupScreen(); - if (!wm.startConfigPortal("NerdMinerAP","MineYourCoins")) + Settings = SPIFS.loadConfigFile(); + if (!Settings.holdsData) { - Serial.println("failed to connect and hit timeout"); - //Could be break forced after edditing, so save new config - strncpy(poolString, pool_text_box.getValue(), sizeof(poolString)); - portNumber = atoi(port_text_box_num.getValue()); - strncpy(btcString, addr_text_box.getValue(), sizeof(btcString)); - GMTzone = atoi(time_text_box_num.getValue()); - saveConfigFile(); - delay(3000); - //reset and try again, or maybe put it to deep sleep - ESP.restart(); - delay(5000); + Serial.println(F("Forcing config mode as there is no saved config")); + forceConfig = true; + }; + + // Reset settings (only for development) + //wm.resetSettings(); + + //Set dark theme + //wm.setClass("invert"); // dark theme + + // Set config save notify callback + wm.setSaveConfigCallback(saveConfigCallback); + + // Set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode + wm.setAPCallback(configModeCallback); + + //Advanced settings + wm.setConfigPortalBlocking(false); //Hacemos que el portal no bloquee el firmware + wm.setConnectTimeout(50); // how long to try to connect for before continuing + //wm.setConfigPortalTimeout(30); // auto close configportal after n seconds + // wm.setCaptivePortalEnable(false); // disable captive portal redirection + // wm.setAPClientCheck(true); // avoid timeout if client connected to softap + //wm.setTimeout(120); + //wm.setConfigPortalTimeout(120); //seconds + + // Custom elements + + // Text box (String) - 80 characters maximum + WiFiManagerParameter pool_text_box("Poolurl", "Pool url", Settings.PoolAddress, 80); + + // Need to convert numerical input to string to display the default value. + char convertedValue[6]; + sprintf(convertedValue, "%d", Settings.PoolPort); + + // Text box (Number) - 7 characters maximum + WiFiManagerParameter port_text_box_num("Poolport", "Pool port", convertedValue, 7); + + // Text box (String) - 80 characters maximum + WiFiManagerParameter addr_text_box("btcAddress", "Your BTC address", Settings.BtcWallet, 80); + + // Text box (Number) - 2 characters maximum + char charZone[6]; + sprintf(charZone, "%d", Settings.Timezone); + WiFiManagerParameter time_text_box_num("TimeZone", "TimeZone fromUTC (-12/+12)", charZone, 3); + + // Add all defined parameters + wm.addParameter(&pool_text_box); + wm.addParameter(&port_text_box_num); + wm.addParameter(&addr_text_box); + wm.addParameter(&time_text_box_num); + + Serial.println("AllDone: "); + if (forceConfig) + // Run if we need a configuration + { + //No configuramos timeout al modulo + wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware + drawSetupScreen(); + Settings = TSettings(); + if (!wm.startConfigPortal(Settings.WifiSSID, Settings.WifiPW)) + { + Serial.println("failed to connect and hit timeout"); + //Could be break forced after edditing, so save new config + strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress)); + Settings.PoolPort = atoi(port_text_box_num.getValue()); + strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); + Settings.Timezone = atoi(time_text_box_num.getValue()); + SPIFS.saveConfigFile(&Settings); + delay(3000); + //reset and try again, or maybe put it to deep sleep + ESP.restart(); + delay(5000); + } } - } - else - { - //Tratamos de conectar con la configuración inicial ya almacenada + else + { + //Tratamos de conectar con la configuración inicial ya almacenada + mMonitor.NerdStatus = NM_Connecting; + wm.setCaptivePortalEnable(false); // disable captive portal redirection + if (!wm.autoConnect(Settings.WifiSSID, Settings.WifiPW)) + { + Serial.println("Failed to connect and hit timeout"); + //delay(3000); + // if we still have not connected restart and try all over again + //ESP.restart(); + //delay(5000); + } + } + mMonitor.NerdStatus = NM_Connecting; - wm.setCaptivePortalEnable(false); // disable captive portal redirection - if (!wm.autoConnect("NerdMinerAP","MineYourCoins")) - { - Serial.println("Failed to connect and hit timeout"); - //delay(3000); - // if we still have not connected restart and try all over again - //ESP.restart(); - //delay(5000); + + //Conectado a la red Wifi + if (WiFi.status() == WL_CONNECTED) { + //tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); + Serial.println(""); + Serial.println("WiFi connected"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + + // Lets deal with the user config values + + // Copy the string value + strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress)); + Serial.print("PoolString: "); + Serial.println(Settings.PoolAddress); + + //Convert the number value + Settings.PoolPort = atoi(port_text_box_num.getValue()); + Serial.print("portNumber: "); + Serial.println(Settings.PoolPort); + + // Copy the string value + strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); + Serial.print("btcString: "); + Serial.println(Settings.BtcWallet); + + //Convert the number value + Settings.Timezone = atoi(time_text_box_num.getValue()); + Serial.print("TimeZone fromUTC: "); + Serial.println(Settings.Timezone); } - } - mMonitor.NerdStatus = NM_Connecting; - - //Conectado a la red Wifi - if(WiFi.status() == WL_CONNECTED){ - //tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); - Serial.println(""); - Serial.println("WiFi connected"); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); - - // Lets deal with the user config values - - // Copy the string value - strncpy(poolString, pool_text_box.getValue(), sizeof(poolString)); - Serial.print("PoolString: "); - Serial.println(poolString); - - //Convert the number value - portNumber = atoi(port_text_box_num.getValue()); - Serial.print("portNumber: "); - Serial.println(portNumber); - - // Copy the string value - strncpy(btcString, addr_text_box.getValue(), sizeof(btcString)); - Serial.print("btcString: "); - Serial.println(btcString); - - //Convert the number value - GMTzone = atoi(time_text_box_num.getValue()); - Serial.print("TimeZone fromUTC: "); - Serial.println(GMTzone); - } - - // Save the custom parameters to FS - if (shouldSaveConfig) - { - saveConfigFile(); - } + // Save the custom parameters to FS + if (shouldSaveConfig) + { + SPIFS.saveConfigFile(&Settings); + } } -void reset_configurations() { - Serial.println("Erasing Config, restarting"); - wm.resetSettings(); - SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero - ESP.restart(); -} - - //----------------- MAIN PROCESS WIFI MANAGER -------------- int oldStatus = 0; void wifiManagerProcess() { - - wm.process(); // avoid delays() in loop when non-blocking and other long running code - - int newStatus = WiFi.status(); - if (newStatus != oldStatus) { - if (newStatus == WL_CONNECTED) { - Serial.println("CONNECTED - Current ip: " + WiFi.localIP().toString()); - } else { - Serial.print("[Error] - current status: "); - Serial.println(newStatus); + + wm.process(); // avoid delays() in loop when non-blocking and other long running code + + int newStatus = WiFi.status(); + if (newStatus != oldStatus) { + if (newStatus == WL_CONNECTED) { + Serial.println("CONNECTED - Current ip: " + WiFi.localIP().toString()); + } else { + Serial.print("[Error] - current status: "); + Serial.println(newStatus); + } + oldStatus = newStatus; } - oldStatus = newStatus; - } } From 43f5d8fd5b060409a87487b5b0c2501020300291 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 09:29:50 +0200 Subject: [PATCH 07/36] Load settings from SD card. --- src/drivers/devices/esp32CAM.h | 9 ++- src/drivers/memoryCard/SDCard.h | 121 ++++++++++++++++++++++++++++++++ src/wManager.cpp | 11 ++- 3 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 src/drivers/memoryCard/SDCard.h diff --git a/src/drivers/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h index 08e0377..0dbb5f6 100644 --- a/src/drivers/devices/esp32CAM.h +++ b/src/drivers/devices/esp32CAM.h @@ -2,8 +2,15 @@ #define _ESP32CAM_H_ #define PIN_BUTTON_1 0 -#define LED_PIN 2 +#define LED_PIN 33 #define NO_DISPLAY +#define SDMMC_CLK 14 +#define SDMMC_CMD 15 +#define SDMMC_D0 2 +#define SDMMC_D1 4 +#define SDMMC_D2 12 +#define SDMMC_D3 13 + #endif // _ESP32_CAM_H_ \ No newline at end of file diff --git a/src/drivers/memoryCard/SDCard.h b/src/drivers/memoryCard/SDCard.h new file mode 100644 index 0000000..893e737 --- /dev/null +++ b/src/drivers/memoryCard/SDCard.h @@ -0,0 +1,121 @@ +#ifndef _SDCARD_H_ +#define _SDCARD_H_ + +#include +#include +#include + +#include + +#include "..\drivers.h" +#include "..\storage.h" +#include "..\SPIStorage\SPIStorage.h" + +#define JSON_CONFIG_FILE "/config.json" + +class SDCard +{ +private: + bool cardInitialized_; +public: + SDCard() + { + cardInitialized_ = initSDcard(); + } + + ~SDCard() + { + if (cardInitialized_) + SD_MMC.end(); + } + + bool initSDcard() + { + if (cardInitialized_) + return cardInitialized_; + + bool oneBitMode = true; +#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) + if (SD_MMC.cardType() == CARD_NONE) + SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); + oneBitMode = false; +#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) + if (SD_MMC.cardType() == CARD_NONE) + SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); +#else + Serial.println("SD card interface not available."); + return false; +#endif // dataPinsDefined + + if ((!SD_MMC.begin("/sdcard", oneBitMode)) || (SD_MMC.cardType() == CARD_NONE)) + { + Serial.println("No card available."); + return false; + } + return true; + } + + TSettings loadConfigFile() + { + // Load existing configuration file + // Read configuration from FS json + Serial.println("Mounting SD card..."); + TSettings Settings; + + if (initSDcard()) + { + Serial.println("mounted SD card."); + if (SD_MMC.exists(JSON_CONFIG_FILE)) + { + // The file exists, reading and loading + Serial.println("reading config file from sd."); + File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r"); + if (configFile) + { + Serial.println("Opened configuration file"); + StaticJsonDocument<512> json; + DeserializationError error = deserializeJson(json, configFile); + configFile.close(); + serializeJsonPretty(json, Serial); + if (!error) + { + Serial.println("Parsing JSON"); + strcpy(Settings.WifiSSID, json["SSID"]); + strcpy(Settings.WifiPW, json["Password"]); + strcpy(Settings.PoolAddress, json["PoolURL"]); + strcpy(Settings.BtcWallet, json["WalletID"]); + Settings.PoolPort = json["Port"].as(); + Settings.Timezone = json["Timezone"].as(); + Settings.holdsData = true; + } + else + { + // Error loading JSON data + Serial.println("Failed to load json config"); + } + } + SD_MMC.end(); + } + } + else + { + // Error mounting file system + Serial.println("Failed to mount SD card."); + } + return Settings; + } + + void SD2SPIStorage(SPIStorage* spifs) + { + TSettings Settings = loadConfigFile(); + if (Settings.holdsData) + { + spifs->saveConfigFile(&Settings); + WiFi.begin(Settings.WifiSSID, Settings.WifiPW); + Serial.println("Settings copied from SD card. Rebooting now."); + ESP.restart(); + } + } +}; + +#endif // _SDCARD_H_ diff --git a/src/wManager.cpp b/src/wManager.cpp index 3151e58..ea90a76 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -8,7 +8,7 @@ #include "wManager.h" #include "monitor.h" #include "drivers/display.h" - +#include "drivers/memoryCard/SDCard.h" #include "drivers/SPIStorage/SPIStorage.h" #include "drivers/storage.h" @@ -96,8 +96,13 @@ void init_WifiManager() Settings = SPIFS.loadConfigFile(); if (!Settings.holdsData) { - Serial.println(F("Forcing config mode as there is no saved config")); - forceConfig = true; + SDCard sdc; + if (sdc.loadConfigFile().holdsData) + { + Serial.println(F("No config file on internal flash, force config mode.")); + sdc.SD2SPIStorage(&SPIFS); // reboot on success. + forceConfig = true; + }; }; // Reset settings (only for development) From 9b0d7c7de2995dfcc829d7aa8dfe4eb023188302 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 09:32:46 +0200 Subject: [PATCH 08/36] update file --- src/wManager.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wManager.cpp b/src/wManager.cpp index ea90a76..3bbc927 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -248,5 +248,3 @@ void wifiManagerProcess() { oldStatus = newStatus; } } - - From 27f7a1bc83f56da0b5795522d3962d969601489b Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Tue, 12 Sep 2023 09:37:08 +0200 Subject: [PATCH 09/36] update --- src/wManager.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/wManager.cpp b/src/wManager.cpp index 3bbc927..0b979b8 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -18,16 +18,7 @@ bool shouldSaveConfig = false; DisplayDriver dongleDisplayDriver = {}; TSettings Settings; -/* { - .BtcWallet = "", - .holdsData = false, - .PoolAddress = "", - .PoolPort = 0, - .Timezone = 0, - .WifiPW = "", - .WifiSSID = "" -} -*/ + // Define WiFiManager Object WiFiManager wm; extern monitor_data mMonitor; From f2e2f8928440bddc5838155653d461cc9c8cf2b0 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 13 Sep 2023 02:47:40 +0200 Subject: [PATCH 10/36] rename file --- src/drivers/{memoryCard => SDCard}/SDCard.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/drivers/{memoryCard => SDCard}/SDCard.h (100%) diff --git a/src/drivers/memoryCard/SDCard.h b/src/drivers/SDCard/SDCard.h similarity index 100% rename from src/drivers/memoryCard/SDCard.h rename to src/drivers/SDCard/SDCard.h From f65ed4b4a32805835b346cf399a97ad752193c8f Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 13 Sep 2023 02:50:49 +0200 Subject: [PATCH 11/36] add vs files and directories --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 13cd289..5c1f29b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .pio .vscode .vs +*.sln +*.vcxproj* +x64 NerdMinerLog.txt bin/0x10000_firmware.bin logs From 3ea676ec7609132dec5a8892267a2d8eaf7185e7 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:06:40 +0200 Subject: [PATCH 12/36] change path --- src/mining.cpp | 2 +- src/monitor.cpp | 2 +- src/wManager.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mining.cpp b/src/mining.cpp index 454b4cf..ce65d99 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -9,7 +9,7 @@ #include "utils.h" #include "monitor.h" #include "drivers/display.h" -#include "drivers/storage.h" +#include "drivers/storage/storage.h" unsigned long templates = 0; unsigned long hashes= 0; diff --git a/src/monitor.cpp b/src/monitor.cpp index c5bd398..5ee329c 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -7,7 +7,7 @@ #include "mining.h" #include "utils.h" #include "monitor.h" -#include "drivers/storage.h" +#include "drivers/storage/storage.h" extern unsigned long templates; extern unsigned long hashes; diff --git a/src/wManager.cpp b/src/wManager.cpp index 0b979b8..65abb86 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -8,9 +8,9 @@ #include "wManager.h" #include "monitor.h" #include "drivers/display.h" -#include "drivers/memoryCard/SDCard.h" -#include "drivers/SPIStorage/SPIStorage.h" -#include "drivers/storage.h" +#include "drivers/storage/SDCard.h" +#include "drivers/storage/SPIStorage.h" +#include "drivers/storage/storage.h" // Flag for saving data bool shouldSaveConfig = false; From 281f5ec702209616210418b6d84604025d704e50 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:06:54 +0200 Subject: [PATCH 13/36] change path, correct UART output. --- src/drivers/SDCard/SDCard.h | 24 ++++++++++++------------ src/drivers/SPIStorage/SPIStorage.h | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/drivers/SDCard/SDCard.h b/src/drivers/SDCard/SDCard.h index 893e737..dff399a 100644 --- a/src/drivers/SDCard/SDCard.h +++ b/src/drivers/SDCard/SDCard.h @@ -8,8 +8,8 @@ #include #include "..\drivers.h" -#include "..\storage.h" -#include "..\SPIStorage\SPIStorage.h" +#include "storage.h" +#include "SPIStorage.h" #define JSON_CONFIG_FILE "/config.json" @@ -43,13 +43,13 @@ public: if (SD_MMC.cardType() == CARD_NONE) SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); #else - Serial.println("SD card interface not available."); + Serial.println("SDCard: interface not available."); return false; #endif // dataPinsDefined if ((!SD_MMC.begin("/sdcard", oneBitMode)) || (SD_MMC.cardType() == CARD_NONE)) { - Serial.println("No card available."); + Serial.println("SDCard: No card found."); return false; } return true; @@ -59,27 +59,27 @@ public: { // Load existing configuration file // Read configuration from FS json - Serial.println("Mounting SD card..."); + Serial.println("SDCard: Mounting File System..."); TSettings Settings; if (initSDcard()) { - Serial.println("mounted SD card."); + Serial.println("SDCard: Mounted"); if (SD_MMC.exists(JSON_CONFIG_FILE)) { // The file exists, reading and loading - Serial.println("reading config file from sd."); + Serial.println("SDCard: Reading config file"); File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r"); if (configFile) { - Serial.println("Opened configuration file"); + Serial.println("SDCard: Opened configuration file"); StaticJsonDocument<512> json; DeserializationError error = deserializeJson(json, configFile); configFile.close(); serializeJsonPretty(json, Serial); if (!error) { - Serial.println("Parsing JSON"); + Serial.println("SDCard: Parsing JSON"); strcpy(Settings.WifiSSID, json["SSID"]); strcpy(Settings.WifiPW, json["Password"]); strcpy(Settings.PoolAddress, json["PoolURL"]); @@ -91,7 +91,7 @@ public: else { // Error loading JSON data - Serial.println("Failed to load json config"); + Serial.println("SDCard: Failed to load json config"); } } SD_MMC.end(); @@ -100,7 +100,7 @@ public: else { // Error mounting file system - Serial.println("Failed to mount SD card."); + Serial.println("SDCard: Failed to mount."); } return Settings; } @@ -112,7 +112,7 @@ public: { spifs->saveConfigFile(&Settings); WiFi.begin(Settings.WifiSSID, Settings.WifiPW); - Serial.println("Settings copied from SD card. Rebooting now."); + Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); ESP.restart(); } } diff --git a/src/drivers/SPIStorage/SPIStorage.h b/src/drivers/SPIStorage/SPIStorage.h index 3a3ad35..2661be6 100644 --- a/src/drivers/SPIStorage/SPIStorage.h +++ b/src/drivers/SPIStorage/SPIStorage.h @@ -10,7 +10,7 @@ #include #include "..\drivers.h" -#include "..\storage.h" +#include "storage.h" // JSON configuration file #define JSON_CONFIG_FILE "/config.json" @@ -33,7 +33,7 @@ public: void saveConfigFile(TSettings*Settings) { // Save Config in JSON format - Serial.println(F("Saving configuration...")); + Serial.println(F("SPIFS: Saving configuration...")); // Create a JSON document StaticJsonDocument<512> json; @@ -47,7 +47,7 @@ public: if (!configFile) { // Error, file did not open - Serial.println("failed to open config file for writing"); + Serial.println("SPIFS: failed to open config file for writing"); } // Serialize JSON data to write to file @@ -55,7 +55,7 @@ public: if (serializeJson(json, configFile) == 0) { // Error writing file - Serial.println(F("Failed to write to file")); + Serial.println(F("SPIFS: Failed to write to file")); } // Close file configFile.close(); @@ -75,27 +75,27 @@ public: // SPIFFS.format(); // Read configuration from FS json - Serial.println("Mounting File System..."); + Serial.println("SPIFS: Mounting File System..."); TSettings Settings; // May need to make it begin(true) first time you are using SPIFFS if ((SPIFFSInitialized_)||(init())) { - Serial.println("mounted file system"); + Serial.println("SPIFS: Mounted"); if (SPIFFS.exists(JSON_CONFIG_FILE)) { // The file exists, reading and loading - Serial.println("reading config file"); + Serial.println("SPIFS: Reading config file"); File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); if (configFile) { - Serial.println("Opened configuration file"); + Serial.println("SPIFS: Opened configuration file"); StaticJsonDocument<512> json; DeserializationError error = deserializeJson(json, configFile); configFile.close(); serializeJsonPretty(json, Serial); if (!error) { - Serial.println("Parsing JSON"); + Serial.println("SPIFS: Parsing JSON"); strcpy(Settings.PoolAddress, json["poolString"]); strcpy(Settings.BtcWallet, json["btcString"]); @@ -106,7 +106,7 @@ public: else { // Error loading JSON data - Serial.println("Failed to load json config"); + Serial.println("SPIFS: Failed to load json config"); } } } @@ -114,14 +114,14 @@ public: else { // Error mounting file system - Serial.println("Failed to mount FS"); + Serial.println("SPIFS: Failed to mount."); } return Settings; } void deleteConfigFile() { - Serial.println("Erasing config file.."); + Serial.println("SPIFS: Erasing config file.."); SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero } }; From 21147a1adc8e3f413de4992579e0c6e2b7f6a60b Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 13 Sep 2023 03:40:55 +0200 Subject: [PATCH 14/36] move file --- src/drivers/{SDCard => storage}/SDCard.h | 0 src/drivers/{SPIStorage => storage}/SPIStorage.h | 0 src/drivers/{ => storage}/storage.h | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/drivers/{SDCard => storage}/SDCard.h (100%) rename src/drivers/{SPIStorage => storage}/SPIStorage.h (100%) rename src/drivers/{ => storage}/storage.h (100%) diff --git a/src/drivers/SDCard/SDCard.h b/src/drivers/storage/SDCard.h similarity index 100% rename from src/drivers/SDCard/SDCard.h rename to src/drivers/storage/SDCard.h diff --git a/src/drivers/SPIStorage/SPIStorage.h b/src/drivers/storage/SPIStorage.h similarity index 100% rename from src/drivers/SPIStorage/SPIStorage.h rename to src/drivers/storage/SPIStorage.h diff --git a/src/drivers/storage.h b/src/drivers/storage/storage.h similarity index 100% rename from src/drivers/storage.h rename to src/drivers/storage/storage.h From 4af1602b0a928bd15882e9f73587bc275299bf06 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:47:19 +0200 Subject: [PATCH 15/36] add uart ui --- src/drivers/storage/UARTCfgUI.h | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/drivers/storage/UARTCfgUI.h diff --git a/src/drivers/storage/UARTCfgUI.h b/src/drivers/storage/UARTCfgUI.h new file mode 100644 index 0000000..82be232 --- /dev/null +++ b/src/drivers/storage/UARTCfgUI.h @@ -0,0 +1,100 @@ + +#ifndef _UARTCFGUI_H_ +#define _UARTCFGUI_H_ + +#include + +#include "storage.h" +#include "SPIStorage.h" + +class SerialCfgUI +{ +public: + SerialCfgUI() + { + #ifdef MONITOR_SPEED + Serial.begin(MONITOR_SPEED); + #else + Serial.begin(115200); + #endif //MONITOR_SPEED + } + + void UARTUI2SPIStorage(SPIStorage* spifs) + { + TSettings Settings; + + if ((spifs->loadConfigFile(&Settings)) && StartUI(&Settings)) + { + spifs->saveConfigFile(&Settings); + WiFi.begin(Settings.WifiSSID, Settings.WifiPW); + Serial.println("SerialUI: Settings transfered to internal memory. Restarting now."); + ESP.restart(); + } + Serial.println("SerialUI: not started."); + } + +private: + + bool StartUI(TSettings* Settings) + { + Serial.println("Welcome to Nerdminer v2 serial config Interface."); + Serial.println("Fill out the form to set up your Nerdminer."); + Serial.println("Press 'Enter' to save your input or the default value."); + + strcpy(Settings->WifiSSID, readEntry("Enter Wifi SSID:", Settings->WifiSSID)); + strcpy(Settings->WifiPW, readEntry("Enter Wifi Password:", Settings->WifiPW)); + strcpy(Settings->PoolAddress, readEntry("Enter Pool Address:", Settings->PoolAddress)); + Settings->PoolPort = readEntry("Enter Pool Port:", Settings->PoolPort); + strcpy(Settings->BtcWallet, readEntry("Enter your BTC Wallet ID:", Settings->BtcWallet)); + Settings->Timezone = readEntry("Enter your Timezone (UTC+-12):", Settings->Timezone); + + Serial.println("Setup complete."); + + return true; + } + + template + T readEntry(const char* message = "newEntry:", T defaultvalue = "", const char delimieter = '\n') + requires( + (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v) + || (std::is_same_v)) + { + Serial.println(message); + + if(!String(defaultvalue).isEmpty()) + { + Serial.print("Default Value: >"); + Serial.print(defaultvalue); + Serial.println("<"); + }; + String value = Serial.readStringUntil(delimieter); + value.trim(); + while((value.length() > 0) && value.endsWith(String('\r'))) + value.remove(value.length()-1); + value.trim(); + if (value.length() > 0) + { + if constexpr (std::is_same_v) + return value; + else if constexpr ((std::is_same_v)|| (std::is_same_v)) + return value.c_str(); + else if constexpr (std::is_same_v) + return value.toInt(); + else if constexpr (std::is_same_v) + return value.toDouble(); + else if constexpr (std::is_same_v) + return value.toFloat(); + } + else + { + return defaultvalue; + } + } +}; + + +#endif // _UARTCFGUI_H_ \ No newline at end of file From 787d92820cf40e21e62705a482dd9448aaaa190e Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 14 Sep 2023 22:29:57 +0200 Subject: [PATCH 16/36] forma, adjust upload speed --- platformio.ini | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/platformio.ini b/platformio.ini index 15f50de..7251771 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,13 +23,11 @@ monitor_filters = board_build.arduino.memory_type = qio_opi monitor_speed = 115200 upload_speed = 115200 - # 2 x 4.5MB app, 6.875MB SPIFFS ;board_build.partitions = large_spiffs_16MB.csv ;board_build.partitions = default_8MB.csv board_build.partitions = huge_app.csv ;board_build.partitions = default.csv - build_flags = -D LV_LVGL_H_INCLUDE_SIMPLE -D BOARD_HAS_PSRAM @@ -45,7 +43,6 @@ lib_deps = arduino-libraries/NTPClient ;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 - [env:ESP32-devKitv1] platform = espressif32 board = esp32dev @@ -57,10 +54,8 @@ monitor_filters = ;board_build.arduino.memory_type = qio_opi monitor_speed = 115200 upload_speed = 115200 - # 2 x 4.5MB app, 6.875MB SPIFFS board_build.partitions = huge_app.csv - build_flags = -D DEVKITV1=1 ;-D DEBUG_MINING=1 @@ -71,7 +66,6 @@ lib_deps = mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient - [env:TTGO-T-Display] platform = espressif32 board = esp32dev ;esp-wrover-kit @@ -83,11 +77,8 @@ monitor_filters = board_build.arduino.memory_type = qio_opi monitor_speed = 115200 upload_speed = 115200 - - # 2 x 4.5MB app, 6.875MB SPIFFS board_build.partitions = huge_app.csv - build_flags = ;-D DEBUG_MINING=1 -D TDISPLAY=1 @@ -103,9 +94,7 @@ lib_deps = platform = espressif32 board = lilygo-t-display-s3 framework = arduino - board_build.partitions = huge_app.csv - build_flags = -DNERMINER_S3_AMOLED -DBOARD_HAS_PSRAM @@ -116,15 +105,13 @@ lib_deps = https://github.com/tzapu/WiFiManager.git mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient - https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 + ;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 [env:NerminerV2-S3-DONGLE] platform = espressif32 board = esp32-s3-devkitc-1 framework = arduino - board_build.partitions = huge_app.csv - build_flags = -DNERMINER_S3_DONGLE -DBOARD_HAS_PSRAM @@ -135,11 +122,11 @@ lib_deps = https://github.com/tzapu/WiFiManager.git mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient - https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 https://github.com/FastLED/FastLED + ;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 [env:esp32cam] -platform = espressif32 +platform = espressif32 ;(ESP32-D0WD-V3) board = esp32cam framework = arduino monitor_filters = @@ -147,10 +134,10 @@ monitor_filters = time log2file monitor_speed = 115200 -upload_speed = 230400 +upload_speed = 921600 board_build.partitions = huge_app.csv build_flags = - -D ESP32_CAM=1 + -D ESP32_CAM -D MONITOR_SPEED=${this.monitor_speed} lib_deps = bblanchon/ArduinoJson@^6.21.2 From ab48dbf5e309df2fa011d8a255b90e90fc90b39b Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 14 Sep 2023 22:32:25 +0200 Subject: [PATCH 17/36] cleanup, fix --- src/drivers/storage/SDCard.h | 114 +++++++++++++++++------------- src/drivers/storage/SPIStorage.h | 117 ++++++++++++++++--------------- src/drivers/storage/UARTCfgUI.h | 100 -------------------------- src/drivers/storage/storage.h | 51 ++++++++++++-- src/mining.cpp | 4 +- src/wManager.cpp | 35 +++++---- 6 files changed, 192 insertions(+), 229 deletions(-) delete mode 100644 src/drivers/storage/UARTCfgUI.h diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index dff399a..75c812a 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -11,8 +11,6 @@ #include "storage.h" #include "SPIStorage.h" -#define JSON_CONFIG_FILE "/config.json" - class SDCard { private: @@ -20,7 +18,7 @@ private: public: SDCard() { - cardInitialized_ = initSDcard(); + cardInitialized_ = false; } ~SDCard() @@ -29,42 +27,26 @@ public: SD_MMC.end(); } - bool initSDcard() + void SD2SPIStorage(SPIStorage* spifs) { - if (cardInitialized_) - return cardInitialized_; - - bool oneBitMode = true; -#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) - if (SD_MMC.cardType() == CARD_NONE) - SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); - oneBitMode = false; -#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) - if (SD_MMC.cardType() == CARD_NONE) - SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); -#else - Serial.println("SDCard: interface not available."); - return false; -#endif // dataPinsDefined - - if ((!SD_MMC.begin("/sdcard", oneBitMode)) || (SD_MMC.cardType() == CARD_NONE)) + TSettings Settings; + if (loadConfigFile(&Settings)) { - Serial.println("SDCard: No card found."); - return false; + spifs->saveConfigFile(&Settings); + WiFi.begin(Settings.WifiSSID, Settings.WifiPW); + Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); + ESP.restart(); } - return true; } - TSettings loadConfigFile() + bool loadConfigFile(TSettings* Settings) { // Load existing configuration file // Read configuration from FS json Serial.println("SDCard: Mounting File System..."); - TSettings Settings; if (initSDcard()) { - Serial.println("SDCard: Mounted"); if (SD_MMC.exists(JSON_CONFIG_FILE)) { // The file exists, reading and loading @@ -77,16 +59,20 @@ public: DeserializationError error = deserializeJson(json, configFile); configFile.close(); serializeJsonPretty(json, Serial); + Serial.print('\n'); if (!error) { Serial.println("SDCard: Parsing JSON"); - strcpy(Settings.WifiSSID, json["SSID"]); - strcpy(Settings.WifiPW, json["Password"]); - strcpy(Settings.PoolAddress, json["PoolURL"]); - strcpy(Settings.BtcWallet, json["WalletID"]); - Settings.PoolPort = json["Port"].as(); - Settings.Timezone = json["Timezone"].as(); - Settings.holdsData = true; + strcpy(Settings->WifiSSID, json[JSON_KEY_SSID] | Settings->WifiSSID); + strcpy(Settings->WifiPW, json[JSON_KEY_PASW] | Settings->WifiPW); + strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); + strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); + if (json.containsKey(JSON_KEY_POOLPORT)) + Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); + if (json.containsKey(JSON_KEY_TIMEZONE)) + Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); + SD_MMC.end(); + return true; } else { @@ -94,26 +80,54 @@ public: Serial.println("SDCard: Failed to load json config"); } } - SD_MMC.end(); } + else + { + Serial.println("SDCard: No config file available!"); + } + SD_MMC.end(); + } + return false; + } + +private: + + bool initSDcard() + { + if((cardInitialized_)&&(SD_MMC.cardType() != CARD_NONE)) + { + Serial.println("SDCard: Already mounted."); + return cardInitialized_; + } + + bool oneBitMode = true; +#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) + if (SD_MMC.cardType() == CARD_NONE) + { + SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); + oneBitMode = false; + Serial.println("SDCard: 4-Bit Mode."); + } +#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) + if (SD_MMC.cardType() == CARD_NONE) + { + SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); + Serial.println("SDCard: 1-Bit Mode."); + } +#else + Serial.println("SDCard: interface not available."); + return false; +#endif // dataPinsDefined + cardInitialized_ = SD_MMC.begin("/sdcard", oneBitMode); + if ((cardInitialized_) && (SD_MMC.cardType() != CARD_NONE)) + { + Serial.println("SDCard: Card mounted."); + return true; } else { - // Error mounting file system - Serial.println("SDCard: Failed to mount."); - } - return Settings; - } - - void SD2SPIStorage(SPIStorage* spifs) - { - TSettings Settings = loadConfigFile(); - if (Settings.holdsData) - { - spifs->saveConfigFile(&Settings); - WiFi.begin(Settings.WifiSSID, Settings.WifiPW); - Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); - ESP.restart(); + Serial.println("SDCard: No card found."); + return false; } } }; diff --git a/src/drivers/storage/SPIStorage.h b/src/drivers/storage/SPIStorage.h index 2661be6..c17d15f 100644 --- a/src/drivers/storage/SPIStorage.h +++ b/src/drivers/storage/SPIStorage.h @@ -12,9 +12,6 @@ #include "..\drivers.h" #include "storage.h" -// JSON configuration file -#define JSON_CONFIG_FILE "/config.json" - class SPIStorage { private: @@ -22,65 +19,60 @@ private: public: SPIStorage() { - SPIFFSInitialized_ = init(); + SPIFFSInitialized_ = false; } ~SPIStorage() { - SPIFFS.end(); + if (SPIFFSInitialized_) + SPIFFS.end(); }; void saveConfigFile(TSettings*Settings) { - // Save Config in JSON format - Serial.println(F("SPIFS: Saving configuration...")); - - // Create a JSON document - StaticJsonDocument<512> json; - json["poolString"] = Settings->PoolAddress; - json["portNumber"] = Settings->PoolPort; - json["btcString"] = Settings->BtcWallet; - json["gmtZone"] = Settings->Timezone; - - // Open config file - File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); - if (!configFile) + if (init()) { - // Error, file did not open - Serial.println("SPIFS: failed to open config file for writing"); - } + // Save Config in JSON format + Serial.println(F("SPIFS: Saving configuration...")); - // Serialize JSON data to write to file - serializeJsonPretty(json, Serial); - if (serializeJson(json, configFile) == 0) - { - // Error writing file - Serial.println(F("SPIFS: Failed to write to file")); - } - // Close file - configFile.close(); + // Create a JSON document + StaticJsonDocument<512> json; + json[JSON_KEY_POOLURL] = Settings->PoolAddress; + json[JSON_KEY_POOLPORT] = Settings->PoolPort; + json[JSON_KEY_WALLETID] = Settings->BtcWallet; + json[JSON_KEY_TIMEZONE] = Settings->Timezone; + + // Open config file + File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); + if (!configFile) + { + // Error, file did not open + Serial.println("SPIFS: failed to open config file for writing"); + } + + // Serialize JSON data to write to file + serializeJsonPretty(json, Serial); + Serial.print('\n'); + if (serializeJson(json, configFile) == 0) + { + // Error writing file + Serial.println(F("SPIFS: Failed to write to file")); + } + // Close file + configFile.close(); + }; } - bool init() + bool loadConfigFile(TSettings* Settings) { - if (SPIFFSInitialized_) - return SPIFFSInitialized_; - return SPIFFS.begin(false) || SPIFFS.begin(true); - }; - - TSettings loadConfigFile() - { - // Load existing configuration file // Uncomment if we need to format filesystem // SPIFFS.format(); + // Load existing configuration file // Read configuration from FS json - Serial.println("SPIFS: Mounting File System..."); - TSettings Settings; - // May need to make it begin(true) first time you are using SPIFFS - if ((SPIFFSInitialized_)||(init())) + + if (init()) { - Serial.println("SPIFS: Mounted"); if (SPIFFS.exists(JSON_CONFIG_FILE)) { // The file exists, reading and loading @@ -93,15 +85,17 @@ public: DeserializationError error = deserializeJson(json, configFile); configFile.close(); serializeJsonPretty(json, Serial); + Serial.print('\n'); if (!error) { Serial.println("SPIFS: Parsing JSON"); - - strcpy(Settings.PoolAddress, json["poolString"]); - strcpy(Settings.BtcWallet, json["btcString"]); - Settings.PoolPort = json["portNumber"].as(); - Settings.Timezone = json["gmtZone"].as(); - Settings.holdsData = true; + strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); + strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); + if(json.containsKey(JSON_KEY_POOLPORT)) + Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); + if (json.containsKey(JSON_KEY_TIMEZONE)) + Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); + return true; } else { @@ -111,12 +105,7 @@ public: } } } - else - { - // Error mounting file system - Serial.println("SPIFS: Failed to mount."); - } - return Settings; + return false; } void deleteConfigFile() @@ -124,6 +113,22 @@ public: Serial.println("SPIFS: Erasing config file.."); SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero } +private: + bool init() + { + if (!SPIFFSInitialized_) + { + Serial.println("SPIFS: Mounting File System..."); + // May need to make it begin(true) first time you are using SPIFFS + SPIFFSInitialized_ = SPIFFS.begin(false) || SPIFFS.begin(true); + SPIFFSInitialized_ ? Serial.println("SPIFS: Mounted") : Serial.println("SPIFS: Mounting failed."); + } + else + { + Serial.println("SPIFS: Already Mounted"); + } + return SPIFFSInitialized_; + }; }; #endif // _SPISTORAGE_H_ diff --git a/src/drivers/storage/UARTCfgUI.h b/src/drivers/storage/UARTCfgUI.h deleted file mode 100644 index 82be232..0000000 --- a/src/drivers/storage/UARTCfgUI.h +++ /dev/null @@ -1,100 +0,0 @@ - -#ifndef _UARTCFGUI_H_ -#define _UARTCFGUI_H_ - -#include - -#include "storage.h" -#include "SPIStorage.h" - -class SerialCfgUI -{ -public: - SerialCfgUI() - { - #ifdef MONITOR_SPEED - Serial.begin(MONITOR_SPEED); - #else - Serial.begin(115200); - #endif //MONITOR_SPEED - } - - void UARTUI2SPIStorage(SPIStorage* spifs) - { - TSettings Settings; - - if ((spifs->loadConfigFile(&Settings)) && StartUI(&Settings)) - { - spifs->saveConfigFile(&Settings); - WiFi.begin(Settings.WifiSSID, Settings.WifiPW); - Serial.println("SerialUI: Settings transfered to internal memory. Restarting now."); - ESP.restart(); - } - Serial.println("SerialUI: not started."); - } - -private: - - bool StartUI(TSettings* Settings) - { - Serial.println("Welcome to Nerdminer v2 serial config Interface."); - Serial.println("Fill out the form to set up your Nerdminer."); - Serial.println("Press 'Enter' to save your input or the default value."); - - strcpy(Settings->WifiSSID, readEntry("Enter Wifi SSID:", Settings->WifiSSID)); - strcpy(Settings->WifiPW, readEntry("Enter Wifi Password:", Settings->WifiPW)); - strcpy(Settings->PoolAddress, readEntry("Enter Pool Address:", Settings->PoolAddress)); - Settings->PoolPort = readEntry("Enter Pool Port:", Settings->PoolPort); - strcpy(Settings->BtcWallet, readEntry("Enter your BTC Wallet ID:", Settings->BtcWallet)); - Settings->Timezone = readEntry("Enter your Timezone (UTC+-12):", Settings->Timezone); - - Serial.println("Setup complete."); - - return true; - } - - template - T readEntry(const char* message = "newEntry:", T defaultvalue = "", const char delimieter = '\n') - requires( - (std::is_same_v) - || (std::is_same_v) - || (std::is_same_v) - || (std::is_same_v) - || (std::is_same_v) - || (std::is_same_v)) - { - Serial.println(message); - - if(!String(defaultvalue).isEmpty()) - { - Serial.print("Default Value: >"); - Serial.print(defaultvalue); - Serial.println("<"); - }; - String value = Serial.readStringUntil(delimieter); - value.trim(); - while((value.length() > 0) && value.endsWith(String('\r'))) - value.remove(value.length()-1); - value.trim(); - if (value.length() > 0) - { - if constexpr (std::is_same_v) - return value; - else if constexpr ((std::is_same_v)|| (std::is_same_v)) - return value.c_str(); - else if constexpr (std::is_same_v) - return value.toInt(); - else if constexpr (std::is_same_v) - return value.toDouble(); - else if constexpr (std::is_same_v) - return value.toFloat(); - } - else - { - return defaultvalue; - } - } -}; - - -#endif // _UARTCFGUI_H_ \ No newline at end of file diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index 5fbd4b7..bddb103 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -1,16 +1,53 @@ #ifndef _STORAGE_H_ #define _STORAGE_H_ +#define DEFAULT_SSID "NMAP" +#define DEFAULT_WIFIPW "1234567890" +#define DEFAULT_POOLURL "public-pool.io" +#define DEFAULT_WALLETID "yourBtcAddress" +#define DEFAULT_POOLPORT 21496 +#define DEFAULT_TIMEZONE 2 + +// JSON config file +#define JSON_CONFIG_FILE "/config.json" +#define JSON_KEY_SSID "SSID" +#define JSON_KEY_PASW "PW" +#define JSON_KEY_POOLURL "PoolUrl" +#define JSON_KEY_WALLETID "BtcWallet" +#define JSON_KEY_POOLPORT "PoolPort" +#define JSON_KEY_TIMEZONE "Timezone" + class TSettings { public: - char WifiSSID[80]{ "sA51" }; - char WifiPW[80]{ "0000" }; - char PoolAddress[80]{ "public-pool.io" }; - char BtcWallet[80]{ "yourBtcAddress" }; - uint32_t PoolPort{ 21496 }; - uint32_t Timezone{ 2 }; - bool holdsData{ false }; + char WifiSSID[80]{ DEFAULT_SSID }; + char WifiPW[80]{ DEFAULT_WIFIPW }; + char PoolAddress[80]{ DEFAULT_POOLURL }; + char BtcWallet[80]{ DEFAULT_WALLETID }; + uint32_t PoolPort{ DEFAULT_POOLPORT }; + uint32_t Timezone{ DEFAULT_TIMEZONE }; + + void print() + { + Serial.print("WifiSSID:>"); + Serial.print(WifiSSID); + Serial.print("<, "); + Serial.print("WifiPW:>"); + Serial.print(WifiPW); + Serial.print("<, "); + Serial.print("PoolAddress:>"); + Serial.print(PoolAddress); + Serial.print("<, "); + Serial.print("BtcWallet:>"); + Serial.print(BtcWallet); + Serial.print("<, "); + Serial.print("PoolPort:>"); + Serial.print(PoolPort); + Serial.print("<, "); + Serial.print("Timezone:>"); + Serial.print(Timezone); + Serial.println("<"); + } }; #endif // _STORAGE_H_ \ No newline at end of file diff --git a/src/mining.cpp b/src/mining.cpp index ce65d99..0395b57 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -402,8 +402,8 @@ void runMonitor(void *name) if (elapsedKHs == 0) { Serial.printf(">>> [i] Miner: newJob>%s / inRun>%s) - Client: connected>%s / subscribed>%s / wificonnected>%s\n", - mMiner.newJob ? "true" : "false", mMiner.inRun ? "true" : "false", - client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false"); + mMiner.newJob ? "true" : "false", mMiner.inRun ? "true" : "false", + client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false"); } #ifdef DEBUG_MEMORY diff --git a/src/wManager.cpp b/src/wManager.cpp index 65abb86..e49164b 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -12,6 +12,7 @@ #include "drivers/storage/SPIStorage.h" #include "drivers/storage/storage.h" + // Flag for saving data bool shouldSaveConfig = false; @@ -45,7 +46,7 @@ void configModeCallback(WiFiManager* myWiFiManager) Serial.println(WiFi.softAPIP()); } -void reset_configurations() +void reset_configurations() { Serial.println("Erasing Config, restarting"); SPIFS.deleteConfigFile(); @@ -53,7 +54,6 @@ void reset_configurations() ESP.restart(); } - void init_WifiManager() { #ifdef MONITOR_SPEED @@ -76,7 +76,7 @@ void init_WifiManager() // Check if button2 is pressed to enter configMode with actual configuration if (!digitalRead(PIN_BUTTON_2)) { Serial.println(F("Button pressed to force start config mode")); - resetConfig(); + reset_configurations(); forceConfig = true; wm.setBreakAfterConfig(true); //Set to detect config edition and save } @@ -84,16 +84,20 @@ void init_WifiManager() // Explicitly set WiFi mode WiFi.mode(WIFI_STA); - Settings = SPIFS.loadConfigFile(); - if (!Settings.holdsData) + if (!SPIFS.loadConfigFile(&Settings)) { + Serial.println(F("No config file on internal flash.")); SDCard sdc; - if (sdc.loadConfigFile().holdsData) + if (!sdc.loadConfigFile(&Settings)) { - Serial.println(F("No config file on internal flash, force config mode.")); - sdc.SD2SPIStorage(&SPIFS); // reboot on success. + Serial.println(F("No config file on SD card.")); forceConfig = true; - }; + } + else + { + Serial.println(F("Config file on SD card. Copy and restart.")); + sdc.SD2SPIStorage(&SPIFS); // reboot on success. + } }; // Reset settings (only for development) @@ -136,7 +140,7 @@ void init_WifiManager() char charZone[6]; sprintf(charZone, "%d", Settings.Timezone); WiFiManagerParameter time_text_box_num("TimeZone", "TimeZone fromUTC (-12/+12)", charZone, 3); - + // Add all defined parameters wm.addParameter(&pool_text_box); wm.addParameter(&port_text_box_num); @@ -144,21 +148,23 @@ void init_WifiManager() wm.addParameter(&time_text_box_num); Serial.println("AllDone: "); - if (forceConfig) - // Run if we need a configuration + if (forceConfig) { + // Run if we need a configuration //No configuramos timeout al modulo wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware drawSetupScreen(); - Settings = TSettings(); - if (!wm.startConfigPortal(Settings.WifiSSID, Settings.WifiPW)) + + if (!wm.startConfigPortal(DEFAULT_SSID, DEFAULT_WIFIPW)) { Serial.println("failed to connect and hit timeout"); //Could be break forced after edditing, so save new config + strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress)); Settings.PoolPort = atoi(port_text_box_num.getValue()); strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); Settings.Timezone = atoi(time_text_box_num.getValue()); + SPIFS.saveConfigFile(&Settings); delay(3000); //reset and try again, or maybe put it to deep sleep @@ -212,6 +218,7 @@ void init_WifiManager() Settings.Timezone = atoi(time_text_box_num.getValue()); Serial.print("TimeZone fromUTC: "); Serial.println(Settings.Timezone); + } // Save the custom parameters to FS From 80618d3cdc666cc1bcd2631370fd76703c468912 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 14 Sep 2023 23:16:56 +0200 Subject: [PATCH 18/36] SD card enable flag --- src/drivers/devices/esp32CAM.h | 2 + src/drivers/storage/SDCard.h | 238 ++++++++++++++++++--------------- 2 files changed, 130 insertions(+), 110 deletions(-) diff --git a/src/drivers/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h index 0dbb5f6..7911db7 100644 --- a/src/drivers/devices/esp32CAM.h +++ b/src/drivers/devices/esp32CAM.h @@ -6,6 +6,8 @@ #define NO_DISPLAY +#define BUILD_SDMMC + #define SDMMC_CLK 14 #define SDMMC_CMD 15 #define SDMMC_D0 2 diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 75c812a..2a1cfcc 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -1,135 +1,153 @@ #ifndef _SDCARD_H_ #define _SDCARD_H_ -#include -#include -#include - -#include - #include "..\drivers.h" #include "storage.h" #include "SPIStorage.h" class SDCard { -private: - bool cardInitialized_; public: - SDCard() - { - cardInitialized_ = false; - } + SDCard(); + ~SDCard(); + void SD2SPIStorage(SPIStorage* spifs); + bool loadConfigFile(TSettings* Settings); +private: + bool initSDcard(); - ~SDCard() - { - if (cardInitialized_) - SD_MMC.end(); - } + bool cardInitialized_; +}; - void SD2SPIStorage(SPIStorage* spifs) + +#ifdef BUILD_SDMMC + +#include +#include + +#include + +SDCard::SDCard() +{ + cardInitialized_ = false; +} + +SDCard::~SDCard() +{ + if (cardInitialized_) + SD_MMC.end(); +} + +void SDCard::SD2SPIStorage(SPIStorage* spifs) +{ + TSettings Settings; + if (loadConfigFile(&Settings)) { - TSettings Settings; - if (loadConfigFile(&Settings)) + spifs->saveConfigFile(&Settings); + WiFi.begin(Settings.WifiSSID, Settings.WifiPW); + Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); + ESP.restart(); + } +} + +bool SDCard::loadConfigFile(TSettings* Settings) +{ + // Load existing configuration file + // Read configuration from FS json + Serial.println("SDCard: Mounting File System..."); + + if (initSDcard()) + { + if (SD_MMC.exists(JSON_CONFIG_FILE)) { - spifs->saveConfigFile(&Settings); - WiFi.begin(Settings.WifiSSID, Settings.WifiPW); - Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); - ESP.restart(); - } - } - - bool loadConfigFile(TSettings* Settings) - { - // Load existing configuration file - // Read configuration from FS json - Serial.println("SDCard: Mounting File System..."); - - if (initSDcard()) - { - if (SD_MMC.exists(JSON_CONFIG_FILE)) + // The file exists, reading and loading + Serial.println("SDCard: Reading config file"); + File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r"); + if (configFile) { - // The file exists, reading and loading - Serial.println("SDCard: Reading config file"); - File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r"); - if (configFile) + Serial.println("SDCard: Opened configuration file"); + StaticJsonDocument<512> json; + DeserializationError error = deserializeJson(json, configFile); + configFile.close(); + serializeJsonPretty(json, Serial); + Serial.print('\n'); + if (!error) { - Serial.println("SDCard: Opened configuration file"); - StaticJsonDocument<512> json; - DeserializationError error = deserializeJson(json, configFile); - configFile.close(); - serializeJsonPretty(json, Serial); - Serial.print('\n'); - if (!error) - { - Serial.println("SDCard: Parsing JSON"); - strcpy(Settings->WifiSSID, json[JSON_KEY_SSID] | Settings->WifiSSID); - strcpy(Settings->WifiPW, json[JSON_KEY_PASW] | Settings->WifiPW); - strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); - strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); - if (json.containsKey(JSON_KEY_POOLPORT)) - Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); - if (json.containsKey(JSON_KEY_TIMEZONE)) - Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); - SD_MMC.end(); - return true; - } - else - { - // Error loading JSON data - Serial.println("SDCard: Failed to load json config"); - } + Serial.println("SDCard: Parsing JSON"); + strcpy(Settings->WifiSSID, json[JSON_KEY_SSID] | Settings->WifiSSID); + strcpy(Settings->WifiPW, json[JSON_KEY_PASW] | Settings->WifiPW); + strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); + strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); + if (json.containsKey(JSON_KEY_POOLPORT)) + Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); + if (json.containsKey(JSON_KEY_TIMEZONE)) + Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); + SD_MMC.end(); + return true; + } + else + { + // Error loading JSON data + Serial.println("SDCard: Failed to load json config"); } } - else - { - Serial.println("SDCard: No config file available!"); - } - SD_MMC.end(); - } - return false; - } - -private: - - bool initSDcard() - { - if((cardInitialized_)&&(SD_MMC.cardType() != CARD_NONE)) - { - Serial.println("SDCard: Already mounted."); - return cardInitialized_; - } - - bool oneBitMode = true; -#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) - if (SD_MMC.cardType() == CARD_NONE) - { - SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); - oneBitMode = false; - Serial.println("SDCard: 4-Bit Mode."); - } -#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) - if (SD_MMC.cardType() == CARD_NONE) - { - SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); - Serial.println("SDCard: 1-Bit Mode."); - } -#else - Serial.println("SDCard: interface not available."); - return false; -#endif // dataPinsDefined - cardInitialized_ = SD_MMC.begin("/sdcard", oneBitMode); - if ((cardInitialized_) && (SD_MMC.cardType() != CARD_NONE)) - { - Serial.println("SDCard: Card mounted."); - return true; } else { - Serial.println("SDCard: No card found."); - return false; + Serial.println("SDCard: No config file available!"); } + SD_MMC.end(); } -}; + return false; +} + +bool SDCard::initSDcard() +{ + if((cardInitialized_)&&(SD_MMC.cardType() != CARD_NONE)) + { + Serial.println("SDCard: Already mounted."); + return cardInitialized_; + } + + bool oneBitMode = true; +#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) + if (SD_MMC.cardType() == CARD_NONE) + { + SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); + oneBitMode = false; + Serial.println("SDCard: 4-Bit Mode."); + } +#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) + if (SD_MMC.cardType() == CARD_NONE) + { + SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); + Serial.println("SDCard: 1-Bit Mode."); + } +#else + Serial.println("SDCard: interface not available."); + return false; +#endif // dataPinsDefined + cardInitialized_ = SD_MMC.begin("/sdcard", oneBitMode); + if ((cardInitialized_) && (SD_MMC.cardType() != CARD_NONE)) + { + Serial.println("SDCard: Card mounted."); + return true; + } + else + { + Serial.println("SDCard: No card found."); + return false; + } +} + +#else + +SDCard::SDCard() {} +SDCard::~SDCard() {} +void SDCard::SD2SPIStorage(SPIStorage* spifs) {}; +bool SDCard::loadConfigFile(TSettings* Settings) { return false; } +bool SDCard::initSDcard() { return false; } + +#endif //BUILD_SDMMC + #endif // _SDCARD_H_ From 2e5be19a60c47c41c3ea74fa393c7c968938314a Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 14 Sep 2023 23:18:08 +0200 Subject: [PATCH 19/36] prepare for builds without SD support --- src/wManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/wManager.cpp b/src/wManager.cpp index e49164b..a1c526f 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -86,17 +86,18 @@ void init_WifiManager() if (!SPIFS.loadConfigFile(&Settings)) { - Serial.println(F("No config file on internal flash.")); + //No config file on internal flash. SDCard sdc; if (!sdc.loadConfigFile(&Settings)) { - Serial.println(F("No config file on SD card.")); - forceConfig = true; + //No config file on SD card. + sdc.SD2SPIStorage(&SPIFS); // reboot on success. + } else { - Serial.println(F("Config file on SD card. Copy and restart.")); - sdc.SD2SPIStorage(&SPIFS); // reboot on success. + //Config file on SD card. Copy and restart. + forceConfig = true; } }; From 91ae5ef60cf80a6644c47bf2810b43aacd19e345 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 00:27:19 +0200 Subject: [PATCH 20/36] better identifiers --- src/drivers/storage/SDCard.h | 10 +- src/drivers/storage/SPIStorage.h | 134 ------------------------- src/drivers/storage/nvMemory.h | 167 +++++++++++++++++++++++++++++++ src/wManager.cpp | 18 ++-- 4 files changed, 181 insertions(+), 148 deletions(-) delete mode 100644 src/drivers/storage/SPIStorage.h create mode 100644 src/drivers/storage/nvMemory.h diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 2a1cfcc..8734178 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -3,14 +3,14 @@ #include "..\drivers.h" #include "storage.h" -#include "SPIStorage.h" +#include "nvMemory.h" class SDCard { public: SDCard(); ~SDCard(); - void SD2SPIStorage(SPIStorage* spifs); + void SD2nvMemory(nvMemory* nvMem); bool loadConfigFile(TSettings* Settings); private: bool initSDcard(); @@ -37,12 +37,12 @@ SDCard::~SDCard() SD_MMC.end(); } -void SDCard::SD2SPIStorage(SPIStorage* spifs) +void SDCard::SD2nvMemory(NVMem* nvMem) { TSettings Settings; if (loadConfigFile(&Settings)) { - spifs->saveConfigFile(&Settings); + nvMem->saveConfig(&Settings); WiFi.begin(Settings.WifiSSID, Settings.WifiPW); Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); ESP.restart(); @@ -143,7 +143,7 @@ bool SDCard::initSDcard() SDCard::SDCard() {} SDCard::~SDCard() {} -void SDCard::SD2SPIStorage(SPIStorage* spifs) {}; +void SDCard::SD2nvMemory(nvMemory* nvMem) {}; bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } diff --git a/src/drivers/storage/SPIStorage.h b/src/drivers/storage/SPIStorage.h deleted file mode 100644 index c17d15f..0000000 --- a/src/drivers/storage/SPIStorage.h +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef _SPISTORAGE_H_ -#define _SPISTORAGE_H_ - -#define ESP_DRD_USE_SPIFFS true - -#include -#include -#include - -#include - -#include "..\drivers.h" -#include "storage.h" - -class SPIStorage -{ -private: - bool SPIFFSInitialized_; -public: - SPIStorage() - { - SPIFFSInitialized_ = false; - } - - ~SPIStorage() - { - if (SPIFFSInitialized_) - SPIFFS.end(); - }; - - void saveConfigFile(TSettings*Settings) - { - if (init()) - { - // Save Config in JSON format - Serial.println(F("SPIFS: Saving configuration...")); - - // Create a JSON document - StaticJsonDocument<512> json; - json[JSON_KEY_POOLURL] = Settings->PoolAddress; - json[JSON_KEY_POOLPORT] = Settings->PoolPort; - json[JSON_KEY_WALLETID] = Settings->BtcWallet; - json[JSON_KEY_TIMEZONE] = Settings->Timezone; - - // Open config file - File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); - if (!configFile) - { - // Error, file did not open - Serial.println("SPIFS: failed to open config file for writing"); - } - - // Serialize JSON data to write to file - serializeJsonPretty(json, Serial); - Serial.print('\n'); - if (serializeJson(json, configFile) == 0) - { - // Error writing file - Serial.println(F("SPIFS: Failed to write to file")); - } - // Close file - configFile.close(); - }; - } - - bool loadConfigFile(TSettings* Settings) - { - // Uncomment if we need to format filesystem - // SPIFFS.format(); - - // Load existing configuration file - // Read configuration from FS json - - if (init()) - { - if (SPIFFS.exists(JSON_CONFIG_FILE)) - { - // The file exists, reading and loading - Serial.println("SPIFS: Reading config file"); - File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); - if (configFile) - { - Serial.println("SPIFS: Opened configuration file"); - StaticJsonDocument<512> json; - DeserializationError error = deserializeJson(json, configFile); - configFile.close(); - serializeJsonPretty(json, Serial); - Serial.print('\n'); - if (!error) - { - Serial.println("SPIFS: Parsing JSON"); - strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); - strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); - if(json.containsKey(JSON_KEY_POOLPORT)) - Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); - if (json.containsKey(JSON_KEY_TIMEZONE)) - Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); - return true; - } - else - { - // Error loading JSON data - Serial.println("SPIFS: Failed to load json config"); - } - } - } - } - return false; - } - - void deleteConfigFile() - { - Serial.println("SPIFS: Erasing config file.."); - SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero - } -private: - bool init() - { - if (!SPIFFSInitialized_) - { - Serial.println("SPIFS: Mounting File System..."); - // May need to make it begin(true) first time you are using SPIFFS - SPIFFSInitialized_ = SPIFFS.begin(false) || SPIFFS.begin(true); - SPIFFSInitialized_ ? Serial.println("SPIFS: Mounted") : Serial.println("SPIFS: Mounting failed."); - } - else - { - Serial.println("SPIFS: Already Mounted"); - } - return SPIFFSInitialized_; - }; -}; - -#endif // _SPISTORAGE_H_ diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h new file mode 100644 index 0000000..448e1fb --- /dev/null +++ b/src/drivers/storage/nvMemory.h @@ -0,0 +1,167 @@ +#ifndef _NVMEMORY_H_ +#define _NVMEMORY_H_ + +#define BUILD_SPIFFS + +#include "..\drivers.h" +#include "storage.h" + +class nvMemory +{ +public: + nvMemory(); + ~nvMemory(); + bool saveConfig(TSettings* Settings); + bool loadConfig(TSettings* Settings); + bool deleteConfig(); +private: + bool init(); + bool Initialized_; +}; + +#ifdef BUILD_SPIFFS + +#define ESP_DRD_USE_SPIFFS true + +#include +#include +#include +#include + +nvMemory::nvMemory() +{ + Initialized_ = false; +} + +nvMemory::~nvMemory() +{ + if (Initialized_) + SPIFFS.end(); +}; + +bool nvMemory::saveConfig(TSettings* Settings) +{ + if (init()) + { + // Save Config in JSON format + Serial.println(F("SPIFS: Saving configuration...")); + + // Create a JSON document + StaticJsonDocument<512> json; + json[JSON_KEY_POOLURL] = Settings->PoolAddress; + json[JSON_KEY_POOLPORT] = Settings->PoolPort; + json[JSON_KEY_WALLETID] = Settings->BtcWallet; + json[JSON_KEY_TIMEZONE] = Settings->Timezone; + + // Open config file + File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); + if (!configFile) + { + // Error, file did not open + Serial.println("SPIFS: failed to open config file for writing"); + return false; + } + + // Serialize JSON data to write to file + serializeJsonPretty(json, Serial); + Serial.print('\n'); + if (serializeJson(json, configFile) == 0) + { + // Error writing file + Serial.println(F("SPIFS: Failed to write to file")); + return false; + } + // Close file + configFile.close(); + return true; + }; + return false; +} + +bool nvMemory::loadConfig(TSettings* Settings) +{ + // Uncomment if we need to format filesystem + // SPIFFS.format(); + + // Load existing configuration file + // Read configuration from FS json + + if (init()) + { + if (SPIFFS.exists(JSON_CONFIG_FILE)) + { + // The file exists, reading and loading + Serial.println("SPIFS: Reading config file"); + File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); + if (configFile) + { + Serial.println("SPIFS: Opened configuration file"); + StaticJsonDocument<512> json; + DeserializationError error = deserializeJson(json, configFile); + configFile.close(); + serializeJsonPretty(json, Serial); + Serial.print('\n'); + if (!error) + { + Serial.println("SPIFS: Parsing JSON"); + strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); + strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); + if (json.containsKey(JSON_KEY_POOLPORT)) + Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); + if (json.containsKey(JSON_KEY_TIMEZONE)) + Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); + return true; + } + else + { + // Error loading JSON data + Serial.println("SPIFS: Failed to load json config"); + } + } + } + } + return false; +} + +bool nvMemory::deleteConfig() +{ + Serial.println("SPIFS: Erasing config file.."); + return SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero +} + +bool nvMemory::init() +{ + if (!Initialized_) + { + Serial.println("SPIFS: Mounting File System..."); + // May need to make it begin(true) first time you are using SPIFFS + Initialized_ = SPIFFS.begin(false) || SPIFFS.begin(true); + Initialized_ ? Serial.println("SPIFS: Mounted") : Serial.println("SPIFS: Mounting failed."); + } + else + { + Serial.println("SPIFS: Already Mounted"); + } + return Initialized_; +}; + + +#else +#error We need some kind of permanent storage here! + +nvMemory::nvMemory() {} + +nvMemory::~nvMemory() {} + +bool nvMemory::saveConfig(TSettings* Settings) { return false; } + +bool nvMemory::loadConfig(TSettings* Settings) { return false; } + +bool nvMemory::deleteConfig() { return false; } + +bool nvMemory::init() { return false; } + + +#endif //BUILD_SPIFFS + +#endif // _NVMEMORY_H_ diff --git a/src/wManager.cpp b/src/wManager.cpp index a1c526f..bb8ccde 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -9,7 +9,7 @@ #include "monitor.h" #include "drivers/display.h" #include "drivers/storage/SDCard.h" -#include "drivers/storage/SPIStorage.h" +#include "drivers/storage/nvMemory.h" #include "drivers/storage/storage.h" @@ -24,7 +24,7 @@ TSettings Settings; WiFiManager wm; extern monitor_data mMonitor; -SPIStorage SPIFS; +nvMemory nvMem; void saveConfigCallback() // Callback notifying us of the need to save configuration @@ -49,7 +49,7 @@ void configModeCallback(WiFiManager* myWiFiManager) void reset_configurations() { Serial.println("Erasing Config, restarting"); - SPIFS.deleteConfigFile(); + nvMem.deleteConfig(); wm.resetSettings(); ESP.restart(); } @@ -84,14 +84,14 @@ void init_WifiManager() // Explicitly set WiFi mode WiFi.mode(WIFI_STA); - if (!SPIFS.loadConfigFile(&Settings)) + if (!nvMem.loadConfig(&Settings)) { //No config file on internal flash. - SDCard sdc; - if (!sdc.loadConfigFile(&Settings)) + SDCard SDCrd; + if (!SDCrd.loadConfigFile(&Settings)) { //No config file on SD card. - sdc.SD2SPIStorage(&SPIFS); // reboot on success. + SDCrd.SD2nvMemory(&nvMem); // reboot on success. } else @@ -166,7 +166,7 @@ void init_WifiManager() strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); Settings.Timezone = atoi(time_text_box_num.getValue()); - SPIFS.saveConfigFile(&Settings); + nvMem.saveConfig(&Settings); delay(3000); //reset and try again, or maybe put it to deep sleep ESP.restart(); @@ -225,7 +225,7 @@ void init_WifiManager() // Save the custom parameters to FS if (shouldSaveConfig) { - SPIFS.saveConfigFile(&Settings); + nvMem.saveConfig(&Settings); } } From 83938f72101ed56c5c4feeb32017e8b84ccbfe18 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 00:32:25 +0200 Subject: [PATCH 21/36] fix --- src/drivers/storage/SDCard.h | 4 ++-- src/wManager.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 8734178..bf7f2b7 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -37,7 +37,7 @@ SDCard::~SDCard() SD_MMC.end(); } -void SDCard::SD2nvMemory(NVMem* nvMem) +void SDCard::SD2nvMemory(nvMemory* nvMem) { TSettings Settings; if (loadConfigFile(&Settings)) @@ -143,7 +143,7 @@ bool SDCard::initSDcard() SDCard::SDCard() {} SDCard::~SDCard() {} -void SDCard::SD2nvMemory(nvMemory* nvMem) {}; +void SDCard::SD2NVMemory(NVMemory* nvMem) {}; bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } diff --git a/src/wManager.cpp b/src/wManager.cpp index bb8ccde..dab719e 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -91,8 +91,7 @@ void init_WifiManager() if (!SDCrd.loadConfigFile(&Settings)) { //No config file on SD card. - SDCrd.SD2nvMemory(&nvMem); // reboot on success. - + SDCrd.SD2nvMemory(&nvMem); // reboot on success. } else { From 309f20940e131053e707855e2a4a5d945872cac0 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:01:32 +0200 Subject: [PATCH 22/36] fix --- platformio.ini | 1 + src/drivers/storage/SDCard.h | 3 ++- src/drivers/storage/nvMemory.h | 16 ++++++---------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7251771..07a6db8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -140,6 +140,7 @@ build_flags = -D ESP32_CAM -D MONITOR_SPEED=${this.monitor_speed} lib_deps = + ;https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 https://github.com/tzapu/WiFiManager.git mathertel/OneButton @ ^2.0.3 diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index bf7f2b7..e5cf7e9 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -5,6 +5,7 @@ #include "storage.h" #include "nvMemory.h" +// Handles the transfer of settings from sd card to nv memory (wifi credentials are handled by wifimanager) class SDCard { public: @@ -143,7 +144,7 @@ bool SDCard::initSDcard() SDCard::SDCard() {} SDCard::~SDCard() {} -void SDCard::SD2NVMemory(NVMemory* nvMem) {}; +void SDCard::SD2nvMemory(nvMemory* nvMem) {}; bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h index 448e1fb..777e46a 100644 --- a/src/drivers/storage/nvMemory.h +++ b/src/drivers/storage/nvMemory.h @@ -1,11 +1,13 @@ #ifndef _NVMEMORY_H_ #define _NVMEMORY_H_ -#define BUILD_SPIFFS +// we only have one implementation right now and nothing to choose from. +#define NVMEM_SPIFFS #include "..\drivers.h" #include "storage.h" +// Handles load and store of user settings, except wifi credentials. Those are managed by the wifimanager. class nvMemory { public: @@ -19,14 +21,13 @@ private: bool Initialized_; }; -#ifdef BUILD_SPIFFS +#ifdef NVMEM_SPIFFS #define ESP_DRD_USE_SPIFFS true #include #include #include -#include nvMemory::nvMemory() { @@ -147,21 +148,16 @@ bool nvMemory::init() #else -#error We need some kind of permanent storage here! +#error We need some kind of permanent storage implemented here! nvMemory::nvMemory() {} - nvMemory::~nvMemory() {} - bool nvMemory::saveConfig(TSettings* Settings) { return false; } - bool nvMemory::loadConfig(TSettings* Settings) { return false; } - bool nvMemory::deleteConfig() { return false; } - bool nvMemory::init() { return false; } -#endif //BUILD_SPIFFS +#endif //NVMEM_TYPE #endif // _NVMEMORY_H_ From bc43d83b5e124fab69981235cff4fe1cb9603f21 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:41:15 +0200 Subject: [PATCH 23/36] update Readme: SD card, ESP32CAM --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 232fe0c..f17d9f6 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,11 @@ Every time an stratum job notification is received miner update its current work - 3D BOX [here](3d_files/) #### Current Supported Boards -- TTGO T-Display S3 ([Aliexpress link](https://s.click.aliexpress.com/e/_Ddy7739)) -- ESP32-WROOM-32, ESP32-Devkit1.. ([Aliexpress link](https://s.click.aliexpress.com/e/_DCzlUiX)) +- TTGO T-Display S3 ([Aliexpress link](https://s.click.aliexpress.com/e/_Ddy7739)*) +- ESP32-WROOM-32, ESP32-Devkit1.. ([Aliexpress link](https://s.click.aliexpress.com/e/_DCzlUiX)*) +- ESP32-cam (https://lastminuteengineers.com/getting-started-with-esp32-cam/) +*affiliate links ### Flash firmware #### microMiners Flashtool [Recommended] Easyiest way to flash firmware. Build your own miner using the folowing firwmare flash tool: @@ -76,6 +78,24 @@ After programming, you will only need to setup your Wifi and BTC address. 1. Setup your Wifi Network 1. Add your BTCaddress +OR + +1. Your board and firmware are SD card enabled. +1. Format a SD card using Fat32. +1. Create a file named "config.json" in your card's root with the following structure. Adjust the settings to your needs: +{ + "SSID": "myWifiSSID", + "PW": "myWifiPassword", + "PoolUrl": "public-pool.io", + "PoolPort": 21496, + "BtcWallet": "walletID", + "Timezone": 2 +} +1. Insert the SD card. +1. Hold down the "reset configurations" button as described below or power up without settings in your nvmemory. +1. Power down to remove the SD card. It is not needed for mining. + + Recommended low difficulty share pools: | Pool URL | Port | Web URL | Status | From d93d11d27f5ce279b1e65dda8ef9c6fd4d7fa06b Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:47:36 +0200 Subject: [PATCH 24/36] update reame affiliate links --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f17d9f6..d02d7e5 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,10 @@ Every time an stratum job notification is received miner update its current work - 3D BOX [here](3d_files/) #### Current Supported Boards -- TTGO T-Display S3 ([Aliexpress link](https://s.click.aliexpress.com/e/_Ddy7739)*) -- ESP32-WROOM-32, ESP32-Devkit1.. ([Aliexpress link](https://s.click.aliexpress.com/e/_DCzlUiX)*) -- ESP32-cam (https://lastminuteengineers.com/getting-started-with-esp32-cam/) +- TTGO T-Display S3 ([Aliexpress link*](https://s.click.aliexpress.com/e/_Ddy7739)) +- ESP32-WROOM-32, ESP32-Devkit1.. ([Aliexpress link*](https://s.click.aliexpress.com/e/_DCzlUiX)) +- ESP32-cam [Board Info](https://lastminuteengineers.com/getting-started-with-esp32-cam/) -*affiliate links ### Flash firmware #### microMiners Flashtool [Recommended] Easyiest way to flash firmware. Build your own miner using the folowing firwmare flash tool: @@ -162,5 +161,6 @@ With the USB-C port to the right: ### Donations/Project contributions If you would like to contribute and help dev team with this project you can send a donation to the following LN address ⚡teamnerdminer@getalby.com⚡ +Or order by using the affiliate links(*) above. Enjoy From dd9c9b340181fe752d5d34eeff075cbe66affd78 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:49:01 +0200 Subject: [PATCH 25/36] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d02d7e5..6666b60 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ With the USB-C port to the right: ### Donations/Project contributions If you would like to contribute and help dev team with this project you can send a donation to the following LN address ⚡teamnerdminer@getalby.com⚡ -Or order by using the affiliate links(*) above. + +Or by using the affiliate links(*) above. Enjoy From cd69d0354a05e5709b568e3bd633333086644822 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:50:43 +0200 Subject: [PATCH 26/36] upate --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 6666b60..0b91f7d 100644 --- a/README.md +++ b/README.md @@ -160,8 +160,6 @@ With the USB-C port to the right: - [ ] Add support to control BM1397 ### Donations/Project contributions -If you would like to contribute and help dev team with this project you can send a donation to the following LN address ⚡teamnerdminer@getalby.com⚡ - -Or by using the affiliate links(*) above. +If you would like to contribute and help dev team with this project you can send a donation to the following LN address ⚡teamnerdminer@getalby.com⚡ or use the affiliate links(*) above. Enjoy From 457cef392861633c634997afcb5efa85cb2919a0 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:55:27 +0200 Subject: [PATCH 27/36] update readme --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0b91f7d..7473876 100644 --- a/README.md +++ b/README.md @@ -71,29 +71,31 @@ Update NerdMiner firmware following same flashing steps but only adding 0x10000_ ### NerdMiner configuration After programming, you will only need to setup your Wifi and BTC address. +#### Wifi Accesspoint + 1. Connect to NerdMinerAP - AP: NerdMinerAP - PASS: MineYourCoins 1. Setup your Wifi Network 1. Add your BTCaddress -OR +#### SD card (if available) -1. Your board and firmware are SD card enabled. 1. Format a SD card using Fat32. 1. Create a file named "config.json" in your card's root with the following structure. Adjust the settings to your needs: -{ - "SSID": "myWifiSSID", - "PW": "myWifiPassword", - "PoolUrl": "public-pool.io", - "PoolPort": 21496, - "BtcWallet": "walletID", - "Timezone": 2 +{ + "SSID": "myWifiSSID", + "PW": "myWifiPassword", + "PoolUrl": "public-pool.io", + "PoolPort": 21496, + "BtcWallet": "walletID", + "Timezone": 2 } 1. Insert the SD card. 1. Hold down the "reset configurations" button as described below or power up without settings in your nvmemory. 1. Power down to remove the SD card. It is not needed for mining. +#### Pool selection Recommended low difficulty share pools: From a856b8512d3218bc956f6bdc62695596662bde55 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:58:29 +0200 Subject: [PATCH 28/36] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7473876..e8a2769 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ After programming, you will only need to setup your Wifi and BTC address. #### SD card (if available) 1. Format a SD card using Fat32. -1. Create a file named "config.json" in your card's root with the following structure. Adjust the settings to your needs: +1. Create a file named "config.json" in your card's root containing the the following structure. Adjust the settings to your needs: { "SSID": "myWifiSSID", "PW": "myWifiPassword", From 9d7aa2eef2a9942526a600500fdb66d15ea91df1 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 07:29:58 +0200 Subject: [PATCH 29/36] fix compiler warnings. --- lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h index 197ebc5..f8f4dbd 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h @@ -366,7 +366,7 @@ SPI3_HOST = 2 #define PARALLEL_INIT_TFT_DATA_BUS \ for (int32_t c = 0; c<256; c++) \ { \ - xset_mask[c] = 0; \ + xset_mask[c] = 0; \ if ( c & 0x01 ) xset_mask[c] |= (1 << (TFT_D0-MASK_OFFSET)); \ if ( c & 0x02 ) xset_mask[c] |= (1 << (TFT_D1-MASK_OFFSET)); \ if ( c & 0x04 ) xset_mask[c] |= (1 << (TFT_D2-MASK_OFFSET)); \ @@ -374,7 +374,7 @@ SPI3_HOST = 2 if ( c & 0x10 ) xset_mask[c] |= (1 << (TFT_D4-MASK_OFFSET)); \ if ( c & 0x20 ) xset_mask[c] |= (1 << (TFT_D5-MASK_OFFSET)); \ if ( c & 0x40 ) xset_mask[c] |= (1 << (TFT_D6-MASK_OFFSET)); \ - if ( c & 0x80 ) xset_mask[c] |= (1 << (TFT_D7-MASK_OFFSET)); \ + if ( c & 0x80 ) xset_mask[c] |= (1 << (TFT_D7-MASK_OFFSET)); \ } \ // Mask for the 8 data bits to set pin directions From bcd8b2f60dc700d4f22d829057af349922dd3262 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 07:36:46 +0200 Subject: [PATCH 30/36] seperate display drivers --- platformio.ini | 1 + src/NerdMinerV2.ino.cpp | 6 ++--- src/drivers/devices/device.h | 20 +++++++++++++++ src/drivers/displays/amoledDisplayDriver.cpp | 2 +- src/drivers/{ => displays}/display.cpp | 0 src/drivers/{ => displays}/display.h | 2 +- .../{drivers.h => displays/displayDriver.h} | 22 +++------------- src/drivers/displays/dongleDisplayDriver.cpp | 8 +++--- src/drivers/displays/noDisplayDriver.cpp | 2 +- src/drivers/displays/tDisplayDriver.cpp | 2 +- src/drivers/storage/SDCard.h | 2 +- src/drivers/storage/nvMemory.h | 2 +- src/drivers/storage/storage.h | 25 +------------------ src/mining.cpp | 2 +- src/wManager.cpp | 6 ++--- src/wManager.h | 2 +- 16 files changed, 44 insertions(+), 60 deletions(-) create mode 100644 src/drivers/devices/device.h rename src/drivers/{ => displays}/display.cpp (100%) rename src/drivers/{ => displays}/display.h (94%) rename src/drivers/{drivers.h => displays/displayDriver.h} (76%) diff --git a/platformio.ini b/platformio.ini index 07a6db8..f5b5984 100644 --- a/platformio.ini +++ b/platformio.ini @@ -145,5 +145,6 @@ lib_deps = https://github.com/tzapu/WiFiManager.git mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient + ;https://github.com/jbtronics/ESP32Console.git#v1.2.1 lib_ignore = TFT_eSPI diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 5c0e4a7..9ee202e 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -10,7 +10,7 @@ #include "wManager.h" #include "mining.h" #include "monitor.h" -#include "drivers/display.h" +#include "drivers/displays/display.h" //3 seconds WDT #define WDT_TIMEOUT 3 @@ -57,7 +57,7 @@ void setup() button1.setPressTicks(5000); button1.attachClick(switchToNextScreen); button1.attachDoubleClick(alternateScreenRotation); - button1.attachLongPressStart(reset_configurations); + button1.attachLongPressStart(reset_configuration); #endif #if defined(PIN_BUTTON_1) && defined(PIN_BUTTON_2) //Button 1 of two button device @@ -69,7 +69,7 @@ void setup() #if defined(PIN_BUTTON_2) //Button 2 of two button device button2.setPressTicks(5000); button2.attachClick(switchToNextScreen); - button2.attachLongPressStart(reset_configurations); + button2.attachLongPressStart(reset_configuration); #endif /******** INIT NERDMINER ************/ diff --git a/src/drivers/devices/device.h b/src/drivers/devices/device.h new file mode 100644 index 0000000..1e46037 --- /dev/null +++ b/src/drivers/devices/device.h @@ -0,0 +1,20 @@ +#ifndef __DEVICE_H__ +#define __DEVICE_H__ + +#if defined(NERDMINERV2) +#include "nerdMinerV2.h" +#elif defined(DEVKITV1) +#include "esp32DevKit.h" +#elif defined(TDISPLAY) +#include "lilygoS3TDisplay.h" +#elif defined(NERMINER_S3_AMOLED) +#include "lilygoS3Amoled.h" +#elif defined(NERMINER_S3_DONGLE) +#include "lilygoS3Dongle.h" +#elif defined(ESP32_CAM) +#include "esp32CAM.h" +#else +#error "No device defined" +#endif + +#endif // __DEVICE_H__ \ No newline at end of file diff --git a/src/drivers/displays/amoledDisplayDriver.cpp b/src/drivers/displays/amoledDisplayDriver.cpp index c0eae8b..4abc576 100644 --- a/src/drivers/displays/amoledDisplayDriver.cpp +++ b/src/drivers/displays/amoledDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef AMOLED_DISPLAY diff --git a/src/drivers/display.cpp b/src/drivers/displays/display.cpp similarity index 100% rename from src/drivers/display.cpp rename to src/drivers/displays/display.cpp diff --git a/src/drivers/display.h b/src/drivers/displays/display.h similarity index 94% rename from src/drivers/display.h rename to src/drivers/displays/display.h index 331ea95..2a4a469 100644 --- a/src/drivers/display.h +++ b/src/drivers/displays/display.h @@ -1,7 +1,7 @@ #ifndef DISPLAY_H #define DISPLAY_H -#include "drivers.h" +#include "DisplayDriver.h" extern DisplayDriver *currentDisplayDriver; diff --git a/src/drivers/drivers.h b/src/drivers/displays/displayDriver.h similarity index 76% rename from src/drivers/drivers.h rename to src/drivers/displays/displayDriver.h index b2c1e46..98ef3f1 100644 --- a/src/drivers/drivers.h +++ b/src/drivers/displays/displayDriver.h @@ -1,21 +1,7 @@ -#ifndef DRIVERS_H -#define DRIVERS_H +#ifndef DISPLAYDRIVER_H_ +#define DISPLAYDRIVER_H_ -#if defined(NERDMINERV2) -#include "devices/nerdMinerV2.h" -#elif defined(DEVKITV1) -#include "devices/esp32DevKit.h" -#elif defined(TDISPLAY) -#include "devices/lilygoS3TDisplay.h" -#elif defined(NERMINER_S3_AMOLED) -#include "devices/lilygoS3Amoled.h" -#elif defined(NERMINER_S3_DONGLE) -#include "devices/lilygoS3Dongle.h" -#elif defined(ESP32_CAM) -#include "devices/esp32CAM.h" -#else -#error "No device defined" -#endif +#include "..\devices\device.h" typedef void (*AlternateFunction)(void); typedef void (*DriverInitFunction)(void); @@ -49,4 +35,4 @@ extern DisplayDriver dongleDisplayDriver; #define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#endif // DRIVERS_H +#endif // DISPLAYDRIVER_H_ diff --git a/src/drivers/displays/dongleDisplayDriver.cpp b/src/drivers/displays/dongleDisplayDriver.cpp index 2ba6356..f6b4fe0 100644 --- a/src/drivers/displays/dongleDisplayDriver.cpp +++ b/src/drivers/displays/dongleDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef DONGLE_DISPLAY @@ -45,15 +45,15 @@ extern monitor_data mMonitor; int32_t x = 8, y = 8; \ background.setTextSize(1); \ background.setTextFont(FONT2); \ - \ + \ background.setTextColor(KEY_COLOR); \ - \ + \ render.setFontSize(18); #define CLEAR_SCREEN() \ RESET_SCREEN(); \ background.fillRect(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT, BACK_COLOR); \ - \ + \ #define PRINT_STR(str) \ diff --git a/src/drivers/displays/noDisplayDriver.cpp b/src/drivers/displays/noDisplayDriver.cpp index 23a74bd..636cf81 100644 --- a/src/drivers/displays/noDisplayDriver.cpp +++ b/src/drivers/displays/noDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef NO_DISPLAY diff --git a/src/drivers/displays/tDisplayDriver.cpp b/src/drivers/displays/tDisplayDriver.cpp index 6eb454b..76eede4 100644 --- a/src/drivers/displays/tDisplayDriver.cpp +++ b/src/drivers/displays/tDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "../drivers.h" +#include "DisplayDriver.h" #ifdef T_DISPLAY diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index e5cf7e9..36214c0 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -1,7 +1,7 @@ #ifndef _SDCARD_H_ #define _SDCARD_H_ -#include "..\drivers.h" +#include "..\devices\device.h" #include "storage.h" #include "nvMemory.h" diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h index 777e46a..5cd03ea 100644 --- a/src/drivers/storage/nvMemory.h +++ b/src/drivers/storage/nvMemory.h @@ -4,7 +4,7 @@ // we only have one implementation right now and nothing to choose from. #define NVMEM_SPIFFS -#include "..\drivers.h" +#include "..\devices\device.h" #include "storage.h" // Handles load and store of user settings, except wifi credentials. Those are managed by the wifimanager. diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index bddb103..6425b5f 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -17,37 +17,14 @@ #define JSON_KEY_POOLPORT "PoolPort" #define JSON_KEY_TIMEZONE "Timezone" -class TSettings +struct TSettings { -public: char WifiSSID[80]{ DEFAULT_SSID }; char WifiPW[80]{ DEFAULT_WIFIPW }; char PoolAddress[80]{ DEFAULT_POOLURL }; char BtcWallet[80]{ DEFAULT_WALLETID }; uint32_t PoolPort{ DEFAULT_POOLPORT }; uint32_t Timezone{ DEFAULT_TIMEZONE }; - - void print() - { - Serial.print("WifiSSID:>"); - Serial.print(WifiSSID); - Serial.print("<, "); - Serial.print("WifiPW:>"); - Serial.print(WifiPW); - Serial.print("<, "); - Serial.print("PoolAddress:>"); - Serial.print(PoolAddress); - Serial.print("<, "); - Serial.print("BtcWallet:>"); - Serial.print(BtcWallet); - Serial.print("<, "); - Serial.print("PoolPort:>"); - Serial.print(PoolPort); - Serial.print("<, "); - Serial.print("Timezone:>"); - Serial.print(Timezone); - Serial.println("<"); - } }; #endif // _STORAGE_H_ \ No newline at end of file diff --git a/src/mining.cpp b/src/mining.cpp index 0395b57..8c67adc 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -8,7 +8,7 @@ #include "mining.h" #include "utils.h" #include "monitor.h" -#include "drivers/display.h" +#include "drivers/displays/display.h" #include "drivers/storage/storage.h" unsigned long templates = 0; diff --git a/src/wManager.cpp b/src/wManager.cpp index dab719e..1a3ef66 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -7,7 +7,7 @@ #include "wManager.h" #include "monitor.h" -#include "drivers/display.h" +#include "drivers/displays/display.h" #include "drivers/storage/SDCard.h" #include "drivers/storage/nvMemory.h" #include "drivers/storage/storage.h" @@ -46,7 +46,7 @@ void configModeCallback(WiFiManager* myWiFiManager) Serial.println(WiFi.softAPIP()); } -void reset_configurations() +void reset_configuration() { Serial.println("Erasing Config, restarting"); nvMem.deleteConfig(); @@ -76,7 +76,7 @@ void init_WifiManager() // Check if button2 is pressed to enter configMode with actual configuration if (!digitalRead(PIN_BUTTON_2)) { Serial.println(F("Button pressed to force start config mode")); - reset_configurations(); + reset_configuration(); forceConfig = true; wm.setBreakAfterConfig(true); //Set to detect config edition and save } diff --git a/src/wManager.h b/src/wManager.h index 7c8dc64..ef2bd37 100644 --- a/src/wManager.h +++ b/src/wManager.h @@ -3,6 +3,6 @@ void init_WifiManager(); void wifiManagerProcess(); -void reset_configurations(); +void reset_configuration(); #endif // _WMANAGER_H From 7ba6c9dc746aa49affee28939cae1d7252d8c9bb Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:40:43 +0200 Subject: [PATCH 31/36] update readme add tripple click option --- README.md | 15 +++++++++++++-- src/NerdMinerV2.ino.cpp | 1 + src/wManager.cpp | 1 - 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8a2769..47928d6 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ Every time an stratum job notification is received miner update its current work - ESP32-WROOM-32, ESP32-Devkit1.. ([Aliexpress link*](https://s.click.aliexpress.com/e/_DCzlUiX)) - ESP32-cam [Board Info](https://lastminuteengineers.com/getting-started-with-esp32-cam/) +* affiliate link + ### Flash firmware #### microMiners Flashtool [Recommended] Easyiest way to flash firmware. Build your own miner using the folowing firwmare flash tool: @@ -92,7 +94,7 @@ After programming, you will only need to setup your Wifi and BTC address. "Timezone": 2 } 1. Insert the SD card. -1. Hold down the "reset configurations" button as described below or power up without settings in your nvmemory. +1. Hold down the "reset configurations" button as described below to reset the configurations and/or boot without settings in your nvmemory. 1. Power down to remove the SD card. It is not needed for mining. #### Pool selection @@ -115,6 +117,15 @@ Other standard pools not compatible with low difficulty share: | eu.stratum.slushpool.com | 3333 | https://braiins.com/pool | ### Buttons + +#### One button devices: + +- One click > change screen. +- Double click > change screen orientation. +- Tripple click > turn the screen off and on again. +- Hold 5 seconds > **reset the configurations and reboot** your NerdMiner. + +#### Two button devices: With the USB-C port to the right: **TOP BUTTON** @@ -162,6 +173,6 @@ With the USB-C port to the right: - [ ] Add support to control BM1397 ### Donations/Project contributions -If you would like to contribute and help dev team with this project you can send a donation to the following LN address ⚡teamnerdminer@getalby.com⚡ or use the affiliate links(*) above. +If you would like to contribute and help dev team with this project you can send a donation to the following LN address ⚡teamnerdminer@getalby.com⚡ Enjoy diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 9ee202e..8144dcf 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -58,6 +58,7 @@ void setup() button1.attachClick(switchToNextScreen); button1.attachDoubleClick(alternateScreenRotation); button1.attachLongPressStart(reset_configuration); + if(button1.getNumberClicks() == 3) alternateScreenState(); #endif #if defined(PIN_BUTTON_1) && defined(PIN_BUTTON_2) //Button 1 of two button device diff --git a/src/wManager.cpp b/src/wManager.cpp index 1a3ef66..f9b6a1d 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -76,7 +76,6 @@ void init_WifiManager() // Check if button2 is pressed to enter configMode with actual configuration if (!digitalRead(PIN_BUTTON_2)) { Serial.println(F("Button pressed to force start config mode")); - reset_configuration(); forceConfig = true; wm.setBreakAfterConfig(true); //Set to detect config edition and save } From 1beeea2a25ceba13bd404cadea82a11ab3afc4e4 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:47:45 +0200 Subject: [PATCH 32/36] update --- src/drivers/storage/nvMemory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h index 5cd03ea..71c5d80 100644 --- a/src/drivers/storage/nvMemory.h +++ b/src/drivers/storage/nvMemory.h @@ -148,7 +148,7 @@ bool nvMemory::init() #else -#error We need some kind of permanent storage implemented here! +#error We need some kind of permanent storage implementation! nvMemory::nvMemory() {} nvMemory::~nvMemory() {} From 59fbade3471f39ad9868a23ab4e6ee2b0f0f9165 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:42:41 +0200 Subject: [PATCH 33/36] update debug messages, prepare implementation of SPI mode --- src/drivers/storage/SDCard.h | 115 ++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 41 deletions(-) diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 36214c0..7e02ba2 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -1,6 +1,19 @@ #ifndef _SDCARD_H_ #define _SDCARD_H_ +#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) +#define BUILD_SDMMC_4 +#include +#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) +#define BUILD_SDMMC_1 +#include +#else +#warning SD card support disabled! +#endif + +#include +#include + #include "..\devices\device.h" #include "storage.h" #include "nvMemory.h" @@ -15,27 +28,31 @@ public: bool loadConfigFile(TSettings* Settings); private: bool initSDcard(); + void unmount(); - bool cardInitialized_; +#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) + fs::SDMMCFS* iSD_; +#elif defined (BUILD_SDSPI) + fs::SDFS* iSD_; +#error You chose to run the sd card in SPI mode. This is not implemented yet. +#endif }; -#ifdef BUILD_SDMMC - -#include -#include - -#include +#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) || defined (BUILD_SDSPI) SDCard::SDCard() { - cardInitialized_ = false; +#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) + iSD_ = &SD_MMC; +#elif defined (BUILD_SDSPI) +#error You chose to run the sd card in SPI mode. This is not implemented yet. +#endif } SDCard::~SDCard() { - if (cardInitialized_) - SD_MMC.end(); + unmount(); } void SDCard::SD2nvMemory(nvMemory* nvMem) @@ -54,26 +71,24 @@ bool SDCard::loadConfigFile(TSettings* Settings) { // Load existing configuration file // Read configuration from FS json - Serial.println("SDCard: Mounting File System..."); if (initSDcard()) { - if (SD_MMC.exists(JSON_CONFIG_FILE)) + if (iSD_->exists(JSON_CONFIG_FILE)) { // The file exists, reading and loading - Serial.println("SDCard: Reading config file"); - File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r"); + File configFile = iSD_->open(JSON_CONFIG_FILE, "r"); if (configFile) { - Serial.println("SDCard: Opened configuration file"); StaticJsonDocument<512> json; DeserializationError error = deserializeJson(json, configFile); configFile.close(); + Serial.println("SDCard: Loading config file"); serializeJsonPretty(json, Serial); Serial.print('\n'); + unmount(); if (!error) { - Serial.println("SDCard: Parsing JSON"); strcpy(Settings->WifiSSID, json[JSON_KEY_SSID] | Settings->WifiSSID); strcpy(Settings->WifiPW, json[JSON_KEY_PASW] | Settings->WifiPW); strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); @@ -82,62 +97,79 @@ bool SDCard::loadConfigFile(TSettings* Settings) Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); if (json.containsKey(JSON_KEY_TIMEZONE)) Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); - SD_MMC.end(); return true; } else { // Error loading JSON data - Serial.println("SDCard: Failed to load json config"); + Serial.println("SDCard: Error parsing config file!"); } } + else + { + Serial.println("SDCard: Error opening config file!"); + } } else { - Serial.println("SDCard: No config file available!"); + Serial.println("SDCard: No config file available!"); } - SD_MMC.end(); + unmount(); } return false; } +void SDCard::unmount() +{ + iSD_->end(); + Serial.println("SDCard: Unmounted"); +} + bool SDCard::initSDcard() { - if((cardInitialized_)&&(SD_MMC.cardType() != CARD_NONE)) + if(iSD_->cardType() != CARD_NONE) { - Serial.println("SDCard: Already mounted."); - return cardInitialized_; + Serial.println("SDCard: Already mounted."); + return true; } - - bool oneBitMode = true; -#if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) - if (SD_MMC.cardType() == CARD_NONE) + Serial.println("SDCard: Mounting card."); + + bool cardInitialized = false; +#if defined (BUILD_SDMMC_4) + if (iSD_->cardType() == CARD_NONE) { - SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); - oneBitMode = false; + iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); Serial.println("SDCard: 4-Bit Mode."); + cardInitialized = iSD_->begin("/sd", false); } -#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) - if (SD_MMC.cardType() == CARD_NONE) +#elif defined (BUILD_SDMMC_1) +#warning SDMMC: 1-bit mode is not always working. If you experience issues, try other modes. + if (iSD_->cardType() == CARD_NONE) { - SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); + iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); Serial.println("SDCard: 1-Bit Mode."); + cardInitialized = iSD_->begin("/sd", true); } +#elif defined (BUILD_SDSPI) +#error You chose to run the sd card in SPI mode. This is not implemented yet. #else Serial.println("SDCard: interface not available."); return false; #endif // dataPinsDefined - cardInitialized_ = SD_MMC.begin("/sdcard", oneBitMode); - if ((cardInitialized_) && (SD_MMC.cardType() != CARD_NONE)) + if (cardInitialized) { - Serial.println("SDCard: Card mounted."); - return true; - } - else - { - Serial.println("SDCard: No card found."); - return false; + if(iSD_->cardType() != CARD_NONE) + { + Serial.println("SDCard: Mounted."); + return true; + } + else + { + Serial.println("SDCard: Mounting failed."); + iSD_->end(); + } } + return false; } #else @@ -147,6 +179,7 @@ SDCard::~SDCard() {} void SDCard::SD2nvMemory(nvMemory* nvMem) {}; bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } +void unmount() {} #endif //BUILD_SDMMC From a694427b7c3ab2421de232de1e0aec9662ba7d35 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:43:13 +0200 Subject: [PATCH 34/36] update debug messages, comments --- src/drivers/devices/esp32CAM.h | 6 +++--- src/drivers/storage/nvMemory.h | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/drivers/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h index 7911db7..54d7460 100644 --- a/src/drivers/devices/esp32CAM.h +++ b/src/drivers/devices/esp32CAM.h @@ -6,13 +6,13 @@ #define NO_DISPLAY -#define BUILD_SDMMC - +// SDMMC interface: 1-bit mode (might cause issues): #define SDMMC_CLK 14 #define SDMMC_CMD 15 #define SDMMC_D0 2 +// additional defines to enable 4-bit mode #define SDMMC_D1 4 #define SDMMC_D2 12 #define SDMMC_D3 13 -#endif // _ESP32_CAM_H_ \ No newline at end of file +#endif // _ESP32_CAM_H_ diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h index 71c5d80..d53713c 100644 --- a/src/drivers/storage/nvMemory.h +++ b/src/drivers/storage/nvMemory.h @@ -45,7 +45,7 @@ bool nvMemory::saveConfig(TSettings* Settings) if (init()) { // Save Config in JSON format - Serial.println(F("SPIFS: Saving configuration...")); + Serial.println(F("SPIFS: Saving configuration.")); // Create a JSON document StaticJsonDocument<512> json; @@ -59,7 +59,7 @@ bool nvMemory::saveConfig(TSettings* Settings) if (!configFile) { // Error, file did not open - Serial.println("SPIFS: failed to open config file for writing"); + Serial.println("SPIFS: Failed to open config file for writing"); return false; } @@ -92,11 +92,10 @@ bool nvMemory::loadConfig(TSettings* Settings) if (SPIFFS.exists(JSON_CONFIG_FILE)) { // The file exists, reading and loading - Serial.println("SPIFS: Reading config file"); File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); if (configFile) { - Serial.println("SPIFS: Opened configuration file"); + Serial.println("SPIFS: Loading config file"); StaticJsonDocument<512> json; DeserializationError error = deserializeJson(json, configFile); configFile.close(); @@ -104,7 +103,6 @@ bool nvMemory::loadConfig(TSettings* Settings) Serial.print('\n'); if (!error) { - Serial.println("SPIFS: Parsing JSON"); strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); if (json.containsKey(JSON_KEY_POOLPORT)) @@ -116,9 +114,17 @@ bool nvMemory::loadConfig(TSettings* Settings) else { // Error loading JSON data - Serial.println("SPIFS: Failed to load json config"); + Serial.println("SPIFS: Error parsing config file!"); } } + else + { + Serial.println("SPIFS: Error opening config file!"); + } + } + else + { + Serial.println("SPIFS: No config file available!"); } } return false; From cc1832641b26fb423502cb4d6583bac80bacf25a Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:43:16 +0200 Subject: [PATCH 35/36] fix --- src/wManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wManager.cpp b/src/wManager.cpp index f9b6a1d..081b79c 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -87,14 +87,14 @@ void init_WifiManager() { //No config file on internal flash. SDCard SDCrd; - if (!SDCrd.loadConfigFile(&Settings)) + if (SDCrd.loadConfigFile(&Settings)) { - //No config file on SD card. + //Config file on SD card. SDCrd.SD2nvMemory(&nvMem); // reboot on success. } else { - //Config file on SD card. Copy and restart. + //No config file on SD card. Starting wifi config server. forceConfig = true; } }; From 6690f3cccbf6bb4133c6e10037e4f7b5ffa720ec Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Sat, 16 Sep 2023 01:42:40 +0200 Subject: [PATCH 36/36] update --- src/drivers/storage/SDCard.h | 2 +- src/drivers/storage/nvMemory.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 7e02ba2..1bcdf65 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -33,8 +33,8 @@ private: #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) fs::SDMMCFS* iSD_; #elif defined (BUILD_SDSPI) +#error You chose to run the SD card in SPI mode. This is not implemented yet. fs::SDFS* iSD_; -#error You chose to run the sd card in SPI mode. This is not implemented yet. #endif }; diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h index d53713c..8d1e117 100644 --- a/src/drivers/storage/nvMemory.h +++ b/src/drivers/storage/nvMemory.h @@ -152,7 +152,6 @@ bool nvMemory::init() return Initialized_; }; - #else #error We need some kind of permanent storage implementation!