This commit is contained in:
George Alexandre Silva 2023-09-18 22:49:31 -03:00
commit 16ffd47a67
26 changed files with 739 additions and 329 deletions

3
.gitignore vendored
View File

@ -1,5 +1,8 @@
.pio
.vscode
.vs
*.sln
*.vcxproj*
NerdMinerLog.txt
bin/0x10000_firmware.bin
logs

View File

@ -44,6 +44,7 @@ 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]
@ -75,12 +76,33 @@ 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 |
@ -99,6 +121,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**

View File

@ -10,7 +10,7 @@
[platformio]
globallib_dir = lib
default_envs = ESP32-2432S028R ;NerminerV2, ESP32-devKitv1, NerminerV2-S3-DONGLE, NerminerV2-S3-AMOLED, NerminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R
default_envs = esp32cam, 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,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-amoled
framework = arduino
board_build.partitions = huge_app.csv
build_flags =
-DNERMINER_S3_AMOLED
-DBOARD_HAS_PSRAM
@ -122,9 +111,7 @@ 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
@ -135,8 +122,31 @@ 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

View File

@ -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
@ -38,7 +38,12 @@ const char* ntpServer = "pool.ntp.org";
/********* INIT *****/
void setup()
{
#ifdef MONITOR_SPEED
Serial.begin(MONITOR_SPEED);
#else
Serial.begin(115200);
#endif //MONITOR_SPEED
Serial.setTimeout(0);
delay(100);
@ -52,7 +57,8 @@ void setup()
button1.setPressTicks(5000);
button1.attachClick(switchToNextScreen);
button1.attachDoubleClick(alternateScreenRotation);
button1.attachLongPressStart(reset_configurations);
button1.attachLongPressStart(reset_configuration);
button1.attachMultiClick(alternateScreenState);
#endif
#if defined(PIN_BUTTON_1) && defined(PIN_BUTTON_2) //Button 1 of two button device
@ -64,7 +70,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 ************/

View File

@ -0,0 +1,27 @@
#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__

View File

@ -0,0 +1,18 @@
#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_

View File

@ -1,4 +1,4 @@
#include "../drivers.h"
#include "DisplayDriver.h"
#ifdef AMOLED_DISPLAY

View File

@ -1,7 +1,7 @@
#ifndef DISPLAY_H
#define DISPLAY_H
#include "drivers.h"
#include "DisplayDriver.h"
extern DisplayDriver *currentDisplayDriver;

View File

@ -1,26 +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_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
#include "..\devices\device.h"
typedef void (*AlternateFunction)(void);
typedef void (*DriverInitFunction)(void);
@ -57,4 +38,4 @@ extern DisplayDriver tDisplayV1Driver;
#define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif // DRIVERS_H
#endif // DISPLAYDRIVER_H_

View File

@ -1,4 +1,4 @@
#include "../drivers.h"
#include "DisplayDriver.h"
#ifdef DONGLE_DISPLAY

View File

@ -1,4 +1,4 @@
#include "../drivers.h"
#include "DisplayDriver.h"
#ifdef ESP32_2432S028R

View File

@ -1,4 +1,4 @@
#include "../drivers.h"
#include "DisplayDriver.h"
#ifdef NO_DISPLAY

View File

@ -1,4 +1,4 @@
#include "../drivers.h"
#include "DisplayDriver.h"
#ifdef T_DISPLAY

View File

@ -1,4 +1,4 @@
#include "../drivers.h"
#include "DisplayDriver.h"
#ifdef V1_DISPLAY

View File

@ -1,4 +1,4 @@
#include "../drivers.h"
#include "DisplayDriver.h"
#ifdef T_QT_DISPLAY

View File

@ -0,0 +1,157 @@
#include <FS.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include "storage.h"
#include "nvMemory.h"
#include "..\devices\device.h"
#include "SDCard.h"
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)
#include <SD_MMC.h>
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<int>();
if (json.containsKey(JSON_KEY_TIMEZONE))
Settings->Timezone = json[JSON_KEY_TIMEZONE].as<int>();
if (json.containsKey(JSON_KEY_STATS2NV))
Settings->saveStats = json[JSON_KEY_STATS2NV].as<bool>();
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

View File

@ -0,0 +1,38 @@
#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 <SD_MMC.h>
#elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3))
#define BUILD_SDMMC_1
#include <SD_MMC.h>
#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_

View File

@ -0,0 +1,148 @@
#include "nvMemory.h"
#ifdef NVMEM_SPIFFS
#include <SPIFFS.h>
#include <FS.h>
#include <ArduinoJson.h>
#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<int>();
if (json.containsKey(JSON_KEY_TIMEZONE))
Settings->Timezone = json[JSON_KEY_TIMEZONE].as<int>();
if (json.containsKey(JSON_KEY_STATS2NV))
Settings->saveStats = json[JSON_KEY_STATS2NV].as<bool>();
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

View File

@ -0,0 +1,30 @@
#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_

View File

@ -0,0 +1,35 @@
#ifndef _STORAGE_H_
#define _STORAGE_H_
#include <inttypes.h>
#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_

View File

