Made more options configurable in the web interface
This commit is contained in:
parent
fb1cd73acf
commit
81885e3f15
6 changed files with 111 additions and 20 deletions
|
@ -76,12 +76,12 @@ void setupComponents()
|
|||
|
||||
void synchronizeTime()
|
||||
{
|
||||
configTime(3600, 0, NTP_SERVER);
|
||||
configTime(preferences.getUInt("gmtOffset", TIME_OFFSET_SECONDS), 0, NTP_SERVER);
|
||||
struct tm timeinfo;
|
||||
|
||||
while (!getLocalTime(&timeinfo))
|
||||
{
|
||||
configTime(3600, 0, NTP_SERVER);
|
||||
configTime(preferences.getUInt("gmtOffset", TIME_OFFSET_SECONDS), 0, NTP_SERVER);
|
||||
delay(500);
|
||||
Serial.println("Retry set time");
|
||||
}
|
||||
|
@ -114,7 +114,6 @@ void setupPreferences()
|
|||
bgColor = preferences.getUInt("bgColor", DEFAULT_BG_COLOR);
|
||||
preferences.getBool("ledFlashOnUpd", false);
|
||||
|
||||
// screenNameMap = {{SCREEN_BLOCK_HEIGHT, "Block Height"};
|
||||
|
||||
screenNameMap = {{SCREEN_BLOCK_HEIGHT, "Block Height"},
|
||||
{SCREEN_MSCW_TIME, "Sats per dollar"},
|
||||
|
|
|
@ -142,6 +142,11 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
|
|||
root["bgColor"] = getBgColor();
|
||||
root["timerSeconds"] = timerSeconds;
|
||||
root["timerRunning"] = timerRunning;
|
||||
root["tzOffset"] = preferences.getUInt("gmtOffset", TIME_OFFSET_SECONDS) / 60;
|
||||
root["useBitcoinNode"] = preferences.getBool("useNode", false);
|
||||
root["rpcPort"] = preferences.getUInt("rpcPort", BITCOIND_PORT);
|
||||
root["rpcUser"] = preferences.getString("rpcUser", BITCOIND_RPC_USER);
|
||||
root["rpcHost"] = preferences.getString("rpcHost", BITCOIND_HOST);
|
||||
#ifdef IS_BW
|
||||
root["epdColors"] = 2;
|
||||
#else
|
||||
|
@ -219,7 +224,15 @@ void onApiSettingsPost(AsyncWebServerRequest *request)
|
|||
preferences.putBool(prefKey.c_str(), visible);
|
||||
}
|
||||
|
||||
if (request->hasParam("timePerScreen", true))
|
||||
if (request->hasParam("tzOffset", true))
|
||||
{
|
||||
AsyncWebParameter *p = request->getParam("tzOffset", true);
|
||||
int tzOffsetSeconds = p->value().toInt() * 60;
|
||||
preferences.putUInt("tzOffset", tzOffsetSeconds);
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
if (request->hasParam("timePerScreen", true))
|
||||
{
|
||||
AsyncWebParameter *p = request->getParam("timePerScreen", true);
|
||||
timerSeconds = p->value().toInt() * 60;
|
||||
|
@ -227,6 +240,25 @@ void onApiSettingsPost(AsyncWebServerRequest *request)
|
|||
settingsChanged = true;
|
||||
}
|
||||
|
||||
if (request->hasParam("useBitcoinNode", true))
|
||||
{
|
||||
AsyncWebParameter *p = request->getParam("useBitcoinNode", true);
|
||||
bool useBitcoinNode = p->value().toInt();
|
||||
preferences.putBool("useNode", useBitcoinNode);
|
||||
settingsChanged = true;
|
||||
|
||||
String rpcVars[] = {"rpcHost", "rpcPort", "rpcUser", "rpcPass"};
|
||||
|
||||
for (String v : rpcVars)
|
||||
{
|
||||
if (request->hasParam(v, true))
|
||||
{
|
||||
AsyncWebParameter *pv = request->getParam(v, true);
|
||||
preferences.putString(v.c_str(), pv->value().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
request->send(200);
|
||||
if (settingsChanged)
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@ void checkBitcoinBlock(void *pvParameters)
|
|||
int blockHeight = preferences.getUInt("blockHeight", currentBlockHeight);
|
||||
HTTPClient http;
|
||||
http.setReuse(true);
|
||||
useBitcoind = wifiClientInsecure.connect(BITCOIND_HOST, BITCOIND_PORT);
|
||||
useBitcoind = wifiClientInsecure.connect(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT));
|
||||
if (useBitcoind)
|
||||
Serial.println("bitcoind node is reachable, using this for blocks.");
|
||||
else
|
||||
|
@ -32,10 +32,10 @@ void checkBitcoinBlock(void *pvParameters)
|
|||
{
|
||||
StaticJsonDocument<200> jsonDoc;
|
||||
|
||||
http.begin(BITCOIND_HOST, BITCOIND_PORT);
|
||||
http.begin(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT));
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
String payload = "{\"jsonrpc\":\"1.0\",\"id\":\"current_block_height\",\"method\":\"getblockcount\",\"params\":[]}";
|
||||
String auth = String(BITCOIND_RPC_USER) + ":" + String(BITCOIND_RPC_PASS);
|
||||
String auth = preferences.getString("rpcUser", BITCOIND_RPC_USER) + ":" + preferences.getString("rpcPass", BITCOIND_RPC_PASS);
|
||||
String authEncoded = base64::encode(auth);
|
||||
http.addHeader("Authorization", "Basic " + authEncoded);
|
||||
|
||||
|
|
|
@ -21,20 +21,21 @@ void taskGetPrice(void *pvParameters)
|
|||
int httpCode = http.GET();
|
||||
|
||||
// Parse JSON response and extract average price
|
||||
float price;
|
||||
float usdPrice, eurPrice;
|
||||
if (httpCode == 200)
|
||||
{
|
||||
String payload = http.getString();
|
||||
//Serial.println(payload);
|
||||
StaticJsonDocument<768> doc;
|
||||
deserializeJson(doc, payload);
|
||||
JsonObject bpi = doc["bpi"];
|
||||
price = bpi["USD"]["rate_float"];
|
||||
usdPrice = bpi["USD"]["rate_float"];
|
||||
eurPrice = bpi["EUR"]["rate_float"];
|
||||
for(auto &callback : priceEventCallbacks) { // Loop through all the event callbacks and call them
|
||||
callback(price);
|
||||
callback(usdPrice);
|
||||
}
|
||||
|
||||
preferences.putFloat("btcPrice", price);
|
||||
preferences.putFloat("btcPrice", usdPrice);
|
||||
preferences.putFloat("btcPriceEur", eurPrice);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -42,7 +43,6 @@ void taskGetPrice(void *pvParameters)
|
|||
Serial.println(httpCode);
|
||||
}
|
||||
|
||||
// Disconnect from Wi-Fi network and wait for 60 seconds
|
||||
http.end();
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(PRICE_WAIT_TIME));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue