From 0f65433875a4164064da88f832f12b84e4c4a17c Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 20 Sep 2023 19:42:07 +0200 Subject: [PATCH] restore old keys in SPIFFS --- README.md | 4 ++-- src/drivers/storage/nvMemory.cpp | 26 +++++++++++++------------- src/drivers/storage/storage.h | 23 ++++++++++++++++++----- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index dd37a9c..53ad837 100644 --- a/README.md +++ b/README.md @@ -90,12 +90,12 @@ After programming, you will only need to setup your Wifi and BTC address. 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", + "WifiPW": "myWifiPassword", "PoolUrl": "public-pool.io", "PoolPort": 21496, "BtcWallet": "walletID", "Timezone": 2, - "saveStats": false + "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. diff --git a/src/drivers/storage/nvMemory.cpp b/src/drivers/storage/nvMemory.cpp index 0f737aa..cc5f997 100644 --- a/src/drivers/storage/nvMemory.cpp +++ b/src/drivers/storage/nvMemory.cpp @@ -29,11 +29,11 @@ bool nvMemory::saveConfig(TSettings* Settings) // 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; + json[JSON_SPIFFS_KEY_POOLURL] = Settings->PoolAddress; + json[JSON_SPIFFS_KEY_POOLPORT] = Settings->PoolPort; + json[JSON_SPIFFS_KEY_WALLETID] = Settings->BtcWallet; + json[JSON_SPIFFS_KEY_TIMEZONE] = Settings->Timezone; + json[JSON_SPIFFS_KEY_STATS2NV] = Settings->saveStats; // Open config file File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); @@ -84,14 +84,14 @@ bool nvMemory::loadConfig(TSettings* Settings) Serial.print('\n'); if (!error) { - 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(); + Settings->PoolAddress = json[JSON_SPIFFS_KEY_POOLURL] | Settings->PoolAddress; + strcpy(Settings->BtcWallet, json[JSON_SPIFFS_KEY_WALLETID] | Settings->BtcWallet); + if (json.containsKey(JSON_SPIFFS_KEY_POOLPORT)) + Settings->PoolPort = json[JSON_SPIFFS_KEY_POOLPORT].as(); + if (json.containsKey(JSON_SPIFFS_KEY_TIMEZONE)) + Settings->Timezone = json[JSON_SPIFFS_KEY_TIMEZONE].as(); + if (json.containsKey(JSON_SPIFFS_KEY_STATS2NV)) + Settings->saveStats = json[JSON_SPIFFS_KEY_STATS2NV].as(); return true; } else diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index 5da92e3..76e80cd 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -3,6 +3,9 @@ #include +// config files + +// default settings #define DEFAULT_SSID "NerdMinerAP" #define DEFAULT_WIFIPW "MineYourCoins" #define DEFAULT_POOLURL "public-pool.io" @@ -11,16 +14,26 @@ #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" +// JSON config files +#define JSON_CONFIG_FILE "/config.json" + +// JSON config file SD card (for user interaction, readme.md) +#define JSON_KEY_SSID "SSID" +#define JSON_KEY_PASW "WifiPW" #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" +#define JSON_KEY_STATS2NV "SaveStats" +// JSON config file SPIFFS (different for backward compatibility with existing devices) +#define JSON_SPIFFS_KEY_POOLURL "poolString" +#define JSON_SPIFFS_KEY_POOLPORT "portNumber" +#define JSON_SPIFFS_KEY_WALLETID "btcString" +#define JSON_SPIFFS_KEY_TIMEZONE "gmtZone" +#define JSON_SPIFFS_KEY_STATS2NV "saveStatsToNVS" + +// settings struct TSettings { String WifiSSID{ DEFAULT_SSID };