From 56fc227c7c8b4afe47abff60b570de466c59c727 Mon Sep 17 00:00:00 2001 From: George Alexandre Silva Date: Tue, 19 Sep 2023 20:38:15 -0300 Subject: [PATCH] Revert "Merge branch 'dev' of https://github.com/BitMaker-hub/NerdMiner_v2 into dev" This reverts commit 16ffd47a671ebe0267bcf8960567832bfeda5b02, reversing changes made to 43cbaf75cb992260a620a6d67c6a5885eaf85c5c. --- .gitignore | 3 - README.md | 31 -- lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h | 2 +- platformio.ini | 40 +- src/NerdMinerV2.ino.cpp | 14 +- src/drivers/devices/device.h | 27 -- src/drivers/devices/esp32CAM.h | 18 - src/drivers/{displays => }/display.cpp | 0 src/drivers/{displays => }/display.h | 2 +- src/drivers/displays/amoledDisplayDriver.cpp | 2 +- src/drivers/displays/dongleDisplayDriver.cpp | 8 +- src/drivers/displays/esp23_2432s028r.cpp | 2 +- src/drivers/displays/noDisplayDriver.cpp | 2 +- src/drivers/displays/tDisplayDriver.cpp | 2 +- src/drivers/displays/tDisplayV1Driver.cpp | 2 +- src/drivers/displays/t_qtDisplayDriver.cpp | 2 +- .../{displays/displayDriver.h => drivers.h} | 27 +- src/drivers/storage/SDCard.cpp | 157 ------- src/drivers/storage/SDCard.h | 38 -- src/drivers/storage/nvMemory.cpp | 148 ------ src/drivers/storage/nvMemory.h | 30 -- src/drivers/storage/storage.h | 35 -- src/mining.cpp | 28 +- src/monitor.cpp | 10 +- src/wManager.cpp | 431 +++++++++++------- src/wManager.h | 7 +- 26 files changed, 329 insertions(+), 739 deletions(-) delete mode 100644 src/drivers/devices/device.h delete mode 100644 src/drivers/devices/esp32CAM.h rename src/drivers/{displays => }/display.cpp (100%) rename src/drivers/{displays => }/display.h (94%) rename src/drivers/{displays/displayDriver.h => drivers.h} (73%) delete mode 100644 src/drivers/storage/SDCard.cpp delete mode 100644 src/drivers/storage/SDCard.h delete mode 100644 src/drivers/storage/nvMemory.cpp delete mode 100644 src/drivers/storage/nvMemory.h delete mode 100644 src/drivers/storage/storage.h diff --git a/.gitignore b/.gitignore index f7eadc5..bebd06e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .pio .vscode -.vs -*.sln -*.vcxproj* NerdMinerLog.txt bin/0x10000_firmware.bin logs diff --git a/README.md b/README.md index dd37a9c..e38bde5 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ Every time an stratum job notification is received miner update its current work - LILYGO T-Display S3 AMOLED ([Aliexpress link](https://s.click.aliexpress.com/e/_DmOIK6j)) - LILYGO T-Dongle S3 ([Aliexpress link](https://s.click.aliexpress.com/e/_DmQCPyj)) - ESP32-2432S028R 2,8" ([Aliexpress link](https://s.click.aliexpress.com/e/_DdXkvLv)) -- ESP32-cam [Board Info](https://lastminuteengineers.com/getting-started-with-esp32-cam/) ### Flash firmware #### microMiners Flashtool [Recommended] @@ -76,33 +75,12 @@ 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 -#### SD card (if available) - -1. Format a SD card using Fat32. -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", - "PoolUrl": "public-pool.io", - "PoolPort": 21496, - "BtcWallet": "walletID", - "Timezone": 2, - "saveStats": false -} -1. Insert the SD card. -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 - Recommended low difficulty share pools: | Pool URL | Port | Web URL | Status | @@ -121,15 +99,6 @@ 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** diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h index f090f24..4438fe9 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h @@ -375,7 +375,7 @@ SPI3_HOST = 2 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)); \ - } \ + } \ // Mask for the 8 data bits to set pin directions #define GPIO_DIR_MASK ((1 << (TFT_D0-MASK_OFFSET)) | (1 << (TFT_D1-MASK_OFFSET)) | (1 << (TFT_D2-MASK_OFFSET)) | (1 << (TFT_D3-MASK_OFFSET)) | (1 << (TFT_D4-MASK_OFFSET)) | (1 << (TFT_D5-MASK_OFFSET)) | (1 << (TFT_D6-MASK_OFFSET)) | (1 << (TFT_D7-MASK_OFFSET))) diff --git a/platformio.ini b/platformio.ini index ef7a08f..b039650 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [platformio] globallib_dir = lib -default_envs = esp32cam, ESP32-2432S028R, NerminerV2, ESP32-devKitv1, NerminerV2-S3-DONGLE, NerminerV2-S3-AMOLED, NerminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R +default_envs = ESP32-2432S028R ;NerminerV2, ESP32-devKitv1, NerminerV2-S3-DONGLE, NerminerV2-S3-AMOLED, NerminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R [env:NerminerV2] platform = espressif32 @@ -23,11 +23,13 @@ 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 @@ -43,6 +45,7 @@ lib_deps = arduino-libraries/NTPClient ;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 + [env:ESP32-devKitv1] platform = espressif32 board = esp32dev @@ -54,8 +57,10 @@ 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 @@ -66,6 +71,7 @@ lib_deps = mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient + [env:TTGO-T-Display] platform = espressif32 board = esp32dev ;esp-wrover-kit @@ -77,8 +83,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 = huge_app.csv + build_flags = ;-D DEBUG_MINING=1 -D TDISPLAY=1 @@ -94,7 +103,9 @@ lib_deps = platform = espressif32 board = lilygo-t-amoled framework = arduino + board_build.partitions = huge_app.csv + build_flags = -DNERMINER_S3_AMOLED -DBOARD_HAS_PSRAM @@ -111,7 +122,9 @@ lib_deps = platform = espressif32 board = esp32-s3-devkitc-1 framework = arduino + board_build.partitions = huge_app.csv + build_flags = -DNERMINER_S3_DONGLE -DBOARD_HAS_PSRAM @@ -122,31 +135,8 @@ 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 ;(ESP32-D0WD-V3) -board = esp32cam -framework = arduino -monitor_filters = - esp32_exception_decoder - time - log2file -monitor_speed = 115200 -upload_speed = 921600 -board_build.partitions = huge_app.csv -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 - arduino-libraries/NTPClient -lib_ignore = - TFT_eSPI [env:NerminerV2-T-QT] platform = espressif32 diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 9904d15..94e802f 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/displays/display.h" +#include "drivers/display.h" //3 seconds WDT #define WDT_TIMEOUT 3 @@ -38,12 +38,7 @@ const char* ntpServer = "pool.ntp.org"; /********* INIT *****/ void setup() { -#ifdef MONITOR_SPEED - Serial.begin(MONITOR_SPEED); -#else - Serial.begin(115200); -#endif //MONITOR_SPEED - + Serial.begin(115200); Serial.setTimeout(0); delay(100); @@ -57,8 +52,7 @@ void setup() button1.setPressTicks(5000); button1.attachClick(switchToNextScreen); button1.attachDoubleClick(alternateScreenRotation); - button1.attachLongPressStart(reset_configuration); - button1.attachMultiClick(alternateScreenState); + button1.attachLongPressStart(reset_configurations); #endif #if defined(PIN_BUTTON_1) && defined(PIN_BUTTON_2) //Button 1 of two button device @@ -70,7 +64,7 @@ void setup() #if defined(PIN_BUTTON_2) //Button 2 of two button device button2.setPressTicks(5000); button2.attachClick(switchToNextScreen); - button2.attachLongPressStart(reset_configuration); + button2.attachLongPressStart(reset_configurations); #endif /******** INIT NERDMINER ************/ diff --git a/src/drivers/devices/device.h b/src/drivers/devices/device.h deleted file mode 100644 index 7d8ba51..0000000 --- a/src/drivers/devices/device.h +++ /dev/null @@ -1,27 +0,0 @@ -#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_2432S028R) -#include "esp322432s028r.h" -#elif defined(NERMINER_T_QT) -#include "lilygoT_QT.h" -#elif defined(NERDMINER_T_DISPLAY_V1) -#include "lilygoV1TDisplay.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/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h deleted file mode 100644 index 54d7460..0000000 --- a/src/drivers/devices/esp32CAM.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _ESP32CAM_H_ -#define _ESP32CAM_H_ - -#define PIN_BUTTON_1 0 -#define LED_PIN 33 - -#define NO_DISPLAY - -// 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_ diff --git a/src/drivers/displays/display.cpp b/src/drivers/display.cpp similarity index 100% rename from src/drivers/displays/display.cpp rename to src/drivers/display.cpp diff --git a/src/drivers/displays/display.h b/src/drivers/display.h similarity index 94% rename from src/drivers/displays/display.h rename to src/drivers/display.h index 2a4a469..331ea95 100644 --- a/src/drivers/displays/display.h +++ b/src/drivers/display.h @@ -1,7 +1,7 @@ #ifndef DISPLAY_H #define DISPLAY_H -#include "DisplayDriver.h" +#include "drivers.h" extern DisplayDriver *currentDisplayDriver; diff --git a/src/drivers/displays/amoledDisplayDriver.cpp b/src/drivers/displays/amoledDisplayDriver.cpp index 4abc576..c0eae8b 100644 --- a/src/drivers/displays/amoledDisplayDriver.cpp +++ b/src/drivers/displays/amoledDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "DisplayDriver.h" +#include "../drivers.h" #ifdef AMOLED_DISPLAY diff --git a/src/drivers/displays/dongleDisplayDriver.cpp b/src/drivers/displays/dongleDisplayDriver.cpp index f6b4fe0..2ba6356 100644 --- a/src/drivers/displays/dongleDisplayDriver.cpp +++ b/src/drivers/displays/dongleDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "DisplayDriver.h" +#include "../drivers.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/esp23_2432s028r.cpp b/src/drivers/displays/esp23_2432s028r.cpp index 7c96258..e87a279 100644 --- a/src/drivers/displays/esp23_2432s028r.cpp +++ b/src/drivers/displays/esp23_2432s028r.cpp @@ -1,4 +1,4 @@ -#include "DisplayDriver.h" +#include "../drivers.h" #ifdef ESP32_2432S028R diff --git a/src/drivers/displays/noDisplayDriver.cpp b/src/drivers/displays/noDisplayDriver.cpp index 636cf81..23a74bd 100644 --- a/src/drivers/displays/noDisplayDriver.cpp +++ b/src/drivers/displays/noDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "DisplayDriver.h" +#include "../drivers.h" #ifdef NO_DISPLAY diff --git a/src/drivers/displays/tDisplayDriver.cpp b/src/drivers/displays/tDisplayDriver.cpp index 76eede4..6eb454b 100644 --- a/src/drivers/displays/tDisplayDriver.cpp +++ b/src/drivers/displays/tDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "DisplayDriver.h" +#include "../drivers.h" #ifdef T_DISPLAY diff --git a/src/drivers/displays/tDisplayV1Driver.cpp b/src/drivers/displays/tDisplayV1Driver.cpp index 93b8f76..ac05290 100644 --- a/src/drivers/displays/tDisplayV1Driver.cpp +++ b/src/drivers/displays/tDisplayV1Driver.cpp @@ -1,4 +1,4 @@ -#include "DisplayDriver.h" +#include "../drivers.h" #ifdef V1_DISPLAY diff --git a/src/drivers/displays/t_qtDisplayDriver.cpp b/src/drivers/displays/t_qtDisplayDriver.cpp index f632cae..c5ddadc 100644 --- a/src/drivers/displays/t_qtDisplayDriver.cpp +++ b/src/drivers/displays/t_qtDisplayDriver.cpp @@ -1,4 +1,4 @@ -#include "DisplayDriver.h" +#include "../drivers.h" #ifdef T_QT_DISPLAY diff --git a/src/drivers/displays/displayDriver.h b/src/drivers/drivers.h similarity index 73% rename from src/drivers/displays/displayDriver.h rename to src/drivers/drivers.h index 939b00c..9897db0 100644 --- a/src/drivers/displays/displayDriver.h +++ b/src/drivers/drivers.h @@ -1,7 +1,26 @@ -#ifndef DISPLAYDRIVER_H_ -#define DISPLAYDRIVER_H_ +#ifndef DRIVERS_H +#define DRIVERS_H -#include "..\devices\device.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_2432S028R) +#include "devices/esp322432s028r.h" +#elif defined(NERMINER_T_QT) +#include "devices/lilygoT_QT.h" +#elif defined(NERDMINER_T_DISPLAY_V1) +#include "devices/lilygoV1TDisplay.h" + +#else +#error "No device defined" +#endif typedef void (*AlternateFunction)(void); typedef void (*DriverInitFunction)(void); @@ -38,4 +57,4 @@ extern DisplayDriver tDisplayV1Driver; #define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#endif // DISPLAYDRIVER_H_ +#endif // DRIVERS_H diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp deleted file mode 100644 index fe06bde..0000000 --- a/src/drivers/storage/SDCard.cpp +++ /dev/null @@ -1,157 +0,0 @@ - -#include -#include -#include - -#include "storage.h" -#include "nvMemory.h" -#include "..\devices\device.h" -#include "SDCard.h" - -#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) - -#include - -SDCard::SDCard() -{ -#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() -{ - unmount(); -} - -void SDCard::SD2nvMemory(nvMemory* nvMem) -{ - TSettings Settings; - if (loadConfigFile(&Settings)) - { - nvMem->saveConfig(&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 - - if (initSDcard()) - { - if (iSD_->exists(JSON_CONFIG_FILE)) - { - // The file exists, reading and loading - File configFile = iSD_->open(JSON_CONFIG_FILE, "r"); - if (configFile) - { - 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) - { - 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(); - if (json.containsKey(JSON_KEY_STATS2NV)) - Settings->saveStats = json[JSON_KEY_STATS2NV].as(); - return true; - } - else - { - // Error loading JSON data - Serial.println("SDCard: Error parsing config file!"); - } - } - else - { - Serial.println("SDCard: Error opening config file!"); - } - } - else - { - Serial.println("SDCard: No config file available!"); - } - unmount(); - } - return false; -} - -void SDCard::unmount() -{ - iSD_->end(); - Serial.println("SDCard: Unmounted"); -} - -bool SDCard::initSDcard() -{ - if (iSD_->cardType() != CARD_NONE) - { - Serial.println("SDCard: Already mounted."); - return true; - } - Serial.println("SDCard: Mounting card."); - - bool cardInitialized = false; -#if defined (BUILD_SDMMC_4) - if (iSD_->cardType() == CARD_NONE) - { - 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 (BUILD_SDMMC_1) - #warning SDMMC : 1 - bit mode is not always working.If you experience issues, try other modes. - if (iSD_->cardType() == CARD_NONE) - { - 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 - if (cardInitialized) - { - if (iSD_->cardType() != CARD_NONE) - { - Serial.println("SDCard: Mounted."); - return true; - } - else - { - Serial.println("SDCard: Mounting failed."); - iSD_->end(); - } - } - return false; -} - -#else - -SDCard::SDCard() {} -SDCard::~SDCard() {} -void SDCard::SD2nvMemory(nvMemory* nvMem) {}; -bool SDCard::loadConfigFile(TSettings* Settings) { return false; } -bool SDCard::initSDcard() { return false; } -void unmount() {} - -#endif //BUILD_SDMMC \ No newline at end of file diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h deleted file mode 100644 index b2e91f5..0000000 --- a/src/drivers/storage/SDCard.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _SDCARD_H_ -#define _SDCARD_H_ - -#include "storage.h" -#include "nvMemory.h" -#include "..\devices\device.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 - -// Handles the transfer of settings from sd card to nv memory (wifi credentials are handled by wifimanager) -class SDCard -{ -public: - SDCard(); - ~SDCard(); - void SD2nvMemory(nvMemory* nvMem); - bool loadConfigFile(TSettings* Settings); -private: - bool initSDcard(); - void unmount(); - -#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_; -#endif -}; - -#endif // _SDCARD_H_ diff --git a/src/drivers/storage/nvMemory.cpp b/src/drivers/storage/nvMemory.cpp deleted file mode 100644 index a686589..0000000 --- a/src/drivers/storage/nvMemory.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "nvMemory.h" - -#ifdef NVMEM_SPIFFS - -#include -#include -#include - -#include "..\devices\device.h" -#include "storage.h" - -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; - json[JSON_KEY_STATS2NV] = Settings->saveStats; - - // 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 - File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); - if (configFile) - { - Serial.println("SPIFS: Loading config file"); - StaticJsonDocument<512> json; - DeserializationError error = deserializeJson(json, configFile); - configFile.close(); - serializeJsonPretty(json, Serial); - Serial.print('\n'); - if (!error) - { - 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(); - if (json.containsKey(JSON_KEY_STATS2NV)) - Settings->saveStats = json[JSON_KEY_STATS2NV].as(); - return true; - } - else - { - // Error loading JSON data - 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; -} - -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 - -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 //NVMEM_TYPE \ No newline at end of file diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h deleted file mode 100644 index 163431c..0000000 --- a/src/drivers/storage/nvMemory.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _NVMEMORY_H_ -#define _NVMEMORY_H_ - -// we only have one implementation right now and nothing to choose from. -#define NVMEM_SPIFFS - -#include "..\devices\device.h" -#include "storage.h" - -// Handles load and store of user settings, except wifi credentials. Those are managed by the wifimanager. -class nvMemory -{ -public: - nvMemory(); - ~nvMemory(); - bool saveConfig(TSettings* Settings); - bool loadConfig(TSettings* Settings); - bool deleteConfig(); -private: - bool init(); - bool Initialized_; -}; - -#ifdef NVMEM_SPIFFS -#define ESP_DRD_USE_SPIFFS true -#else -#error We need some kind of permanent storage implementation! -#endif //NVMEM_TYPE - -#endif // _NVMEMORY_H_ diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h deleted file mode 100644 index 8aa0668..0000000 --- a/src/drivers/storage/storage.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _STORAGE_H_ -#define _STORAGE_H_ - -#include - -#define DEFAULT_SSID "NerdMinerAP" -#define DEFAULT_WIFIPW "MineYourCoins" -#define DEFAULT_POOLURL "public-pool.io" -#define DEFAULT_WALLETID "yourBtcAddress" -#define DEFAULT_POOLPORT 21496 -#define DEFAULT_TIMEZONE 2 -#define DEFAULT_SAVESTATS false - -// 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" -#define JSON_KEY_STATS2NV "saveStats" - -struct TSettings -{ - 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 }; - bool saveStats{ DEFAULT_SAVESTATS }; -}; - -#endif // _STORAGE_H_ \ No newline at end of file diff --git a/src/mining.cpp b/src/mining.cpp index d6f5694..9bf3fce 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -10,8 +10,7 @@ #include "mining.h" #include "utils.h" #include "monitor.h" -#include "drivers/displays/display.h" -#include "drivers/storage/storage.h" +#include "drivers/display.h" nvs_handle_t stat_handle; @@ -29,10 +28,11 @@ uint32_t valids; // increased if blockhash <= target double best_diff = 0.0; // Variables to hold data from custom textboxes -//Track mining stats in non volatile memory -extern TSettings Settings; - +extern char poolString[80]; +extern int portNumber; +extern char btcString[80]; IPAddress serverIP(1, 1, 1, 1); //Temporally save poolIPaddres +extern bool saveStatsToNVS; //Track mining stats in non volatile memory //Global work data static WiFiClient client; @@ -59,14 +59,14 @@ bool checkPoolConnection(void) { //Resolve first time pool DNS and save IP if(serverIP == IPAddress(1,1,1,1)) { - WiFi.hostByName(Settings.PoolAddress, serverIP); + WiFi.hostByName(poolString, serverIP); Serial.printf("Resolved DNS and save ip (first time) got: %s\n", serverIP.toString()); } //Try connecting pool IP - if (!client.connect(serverIP, Settings.PoolPort)) { - Serial.println("Imposible to connect to : " + String(Settings.PoolAddress)); - WiFi.hostByName(Settings.PoolAddress, serverIP); + if (!client.connect(serverIP, portNumber)) { + Serial.println("Imposible to connect to : " + String(poolString)); + WiFi.hostByName(poolString, serverIP); Serial.printf("Resolved DNS got: %s\n", serverIP.toString()); vTaskDelay(1000 / portTICK_PERIOD_MS); return false; @@ -166,7 +166,7 @@ void runStratumWorker(void *name) { continue; } - strcpy(mWorker.wName, Settings.BtcWallet); + strcpy(mWorker.wName, btcString); strcpy(mWorker.wPass, "x"); // STEP 2: Pool authorize work (Block Info) tx_mining_auth(client, mWorker.wName, mWorker.wPass); //Don't verifies authoritzation, TODO @@ -386,7 +386,7 @@ void runMiner(void * task_id) { #define REDRAW_EVERY 10 void restoreStat() { - if(!Settings.saveStats) return; + if(!saveStatsToNVS) return; esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { Serial.printf("[MONITOR] NVS partition is full or has invalid version, erasing...\n"); @@ -405,7 +405,7 @@ void restoreStat() { } void saveStat() { - if(!Settings.saveStats) return; + if(!saveStatsToNVS) return; Serial.printf("[MONITOR] Saving stats\n"); nvs_set_blob(stat_handle, "best_diff", &best_diff, sizeof(double)); nvs_set_u32(stat_handle, "Mhashes", Mhashes); @@ -447,8 +447,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/monitor.cpp b/src/monitor.cpp index 56f1368..27753cd 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/storage.h" +extern char poolString[80]; extern uint32_t templates; extern uint32_t hashes; extern uint32_t Mhashes; @@ -23,8 +23,7 @@ extern double best_diff; // track best diff extern monitor_data mMonitor; -//from saved config -extern TSettings Settings; +extern int GMTzone; //Gotten from saved config WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); @@ -40,7 +39,7 @@ void setup_monitor(void){ // Adjust offset depending on your zone // GMT +2 in seconds (zona horaria de Europa Central) - timeClient.setTimeOffset(3600 * Settings.Timezone); + timeClient.setTimeOffset(3600 * GMTzone); Serial.println("TimeClient setup done"); } @@ -172,6 +171,7 @@ unsigned long mTriggerUpdate = 0; unsigned long initialMillis = millis(); unsigned long initialTime = 0; unsigned long mPoolUpdate = 0; +extern char btcString[80]; void getTime(unsigned long* currentHours, unsigned long* currentMinutes, unsigned long* currentSeconds){ @@ -296,7 +296,7 @@ pool_data getPoolData(void){ HTTPClient http; http.setReuse(true); try { - String btcWallet = Settings.BtcWallet; + String btcWallet = btcString; Serial.println(btcWallet); if (btcWallet.indexOf(".")>0) btcWallet = btcWallet.substring(0,btcWallet.indexOf(".")); http.begin(String(getPublicPool)+btcWallet); diff --git a/src/wManager.cpp b/src/wManager.cpp index 93afff4..1e94ae4 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -1,148 +1,221 @@ +#define ESP_DRD_USE_SPIFFS true // Include Libraries //#include ".h" #include +#include +#include #include - +#include #include "wManager.h" #include "monitor.h" -#include "drivers/displays/display.h" -#include "drivers/storage/SDCard.h" -#include "drivers/storage/nvMemory.h" -#include "drivers/storage/storage.h" +#include "drivers/display.h" +// JSON configuration file +#define JSON_CONFIG_FILE "/config.json" // Flag for saving data bool shouldSaveConfig = false; // Variables to hold data from custom textboxes -TSettings Settings; +char poolString[80] = "public-pool.io"; +int portNumber = 21496;//3333; +char btcString[80] = "yourBtcAddress"; +int GMTzone = 2; //Currently selected in spain +bool saveStatsToNVS = false; //Track mining stats in non volatile memory + // Define WiFiManager Object WiFiManager wm; extern monitor_data mMonitor; -nvMemory nvMem; +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; + json["saveStatsToNVS"] = String(saveStatsToNVS); + + // 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(); + if(json.containsKey("saveStatsToNVS")) + saveStatsToNVS = json["saveStatsToNVS"].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; +} + 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()); -} - -void reset_configuration() -{ - Serial.println("Erasing Config, restarting"); - nvMem.deleteConfig(); - wm.resetSettings(); - ESP.restart(); + Serial.print("Config IP Address: "); + Serial.println(WiFi.softAPIP()); } void init_WifiManager() { -#ifdef MONITOR_SPEED - Serial.begin(MONITOR_SPEED); -#else - Serial.begin(115200); -#endif //MONITOR_SPEED - //Serial.setTxTimeoutMs(10); + Serial.begin(115200); + //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")); + forceConfig = true; + wm.setBreakAfterConfig(true); //Set to detect config edition and save } -#endif - // Explicitly set WiFi mode - WiFi.mode(WIFI_STA); + #endif + + bool spiffsSetup = loadConfigFile(); + if (!spiffsSetup) + { + Serial.println(F("Forcing config mode as there is no saved config")); + forceConfig = true; + + } - if (!nvMem.loadConfig(&Settings)) - { - //No config file on internal flash. - SDCard SDCrd; - if (SDCrd.loadConfigFile(&Settings)) - { - //Config file on SD card. - SDCrd.SD2nvMemory(&nvMem); // reboot on success. - } - else - { - //No config file on SD card. Starting wifi config server. - forceConfig = true; - } - }; + // Explicitly set WiFi mode + WiFi.mode(WIFI_STA); - // Reset settings (only for development) - //wm.resetSettings(); + // Reset settings (only for development) + //wm.resetSettings(); - //Set dark theme - //wm.setClass("invert"); // dark theme + //Set dark theme + //wm.setClass("invert"); // dark theme + + // Set config save notify callback + wm.setSaveConfigCallback(saveConfigCallback); - // 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); - // 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 - //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 + // Text box (String) - 80 characters maximum + WiFiManagerParameter pool_text_box("Poolurl", "Pool url", poolString, 80); - // Custom elements + // 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 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 (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", Settings.Timezone); + sprintf(charZone, "%d", GMTzone); WiFiManagerParameter time_text_box_num("TimeZone", "TimeZone fromUTC (-12/+12)", charZone, 3); WiFiManagerParameter features_html("

"); char checkboxParams[24] = "type=\"checkbox\""; - if (Settings.saveStats) + if (saveStatsToNVS) { strcat(checkboxParams, " checked"); } @@ -156,103 +229,109 @@ void init_WifiManager() wm.addParameter(&features_html); wm.addParameter(&save_stats_to_nvs); - Serial.println("AllDone: "); - if (forceConfig) + 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")) { - // 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(DEFAULT_SSID, DEFAULT_WIFIPW)) - { - //Could be break forced after edditing, so save new config - Serial.println("failed to connect and hit timeout"); - 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()); - Serial.println(save_stats_to_nvs.getValue()); - Settings.saveStats = (strncmp(save_stats_to_nvs.getValue(), "T", 1) == 0); - - nvMem.saveConfig(&Settings); - delay(3000); - //reset and try again, or maybe put it to deep sleep - ESP.restart(); - delay(5000); - }; + 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()); + saveStatsToNVS = (strncmp(save_stats_to_nvs.getValue(), "T", 1) == 0); + saveConfigFile(); + 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 - 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); - } - } - + } + else + { + //Tratamos de conectar con la configuraciĆ³n inicial ya almacenada 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(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); - - } - - // Save the custom parameters to FS - if (shouldSaveConfig) + wm.setCaptivePortalEnable(false); // disable captive portal redirection + if (!wm.autoConnect("NerdMinerAP","MineYourCoins")) { - nvMem.saveConfig(&Settings); + 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; + + //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(); + } } +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); - } - oldStatus = 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; + } } + + diff --git a/src/wManager.h b/src/wManager.h index ef2bd37..870b435 100644 --- a/src/wManager.h +++ b/src/wManager.h @@ -1,8 +1,3 @@ -#ifndef _WMANAGER_H -#define _WMANAGER_H - void init_WifiManager(); void wifiManagerProcess(); -void reset_configuration(); - -#endif // _WMANAGER_H +void reset_configurations(); \ No newline at end of file