Fix mempool data retrieval, optimize performance

This commit is contained in:
Djuri 2023-11-09 00:15:04 +01:00
parent 42bd78867d
commit 8bad5ebafa
17 changed files with 69 additions and 23585 deletions

View file

@ -37,7 +37,8 @@ void setupBlockNotify()
// std::strcpy(wsServer, String("wss://" + mempoolInstance + "/api/v1/ws").c_str());
esp_websocket_client_config_t config = {
.uri = "wss://mempool.bitcoin.nl/api/v1/ws",
.uri = "wss://mempool.space/api/v1/ws",
.user_agent = USER_AGENT,
};
blockNotifyClient = esp_websocket_client_init(&config);
@ -48,13 +49,14 @@ void setupBlockNotify()
void onWebsocketEvent(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;
const char sub[38] = "{\"action\": \"want\", \"data\":[\"blocks\"]}";
const String sub = "{\"action\": \"want\", \"data\":[\"blocks\"]}";
switch (event_id)
{
case WEBSOCKET_EVENT_CONNECTED:
Serial.println(F("Connected to Mempool.space WebSocket"));
if (esp_websocket_client_send_text(blockNotifyClient, sub, 38, portMAX_DELAY) == -1)
Serial.println(sub);
if (esp_websocket_client_send_text(blockNotifyClient, sub.c_str(), sub.length(), portMAX_DELAY) == -1)
{
Serial.println(F("Mempool.space WS Block Subscribe Error"));
}
@ -85,6 +87,8 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data)
currentBlockHeight = block["height"].as<long>();
Serial.printf("New block found: %d\r\n", block["height"].as<long>());
if (blockUpdateTaskHandle != nullptr) {
xTaskNotifyGive(blockUpdateTaskHandle);
if (preferences.getBool("ledFlashOnUpd", false)) {
@ -93,8 +97,8 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data)
queueLedEffect(LED_FLASH_BLOCK_NOTIFY);
}
}
}
}
doc.clear();
}

View file

@ -105,8 +105,8 @@ void setupWebsocketClients()
void setupTimers()
{
xTaskCreate(setupTimeUpdateTimer, "setupTimeUpdateTimer", 2048, NULL, 1, NULL);
xTaskCreate(setupScreenRotateTimer, "setupScreenRotateTimer", 2048, NULL, 1, NULL);
xTaskCreate(setupTimeUpdateTimer, "setupTimeUpdateTimer", 2048, NULL, tskIDLE_PRIORITY, NULL);
xTaskCreate(setupScreenRotateTimer, "setupScreenRotateTimer", 2048, NULL, tskIDLE_PRIORITY, NULL);
}
void finishSetup()

View file

@ -125,15 +125,6 @@ void taskEpd(void *pvParameters)
}
}
}
#ifdef WITH_RGB_LED
if (updatedThisCycle && preferences.getBool("ledFlashOnUpd", false))
{
xTaskNotifyGive(ledHandlerTaskHandle);
}
#endif
// vTaskDelay(pdMS_TO_TICKS(1000));
}
}
@ -189,29 +180,40 @@ extern "C" void updateDisplay(void *pvParameters) noexcept
{
String top = epdContent[epdIndex].substring(0, epdContent[epdIndex].indexOf("/"));
String bottom = epdContent[epdIndex].substring(epdContent[epdIndex].indexOf("/") + 1);
#ifdef PAGED_WRITE
splitTextPaged(epdIndex, top, bottom, updatePartial);
#else
splitText(epdIndex, top, bottom, updatePartial);
#endif
}
else
{
// displays[epdIndex].drawPaged([&epdIndex, &updatePartial](const void *data)
// { showDigit(epdIndex, epdContent[epdIndex].c_str()[0], updatePartial, &FONT_BIG); },
// 0);
#ifdef PAGED_WRITE
showDigitPaged(epdIndex, epdContent[epdIndex].c_str()[0], updatePartial, &FONT_BIG);
#else
showDigit(epdIndex, epdContent[epdIndex].c_str()[0], updatePartial, &FONT_BIG);
#endif
}
// char tries = 0;
// while (tries < 3)
// {
// if (displays[epdIndex].displayWithReturn(updatePartial))
// {
// displays[epdIndex].hibernate();
#ifdef PAGED_WRITE
currentEpdContent[epdIndex] = epdContent[epdIndex];
// break;
// }
#else
char tries = 0;
while (tries < 3)
{
if (displays[epdIndex].displayWithReturn(updatePartial))
{
displays[epdIndex].hibernate();
break;
}
// vTaskDelay(pdMS_TO_TICKS(100));
// tries++;
// }
vTaskDelay(pdMS_TO_TICKS(100));
tries++;
}
currentEpdContent[epdIndex] = epdContent[epdIndex];
#endif
}
xSemaphoreGive(epdUpdateSemaphore[epdIndex]);
}

View file

@ -3,9 +3,6 @@
TaskHandle_t ledTaskHandle = NULL;
QueueHandle_t ledTaskQueue = NULL;
Adafruit_NeoPixel pixels(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
const TickType_t debounceDelay = pdMS_TO_TICKS(50);
uint32_t notificationValue;
unsigned long ledTaskParams;
void ledTask(void *parameter)
@ -53,6 +50,7 @@ void ledTask(void *parameter)
delay(100);
}
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.show();
delay(900);
@ -61,7 +59,7 @@ void ledTask(void *parameter)
break;
case LED_EFFECT_START_TIMER:
pixels.clear();
pixels.setPixelColor(NEOPIXEL_COUNT, pixels.Color(255, 0, 0));
pixels.setPixelColor((NEOPIXEL_COUNT-1), pixels.Color(255, 0, 0));
pixels.show();
delay(900);
@ -114,7 +112,7 @@ void setupLeds()
void setupLedTask()
{
ledTaskQueue = xQueueCreate(10, sizeof(char));
ledTaskQueue = xQueueCreate(5, sizeof(char));
xTaskCreate(ledTask, "LedTask", 2048, NULL, tskIDLE_PRIORITY, &ledTaskHandle);
}

View file

@ -13,10 +13,6 @@
#define NEOPIXEL_COUNT 4
#endif
typedef struct {
int flashType;
} LedTaskParameters;
const int LED_FLASH_ERROR = 0;
const int LED_FLASH_SUCCESS = 1;
const int LED_FLASH_UPDATE = 2;

View file

@ -10,6 +10,7 @@ void setupPriceNotify()
{
esp_websocket_client_config_t config = {
.uri = wsServerPrice,
.user_agent = USER_AGENT,
};
clientPrice = esp_websocket_client_init(&config);