@ -10,7 +10,8 @@
#include "mining.h"
#include "utils.h"
#include "monitor.h"
#include "drivers/display.h"
#include "drivers/displays/display.h"
#include "drivers/storage/storage.h"
nvs_handle_t stat_handle;
@ -28,11 +29,10 @@ uint32_t 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];
//Track mining stats in non volatile memory
extern TSettings Settings;
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(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;
@ -166,7 +166,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
@ -386,7 +386,7 @@ void runMiner(void * task_id) {
#define REDRAW_EVERY 10
void restoreStat() {
if(!saveStatsToNVS) return;
if(!Settings.saveStats) 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(!saveStatsToNVS) return;
if(!Settings.saveStats) 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);

View File

@ -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,7 +23,8 @@ extern double best_diff; // track best diff
extern monitor_data mMonitor;
extern int GMTzone; //Gotten from saved config
//from saved config
extern TSettings Settings;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
@ -39,7 +40,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");
}
@ -171,7 +172,6 @@ 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 = btcString;
String btcWallet = Settings.BtcWallet;
Serial.println(btcWallet);
if (btcWallet.indexOf(".")>0) btcWallet = btcWallet.substring(0,btcWallet.indexOf("."));
http.begin(String(getPublicPool)+btcWallet);

View File

@ -1,121 +1,29 @@
#define ESP_DRD_USE_SPIFFS true
// Include Libraries
//#include ".h"
#include <WiFi.h>
#include <SPIFFS.h>
#include <FS.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
#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"
// JSON configuration file
#define JSON_CONFIG_FILE "/config.json"
// 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
bool saveStatsToNVS = false; //Track mining stats in non volatile memory
TSettings Settings;
// 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;
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<int>();
GMTzone = json["gmtZone"].as<int>();
if(json.containsKey("saveStatsToNVS"))
saveStatsToNVS = json["saveStatsToNVS"].as<int>();
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;
}
nvMemory nvMem;
void saveConfigCallback()
// Callback notifying us of the need to save configuration
@ -137,9 +45,21 @@ void configModeCallback(WiFiManager *myWiFiManager)
Serial.println(WiFi.softAPIP());
}
void reset_configuration()
{
Serial.println("Erasing Config, restarting");
nvMem.deleteConfig();
wm.resetSettings();
ESP.restart();
}
void init_WifiManager()
{
#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)
@ -159,18 +79,25 @@ void init_WifiManager()
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;
}
// Explicitly set WiFi mode
WiFi.mode(WIFI_STA);
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;
}
};
// Reset settings (only for development)
//wm.resetSettings();
@ -195,27 +122,27 @@ void init_WifiManager()
// Custom elements
// Text box (String) - 80 characters maximum
WiFiManagerParameter pool_text_box("Poolurl", "Pool url", poolString, 80);
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", portNumber);
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", btcString, 80);
WiFiManagerParameter addr_text_box("btcAddress", "Your BTC address", Settings.BtcWallet, 80);
// Text box (Number) - 2 characters maximum
char charZone[6];
sprintf(charZone, "%d", GMTzone);
sprintf(charZone, "%d", Settings.Timezone);
WiFiManagerParameter time_text_box_num("TimeZone", "TimeZone fromUTC (-12/+12)", charZone, 3);
WiFiManagerParameter features_html("<hr><br><label style=\"font-weight: bold;margin-bottom: 25px;display: inline-block;\">Features</label>");
char checkboxParams[24] = "type=\"checkbox\"";
if (saveStatsToNVS)
if (Settings.saveStats)
{
strcat(checkboxParams, " checked");
}
@ -231,33 +158,36 @@ void init_WifiManager()
Serial.println("AllDone: ");
if (forceConfig)
// Run if we need a configuration
{
// 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"))
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(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();
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);
}
};
}
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("NerdMinerAP","MineYourCoins"))
if (!wm.autoConnect(Settings.WifiSSID, Settings.WifiPW))
{
Serial.println("Failed to connect and hit timeout");
//delay(3000);
@ -280,41 +210,34 @@ void init_WifiManager()
// Lets deal with the user config values
// Copy the string value
strncpy(poolString, pool_text_box.getValue(), sizeof(poolString));
strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress));
Serial.print("PoolString: ");
Serial.println(poolString);
Serial.println(Settings.PoolAddress);
//Convert the number value
portNumber = atoi(port_text_box_num.getValue());
Settings.PoolPort = atoi(port_text_box_num.getValue());
Serial.print("portNumber: ");
Serial.println(portNumber);
Serial.println(Settings.PoolPort);
// Copy the string value
strncpy(btcString, addr_text_box.getValue(), sizeof(btcString));
strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet));
Serial.print("btcString: ");
Serial.println(btcString);
Serial.println(Settings.BtcWallet);
//Convert the number value
GMTzone = atoi(time_text_box_num.getValue());
Settings.Timezone = atoi(time_text_box_num.getValue());
Serial.print("TimeZone fromUTC: ");
Serial.println(GMTzone);
Serial.println(Settings.Timezone);
}
// Save the custom parameters to FS
if (shouldSaveConfig)
{
saveConfigFile();
nvMem.saveConfig(&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;
@ -333,5 +256,3 @@ void wifiManagerProcess() {
oldStatus = newStatus;
}
}

View File

@ -1,3 +1,8 @@
#ifndef _WMANAGER_H
#define _WMANAGER_H
void init_WifiManager();
void wifiManagerProcess();
void reset_configurations();
void reset_configuration();
#endif // _WMANAGER_H