Use own data source for price and block data

This commit is contained in:
Djuri Baars 2024-05-09 01:02:40 +02:00
parent efaab00fb4
commit e0283d98ca
6 changed files with 20 additions and 11 deletions

2
data

@ -1 +1 @@
Subproject commit e47fc066b0608132c44a35f7041be80b263adcff
Subproject commit 6ecb4826000e4a34f22d98541d28448f844340f7

View File

@ -87,6 +87,11 @@ void setupBlockNotify()
xQueueSend(workQueue, &blockUpdate, portMAX_DELAY);
}
if (preferences.getBool("ownDataSource", true))
{
return;
}
// std::strcpy(wsServer, String("wss://" + mempoolInstance +
// "/api/v1/ws").c_str());
@ -99,11 +104,11 @@ void setupBlockNotify()
blockNotifyClient = esp_websocket_client_init(&config);
esp_websocket_register_events(blockNotifyClient, WEBSOCKET_EVENT_ANY,
onWebsocketEvent, blockNotifyClient);
onWebsocketBlockEvent, blockNotifyClient);
esp_websocket_client_start(blockNotifyClient);
}
void onWebsocketEvent(void *handler_args, esp_event_base_t base,
void onWebsocketBlockEvent(void *handler_args, esp_event_base_t base,
int32_t event_id, void *event_data)
{
esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
@ -124,7 +129,7 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base,
break;
case WEBSOCKET_EVENT_DATA:
onWebsocketMessage(data);
onWebsocketBlockMessage(data);
break;
case WEBSOCKET_EVENT_ERROR:
Serial.println(F("Mempool.space WS Connnection error"));
@ -135,7 +140,7 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base,
}
}
void onWebsocketMessage(esp_websocket_event_data_t *event_data)
void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data)
{
JsonDocument doc;

View File

@ -17,9 +17,9 @@
void setupBlockNotify();
void onWebsocketEvent(void *handler_args, esp_event_base_t base,
void onWebsocketBlockEvent(void *handler_args, esp_event_base_t base,
int32_t event_id, void *event_data);
void onWebsocketMessage(esp_websocket_event_data_t *event_data);
void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data);
void setBlockHeight(uint newBlockHeight);
uint getBlockHeight();

View File

@ -45,7 +45,7 @@ void setupPriceNotify()
{
// currentPrice = preferences.get("lastPrice", 30000);
if (preferences.getBool("ownPriceSource", true))
if (preferences.getBool("ownDataSource", true))
{
config = {.uri = wsOwnServerPrice,
.user_agent = USER_AGENT};
@ -76,6 +76,10 @@ void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base,
break;
case WEBSOCKET_EVENT_DATA:
onWebsocketPriceMessage(data);
if (preferences.getBool("ownDataSource", true))
{
onWebsocketBlockMessage(data);
}
break;
case WEBSOCKET_EVENT_ERROR:
Serial.println(F("Price WS Connnection error"));

View File

@ -3,7 +3,7 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <esp_websocket_client.h>
#include "block_notify.hpp"
#include <string>
#include "lib/screen_handler.hpp"

View File

@ -329,7 +329,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
String boolSettings[] = {"fetchEurPrice", "ledTestOnPower", "ledFlashOnUpd",
"mdnsEnabled", "otaEnabled", "stealFocus",
"mcapBigChar", "useSatsSymbol", "useBlkCountdown",
"suffixPrice", "disableLeds", "ownPriceSource", "flAlwaysOn"};
"suffixPrice", "disableLeds", "ownDataSource", "flAlwaysOn"};
for (String setting : boolSettings) {
if (settings.containsKey(setting)) {
@ -425,7 +425,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request) {
root["hostname"] = getMyHostname();
root["ip"] = WiFi.localIP();
root["txPower"] = WiFi.getTxPower();
root["ownPriceSource"] = preferences.getBool("ownPriceSource", true);
root["ownDataSource"] = preferences.getBool("ownDataSource", true);
#ifdef HAS_FRONTLIGHT
root["hasFrontlight"] = true;