forked from btclock/btclock_v3
Missing files in commit
This commit is contained in:
parent
4538326990
commit
687bc1f60d
23 changed files with 1485 additions and 61 deletions
|
@ -7,21 +7,41 @@ unsigned long int currentBlockHeight;
|
|||
|
||||
void setupBlockNotify()
|
||||
{
|
||||
IPAddress result;
|
||||
|
||||
int dnsErr = -1;
|
||||
String mempoolInstance = preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE);
|
||||
|
||||
while (dnsErr != 1) {
|
||||
dnsErr = WiFi.hostByName(mempoolInstance.c_str(), result);
|
||||
|
||||
if (dnsErr != 1) {
|
||||
Serial.print(mempoolInstance);
|
||||
Serial.println("mempool DNS could not be resolved");
|
||||
WiFi.reconnect();
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
Serial.println("mempool DNS can be resolved");
|
||||
|
||||
// Get current block height through regular API
|
||||
HTTPClient *http = new HTTPClient();
|
||||
http->begin("https://mempool.space/api/blocks/tip/height");
|
||||
http->begin("https://" + mempoolInstance + "/api/blocks/tip/height");
|
||||
int httpCode = http->GET();
|
||||
|
||||
if (httpCode > 0 && httpCode == HTTP_CODE_OK)
|
||||
{
|
||||
String blockHeightStr = http->getString();
|
||||
currentBlockHeight = blockHeightStr.toInt();
|
||||
xTaskNotifyGive(blockUpdateTaskHandle);
|
||||
}
|
||||
|
||||
esp_websocket_client_config_t config = {
|
||||
.uri = "wss://mempool.space/api/v1/ws",
|
||||
.uri = "wss://mempool.bitcoin.nl/api/v1/ws",
|
||||
};
|
||||
|
||||
Serial.printf("Connecting to %s\r\n", config.uri);
|
||||
|
||||
client = esp_websocket_client_init(&config);
|
||||
esp_websocket_register_events(client, WEBSOCKET_EVENT_ANY, onWebsocketEvent, client);
|
||||
esp_websocket_client_start(client);
|
||||
|
@ -36,14 +56,11 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base, int32_t event_i
|
|||
{
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
Serial.println("Connected to Mempool.space WebSocket");
|
||||
// init = "{\"action\": \"init\"}";
|
||||
// if(esp_websocket_client_send_text(client, init.c_str(), init.length(), portMAX_DELAY) == -1) {
|
||||
// Serial.println("Error init");
|
||||
// }
|
||||
|
||||
sub = "{\"action\": \"want\", \"data\":[\"blocks\"]}";
|
||||
if (esp_websocket_client_send_text(client, sub.c_str(), sub.length(), portMAX_DELAY) == -1)
|
||||
{
|
||||
Serial.println("Error want");
|
||||
Serial.println("Mempool.space WS Block Subscribe Error");
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -52,17 +69,17 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base, int32_t event_i
|
|||
// Handle the received WebSocket message (block notifications) here
|
||||
break;
|
||||
case WEBSOCKET_EVENT_ERROR:
|
||||
Serial.println("Connnection error");
|
||||
Serial.println("Mempool.space WS Connnection error");
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||
Serial.println("Connnection Closed");
|
||||
Serial.println("Mempool.space WS Connnection Closed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void onWebsocketMessage(esp_websocket_event_data_t *event_data)
|
||||
{
|
||||
DynamicJsonDocument doc(event_data->data_len);
|
||||
SpiRamJsonDocument doc(event_data->data_len);
|
||||
|
||||
deserializeJson(doc, (char *)event_data->data_ptr);
|
||||
// serializeJsonPretty(doc, Serial);
|
||||
|
@ -82,7 +99,6 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data)
|
|||
doc.clear();
|
||||
}
|
||||
|
||||
|
||||
unsigned long getBlockHeight()
|
||||
{
|
||||
return currentBlockHeight;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue