bugfix, optimization
This commit is contained in:
parent
2057ba8082
commit
89287f43c9
@ -26,13 +26,12 @@ SDCard::~SDCard()
|
||||
unmount();
|
||||
}
|
||||
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem)
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings)
|
||||
{
|
||||
TSettings Settings;
|
||||
if (loadConfigFile(&Settings))
|
||||
if (loadConfigFile(Settings))
|
||||
{
|
||||
nvMem->saveConfig(&Settings);
|
||||
WiFi.begin(Settings.WifiSSID, Settings.WifiPW);
|
||||
nvMem->saveConfig(Settings);
|
||||
WiFi.begin(Settings->WifiSSID, Settings->WifiPW);
|
||||
Serial.println("SDCard: Settings transfered to internal memory. Restarting now.");
|
||||
ESP.restart();
|
||||
}
|
||||
@ -60,9 +59,9 @@ bool SDCard::loadConfigFile(TSettings* Settings)
|
||||
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);
|
||||
Settings->WifiSSID = json[JSON_KEY_SSID] | Settings->WifiSSID;
|
||||
Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW;
|
||||
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>();
|
||||
@ -149,7 +148,7 @@ bool SDCard::initSDcard()
|
||||
|
||||
SDCard::SDCard() {}
|
||||
SDCard::~SDCard() {}
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem) {};
|
||||
void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {};
|
||||
bool SDCard::loadConfigFile(TSettings* Settings) { return false; }
|
||||
bool SDCard::initSDcard() { return false; }
|
||||
void unmount() {}
|
||||
|
@ -21,7 +21,7 @@ class SDCard
|
||||
public:
|
||||
SDCard();
|
||||
~SDCard();
|
||||
void SD2nvMemory(nvMemory* nvMem);
|
||||
void SD2nvMemory(nvMemory* nvMem, TSettings* Settings);
|
||||
bool loadConfigFile(TSettings* Settings);
|
||||
private:
|
||||
bool initSDcard();
|
||||
|
@ -84,7 +84,7 @@ bool nvMemory::loadConfig(TSettings* Settings)
|
||||
Serial.print('\n');
|
||||
if (!error)
|
||||
{
|
||||
strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress);
|
||||
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>();
|
||||
|
@ -21,9 +21,7 @@ private:
|
||||
bool Initialized_;
|
||||
};
|
||||
|
||||
#ifdef NVMEM_SPIFFS
|
||||
#define ESP_DRD_USE_SPIFFS true
|
||||
#else
|
||||
#ifndef NVMEM_SPIFFS
|
||||
#error We need some kind of permanent storage implementation!
|
||||
#endif //NVMEM_TYPE
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef _STORAGE_H_
|
||||
#define _STORAGE_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#define DEFAULT_SSID "NerdMinerAP"
|
||||
#define DEFAULT_WIFIPW "MineYourCoins"
|
||||
@ -23,12 +23,12 @@
|
||||
|
||||
struct TSettings
|
||||
{
|
||||
char WifiSSID[80]{ DEFAULT_SSID };
|
||||
char WifiPW[80]{ DEFAULT_WIFIPW };
|
||||
char PoolAddress[80]{ DEFAULT_POOLURL };
|
||||
String WifiSSID{ DEFAULT_SSID };
|
||||
String WifiPW{ DEFAULT_WIFIPW };
|
||||
String PoolAddress{ DEFAULT_POOLURL };
|
||||
char BtcWallet[80]{ DEFAULT_WALLETID };
|
||||
uint32_t PoolPort{ DEFAULT_POOLPORT };
|
||||
uint32_t Timezone{ DEFAULT_TIMEZONE };
|
||||
int PoolPort{ DEFAULT_POOLPORT };
|
||||
int Timezone{ DEFAULT_TIMEZONE };
|
||||
bool saveStats{ DEFAULT_SAVESTATS };
|
||||
};
|
||||
|
||||
|
@ -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(Settings.PoolAddress.c_str(), 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);
|
||||
Serial.println("Imposible to connect to : " + Settings.PoolAddress);
|
||||
WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP);
|
||||
Serial.printf("Resolved DNS got: %s\n", serverIP.toString());
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
return false;
|
||||
|
@ -1,6 +1,8 @@
|
||||
#define ESP_DRD_USE_SPIFFS true
|
||||
|
||||
// Include Libraries
|
||||
//#include ".h"
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
#include <WiFiManager.h>
|
||||
@ -89,7 +91,7 @@ void init_WifiManager()
|
||||
if (SDCrd.loadConfigFile(&Settings))
|
||||
{
|
||||
//Config file on SD card.
|
||||
SDCrd.SD2nvMemory(&nvMem); // reboot on success.
|
||||
SDCrd.SD2nvMemory(&nvMem, &Settings); // reboot on success.
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -122,7 +124,7 @@ void init_WifiManager()
|
||||
// Custom elements
|
||||
|
||||
// Text box (String) - 80 characters maximum
|
||||
WiFiManagerParameter pool_text_box("Poolurl", "Pool url", Settings.PoolAddress, 80);
|
||||
WiFiManagerParameter pool_text_box("Poolurl", "Pool url", Settings.PoolAddress.c_str(), 80);
|
||||
|
||||
// Need to convert numerical input to string to display the default value.
|
||||
char convertedValue[6];
|
||||
@ -168,7 +170,7 @@ void init_WifiManager()
|
||||
{
|
||||
//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.PoolAddress = pool_text_box.getValue();
|
||||
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());
|
||||
@ -187,7 +189,7 @@ void init_WifiManager()
|
||||
//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))
|
||||
if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str()))
|
||||
{
|
||||
Serial.println("Failed to connect and hit timeout");
|
||||
//delay(3000);
|
||||
@ -210,7 +212,8 @@ void init_WifiManager()
|
||||
// Lets deal with the user config values
|
||||
|
||||
// Copy the string value
|
||||
strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress));
|
||||
Settings.PoolAddress = pool_text_box.getValue();
|
||||
//strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress));
|
||||
Serial.print("PoolString: ");
|
||||
Serial.println(Settings.PoolAddress);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user