Compare commits
4 commits
feature/mi
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
957a947bc5 | ||
|
c44626cb42 | ||
|
4fdd6b6b4f | ||
|
8a818c66a0 |
9 changed files with 190 additions and 208 deletions
12
README.md
12
README.md
|
@ -16,21 +16,21 @@ Biggest differences with v2 are:
|
||||||
|
|
||||||
New features:
|
New features:
|
||||||
- BitAxe integration
|
- BitAxe integration
|
||||||
- Zap notifier
|
- Nostr Zap notifier
|
||||||
- Braiins Pool and Ocean mining stats integration
|
- Multiple mining pool stats integrations
|
||||||
|
|
||||||
"Steal focus on new block" means that when a new block is mined, the display will switch to the block height screen if it's not on it already.
|
"Steal focus on new block" means that when a new block is mined, the display will switch to the block height screen if it's not on it already.
|
||||||
|
|
||||||
Most [information](https://github.com/btclock/btclock_v2/wiki) about BTClock v2 is still valid for this version.
|
See the [docs](https://git.btclock.dev/btclock/docs) repo for more information and building instructions.
|
||||||
|
|
||||||
**NOTE**: The software assumes that the hardware is run in a controlled private network. ~~The Web UI and the OTA update mechanism are not password protected and accessible to anyone in the network. Also, since the device only fetches numbers through WebSockets it will skip server certificate verification to save resources.~~ Since 3.2.0 the WebUI is password protectable and all certificates are verified. OTA update mechanism is not password-protected.
|
**NOTE**: The software assumes that the hardware is run in a controlled private network. ~~The Web UI and the OTA update mechanism are not password protected and accessible to anyone in the network. Also, since the device only fetches numbers through WebSockets it will skip server certificate verification to save resources.~~ Since 3.2.0 the WebUI is password protectable and all certificates are verified. OTA update mechanism is not password-protected.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Use PlatformIO to build it yourself. Make sure you fetch the [WebUI](https://github.com/btclock/webui) submodule.
|
Use PlatformIO to build it yourself. Make sure you fetch the [WebUI](https://git.btclock.dev/btclock/webui) submodule.
|
||||||
|
|
||||||
|
|
||||||
## Braiins Pool and Ocean integration
|
## Mining pool stats
|
||||||
Enable mining pool stats by accessing your btclock's web UI (point a web browser at the device's IP address).
|
Enable mining pool stats by accessing your btclock's web UI (point a web browser at the device's IP address).
|
||||||
|
|
||||||
Under Settings -> Extra Features: toggle Enable Mining Pool Stats.
|
Under Settings -> Extra Features: toggle Enable Mining Pool Stats.
|
||||||
|
@ -41,6 +41,8 @@ The Mining Pool Earnings screen displays:
|
||||||
* Braiins: Today's mining reward thus far
|
* Braiins: Today's mining reward thus far
|
||||||
* Ocean: Your estimated earnings if the pool were to find a block right now
|
* Ocean: Your estimated earnings if the pool were to find a block right now
|
||||||
|
|
||||||
|
For solo mining pools, there are no earning estimations. Your username is the onchain withdrawal address, without the worker name.
|
||||||
|
|
||||||
|
|
||||||
### Braiins Pool integration
|
### Braiins Pool integration
|
||||||
Create an API key based on the steps [here](https://academy.braiins.com/en/braiins-pool/monitoring/#api-configuration).
|
Create an API key based on the steps [here](https://academy.braiins.com/en/braiins-pool/monitoring/#api-configuration).
|
||||||
|
|
|
@ -54,7 +54,7 @@ void taskBitaxeFetch(void *pvParameters)
|
||||||
|
|
||||||
void setupBitaxeFetchTask()
|
void setupBitaxeFetchTask()
|
||||||
{
|
{
|
||||||
xTaskCreate(taskBitaxeFetch, "bitaxeFetch", (6 * 1024), NULL, tskIDLE_PRIORITY,
|
xTaskCreate(taskBitaxeFetch, "bitaxeFetch", (3 * 1024), NULL, tskIDLE_PRIORITY,
|
||||||
&bitaxeFetchTaskHandle);
|
&bitaxeFetchTaskHandle);
|
||||||
|
|
||||||
xTaskNotifyGive(bitaxeFetchTaskHandle);
|
xTaskNotifyGive(bitaxeFetchTaskHandle);
|
||||||
|
|
|
@ -19,41 +19,52 @@ TickType_t lastDebounceTime = 0;
|
||||||
void buttonTask(void *parameter) {
|
void buttonTask(void *parameter) {
|
||||||
while (1) {
|
while (1) {
|
||||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||||
std::lock_guard<std::mutex> lock(mcpMutex);
|
|
||||||
|
|
||||||
TickType_t currentTime = xTaskGetTickCount();
|
TickType_t currentTime = xTaskGetTickCount();
|
||||||
|
|
||||||
if ((currentTime - lastDebounceTime) >= debounceDelay) {
|
if ((currentTime - lastDebounceTime) >= debounceDelay) {
|
||||||
lastDebounceTime = currentTime;
|
lastDebounceTime = currentTime;
|
||||||
|
|
||||||
if (!digitalRead(MCP_INT_PIN)) {
|
std::lock_guard<std::mutex> lock(mcpMutex);
|
||||||
uint pin = mcp1.getInterruptFlagRegister();
|
|
||||||
|
|
||||||
switch (pin) {
|
if (!digitalRead(MCP_INT_PIN)) {
|
||||||
case BTN_1:
|
uint16_t intFlags = mcp1.getInterruptFlagRegister();
|
||||||
toggleTimerActive();
|
uint16_t intCap = mcp1.getInterruptCaptureRegister();
|
||||||
break;
|
|
||||||
case BTN_2:
|
// Check each button individually
|
||||||
nextScreen();
|
if (intFlags & BTN_1) handleButton1();
|
||||||
break;
|
if (intFlags & BTN_2) handleButton2();
|
||||||
case BTN_3:
|
if (intFlags & BTN_3) handleButton3();
|
||||||
previousScreen();
|
if (intFlags & BTN_4) handleButton4();
|
||||||
break;
|
|
||||||
case BTN_4:
|
|
||||||
showSystemStatusScreen();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mcp1.getInterruptCaptureRegister();
|
|
||||||
} else {
|
// Clear interrupt state
|
||||||
}
|
|
||||||
// Very ugly, but for some reason this is necessary
|
|
||||||
while (!digitalRead(MCP_INT_PIN)) {
|
while (!digitalRead(MCP_INT_PIN)) {
|
||||||
|
std::lock_guard<std::mutex> lock(mcpMutex);
|
||||||
mcp1.getInterruptCaptureRegister();
|
mcp1.getInterruptCaptureRegister();
|
||||||
|
delay(1); // Small delay to prevent tight loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper functions to handle each button
|
||||||
|
void handleButton1() {
|
||||||
|
toggleTimerActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleButton2() {
|
||||||
|
nextScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleButton3() {
|
||||||
|
previousScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleButton4() {
|
||||||
|
showSystemStatusScreen();
|
||||||
|
}
|
||||||
|
|
||||||
void IRAM_ATTR handleButtonInterrupt() {
|
void IRAM_ATTR handleButtonInterrupt() {
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
xTaskNotifyFromISR(buttonTaskHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
|
xTaskNotifyFromISR(buttonTaskHandle, 0, eNoAction, &xHigherPriorityTaskWoken);
|
||||||
|
|
|
@ -8,6 +8,13 @@
|
||||||
|
|
||||||
extern TaskHandle_t buttonTaskHandle;
|
extern TaskHandle_t buttonTaskHandle;
|
||||||
|
|
||||||
|
// Task and setup functions
|
||||||
void buttonTask(void *pvParameters);
|
void buttonTask(void *pvParameters);
|
||||||
void IRAM_ATTR handleButtonInterrupt();
|
void IRAM_ATTR handleButtonInterrupt();
|
||||||
void setupButtonTask();
|
void setupButtonTask();
|
||||||
|
|
||||||
|
// Individual button handlers
|
||||||
|
void handleButton1();
|
||||||
|
void handleButton2();
|
||||||
|
void handleButton3();
|
||||||
|
void handleButton4();
|
||||||
|
|
|
@ -466,32 +466,34 @@ void setupHardware()
|
||||||
|
|
||||||
Wire.begin(I2C_SDA_PIN, I2C_SCK_PIN, 400000);
|
Wire.begin(I2C_SDA_PIN, I2C_SCK_PIN, 400000);
|
||||||
|
|
||||||
if (!mcp1.begin())
|
if (!mcp1.begin()) {
|
||||||
{
|
|
||||||
Serial.println(F("Error MCP23017 1"));
|
Serial.println(F("Error MCP23017 1"));
|
||||||
|
} else {
|
||||||
// while (1)
|
|
||||||
// ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pinMode(MCP_INT_PIN, INPUT_PULLUP);
|
pinMode(MCP_INT_PIN, INPUT_PULLUP);
|
||||||
// mcp1.setupInterrupts(false, false, LOW);
|
|
||||||
mcp1.enableControlRegister(MCP23x17_IOCR_ODR);
|
|
||||||
|
|
||||||
mcp1.mirrorInterrupts(true);
|
// Enable mirrored interrupts (both INTA and INTB pins signal any interrupt)
|
||||||
|
if (!mcp1.mirrorInterrupts(true)) {
|
||||||
|
Serial.println(F("Error setting up mirrored interrupts"));
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
// Configure all 4 button pins as inputs with pullups and interrupts
|
||||||
{
|
for (int i = 0; i < 4; i++) {
|
||||||
mcp1.pinMode1(i, INPUT_PULLUP);
|
if (!mcp1.pinMode1(i, INPUT_PULLUP)) {
|
||||||
mcp1.enableInterrupt(i, LOW);
|
Serial.printf("Error setting pin %d to input pull up\n", i);
|
||||||
}
|
}
|
||||||
#ifndef IS_BTCLOCK_V8
|
// Enable interrupt on CHANGE for each pin
|
||||||
for (int i = 8; i <= 14; i++)
|
if (!mcp1.enableInterrupt(i, CHANGE)) {
|
||||||
{
|
Serial.printf("Error enabling interrupt for pin %d\n", i);
|
||||||
mcp1.pinMode1(i, OUTPUT);
|
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
// Set interrupt pins as open drain with active-low polarity
|
||||||
|
if (!mcp1.setInterruptPolarity(2)) { // 2 = Open drain
|
||||||
|
Serial.println(F("Error setting interrupt polarity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear any pending interrupts
|
||||||
|
mcp1.getInterruptCaptureRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IS_HW_REV_B
|
#ifdef IS_HW_REV_B
|
||||||
|
|
|
@ -149,25 +149,6 @@ void forceFullRefresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshFromMemory()
|
|
||||||
{
|
|
||||||
for (uint i = 0; i < NUM_SCREENS; i++)
|
|
||||||
{
|
|
||||||
int *taskParam = new int;
|
|
||||||
*taskParam = i;
|
|
||||||
|
|
||||||
xTaskCreate(
|
|
||||||
[](void *pvParameters)
|
|
||||||
{
|
|
||||||
const int epdIndex = *(int *)pvParameters;
|
|
||||||
delete (int *)pvParameters;
|
|
||||||
displays[epdIndex].refresh(false);
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
},
|
|
||||||
"PrepareUpd", 4096, taskParam, tskIDLE_PRIORITY, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupDisplays()
|
void setupDisplays()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lockMcp(mcpMutex);
|
std::lock_guard<std::mutex> lockMcp(mcpMutex);
|
||||||
|
|
|
@ -26,7 +26,6 @@ typedef struct {
|
||||||
} UpdateDisplayTaskItem;
|
} UpdateDisplayTaskItem;
|
||||||
|
|
||||||
void forceFullRefresh();
|
void forceFullRefresh();
|
||||||
void refreshFromMemory();
|
|
||||||
void setupDisplays();
|
void setupDisplays();
|
||||||
|
|
||||||
void splitText(const uint dispNum, const String &top, const String &bottom,
|
void splitText(const uint dispNum, const String &top, const String &bottom,
|
||||||
|
|
|
@ -93,7 +93,7 @@ void setupMiningPoolStatsFetchTask()
|
||||||
"logoDownload",
|
"logoDownload",
|
||||||
(6 * 1024),
|
(6 * 1024),
|
||||||
NULL,
|
NULL,
|
||||||
12,
|
tskIDLE_PRIORITY,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
xTaskCreate(taskMiningPoolStatsFetch,
|
xTaskCreate(taskMiningPoolStatsFetch,
|
||||||
|
|
206
src/main.cpp
206
src/main.cpp
|
@ -22,152 +22,132 @@
|
||||||
uint wifiLostConnection;
|
uint wifiLostConnection;
|
||||||
uint priceNotifyLostConnection = 0;
|
uint priceNotifyLostConnection = 0;
|
||||||
uint blockNotifyLostConnection = 0;
|
uint blockNotifyLostConnection = 0;
|
||||||
// char ptrTaskList[1500];
|
|
||||||
|
|
||||||
extern "C" void app_main()
|
int64_t getUptime() {
|
||||||
{
|
return esp_timer_get_time() / 1000000;
|
||||||
initArduino();
|
}
|
||||||
|
|
||||||
Serial.begin(115200);
|
void handlePriceNotifyDisconnection() {
|
||||||
setup();
|
if (priceNotifyLostConnection == 0) {
|
||||||
|
priceNotifyLostConnection = getUptime();
|
||||||
|
Serial.println(F("Lost price notification connection, trying to reconnect..."));
|
||||||
|
}
|
||||||
|
|
||||||
while (true)
|
if ((getUptime() - priceNotifyLostConnection) > 300) { // 5 minutes timeout
|
||||||
{
|
Serial.println(F("Price notification connection lost for 5 minutes, restarting handler..."));
|
||||||
// vTaskList(ptrTaskList);
|
restartPriceNotify();
|
||||||
// Serial.println(F("**********************************"));
|
priceNotifyLostConnection = 0;
|
||||||
// Serial.println(F("Task State Prio Stack Num"));
|
}
|
||||||
// Serial.println(F("**********************************"));
|
}
|
||||||
// Serial.print(ptrTaskList);
|
|
||||||
// Serial.println(F("**********************************"));
|
|
||||||
if (eventSourceTaskHandle != NULL)
|
|
||||||
xTaskNotifyGive(eventSourceTaskHandle);
|
|
||||||
|
|
||||||
int64_t currentUptime = esp_timer_get_time() / 1000000;
|
void handleBlockNotifyDisconnection() {
|
||||||
;
|
if (blockNotifyLostConnection == 0) {
|
||||||
|
blockNotifyLostConnection = getUptime();
|
||||||
|
Serial.println(F("Lost block notification connection, trying to reconnect..."));
|
||||||
|
}
|
||||||
|
|
||||||
if (!getIsOTAUpdating())
|
if ((getUptime() - blockNotifyLostConnection) > 300) { // 5 minutes timeout
|
||||||
{
|
Serial.println(F("Block notification connection lost for 5 minutes, restarting handler..."));
|
||||||
|
restartBlockNotify();
|
||||||
|
blockNotifyLostConnection = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleFrontlight() {
|
||||||
#ifdef HAS_FRONTLIGHT
|
#ifdef HAS_FRONTLIGHT
|
||||||
if (hasLightLevel()) {
|
if (hasLightLevel() && preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE) != 0) {
|
||||||
if (preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE) != 0)
|
uint lightLevel = getLightLevel();
|
||||||
{
|
uint luxThreshold = preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE);
|
||||||
if (hasLightLevel() && getLightLevel() <= 1 && preferences.getBool("flOffWhenDark", DEFAULT_FL_OFF_WHEN_DARK))
|
|
||||||
{
|
if (lightLevel <= 1 && preferences.getBool("flOffWhenDark", DEFAULT_FL_OFF_WHEN_DARK)) {
|
||||||
if (frontlightIsOn()) {
|
if (frontlightIsOn()) frontlightFadeOutAll();
|
||||||
frontlightFadeOutAll();
|
} else if (lightLevel < luxThreshold && !frontlightIsOn()) {
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (hasLightLevel() && getLightLevel() < preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE) && !frontlightIsOn())
|
|
||||||
{
|
|
||||||
frontlightFadeInAll();
|
frontlightFadeInAll();
|
||||||
}
|
} else if (frontlightIsOn() && lightLevel > luxThreshold) {
|
||||||
else if (frontlightIsOn() && getLightLevel() > preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE))
|
|
||||||
{
|
|
||||||
frontlightFadeOutAll();
|
frontlightFadeOutAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!WiFi.isConnected())
|
|
||||||
{
|
|
||||||
if (!wifiLostConnection)
|
|
||||||
{
|
|
||||||
wifiLostConnection = currentUptime;
|
|
||||||
Serial.println(F("Lost WiFi connection, trying to reconnect..."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((currentUptime - wifiLostConnection) > 600)
|
void checkWiFiConnection() {
|
||||||
{
|
if (!WiFi.isConnected()) {
|
||||||
|
if (!wifiLostConnection) {
|
||||||
|
wifiLostConnection = getUptime();
|
||||||
|
Serial.println(F("Lost WiFi connection, trying to reconnect..."));
|
||||||
|
}
|
||||||
|
if ((getUptime() - wifiLostConnection) > 600) {
|
||||||
Serial.println(F("Still no connection after 10 minutes, restarting..."));
|
Serial.println(F("Still no connection after 10 minutes, restarting..."));
|
||||||
delay(2000);
|
delay(2000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFi.begin();
|
WiFi.begin();
|
||||||
}
|
} else if (wifiLostConnection) {
|
||||||
else if (wifiLostConnection)
|
|
||||||
{
|
|
||||||
wifiLostConnection = 0;
|
wifiLostConnection = 0;
|
||||||
Serial.println(F("Connection restored, reset timer."));
|
Serial.println(F("Connection restored, reset timer."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPriceNotifyInit() && !preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE) && !isPriceNotifyConnected())
|
|
||||||
{
|
|
||||||
priceNotifyLostConnection++;
|
|
||||||
Serial.println(F("Lost price data connection..."));
|
|
||||||
queueLedEffect(LED_DATA_PRICE_ERROR);
|
|
||||||
|
|
||||||
// if price WS connection does not come back after 6*5 seconds, destroy and recreate
|
|
||||||
if (priceNotifyLostConnection > 6)
|
|
||||||
{
|
|
||||||
Serial.println(F("Restarting price handler..."));
|
|
||||||
|
|
||||||
restartPriceNotify();
|
|
||||||
// setupPriceNotify();
|
|
||||||
priceNotifyLostConnection = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (priceNotifyLostConnection > 0 && isPriceNotifyConnected())
|
|
||||||
{
|
|
||||||
priceNotifyLostConnection = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getBlockNotifyInit() && !isBlockNotifyConnected())
|
void checkMissedBlocks() {
|
||||||
{
|
|
||||||
blockNotifyLostConnection++;
|
|
||||||
Serial.println(F("Lost block data connection..."));
|
|
||||||
queueLedEffect(LED_DATA_BLOCK_ERROR);
|
|
||||||
// if mempool WS connection does not come back after 6*5 seconds, destroy and recreate
|
|
||||||
if (blockNotifyLostConnection > 6)
|
|
||||||
{
|
|
||||||
Serial.println(F("Restarting block handler..."));
|
|
||||||
|
|
||||||
restartBlockNotify();
|
|
||||||
// setupBlockNotify();
|
|
||||||
blockNotifyLostConnection = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (blockNotifyLostConnection > 0 && isBlockNotifyConnected())
|
|
||||||
{
|
|
||||||
blockNotifyLostConnection = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if more than 5 price updates are missed, there is probably something wrong, reconnect
|
|
||||||
if ((getLastPriceUpdate(CURRENCY_USD) - currentUptime) > (preferences.getUInt("minSecPriceUpd", DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE) * 5))
|
|
||||||
{
|
|
||||||
Serial.println(F("Detected 5 missed price updates... restarting price handler."));
|
|
||||||
|
|
||||||
restartPriceNotify();
|
|
||||||
// setupPriceNotify();
|
|
||||||
|
|
||||||
priceNotifyLostConnection = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If after 45 minutes no mempool blocks, check the rest API
|
|
||||||
if ((getLastBlockUpdate() - currentUptime) > 45 * 60)
|
|
||||||
{
|
|
||||||
Serial.println(F("Long time (45 min) since last block, checking if I missed anything..."));
|
Serial.println(F("Long time (45 min) since last block, checking if I missed anything..."));
|
||||||
int currentBlock = getBlockFetch();
|
int currentBlock = getBlockFetch();
|
||||||
if (currentBlock != -1)
|
if (currentBlock != -1) {
|
||||||
{
|
if (currentBlock != getBlockHeight()) {
|
||||||
if (currentBlock != getBlockHeight())
|
|
||||||
{
|
|
||||||
Serial.println(F("Detected stuck block height... restarting block handler."));
|
Serial.println(F("Detected stuck block height... restarting block handler."));
|
||||||
// Mempool source stuck, restart
|
|
||||||
restartBlockNotify();
|
restartBlockNotify();
|
||||||
// setupBlockNotify();
|
|
||||||
}
|
}
|
||||||
// set last block update so it doesn't fetch for 45 minutes
|
setLastBlockUpdate(getUptime());
|
||||||
setLastBlockUpdate(currentUptime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUptime - getLastTimeSync() > 24 * 60 * 60)
|
|
||||||
{
|
void monitorDataConnections() {
|
||||||
|
// Price notification monitoring
|
||||||
|
if (getPriceNotifyInit() && !preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE) && !isPriceNotifyConnected()) {
|
||||||
|
handlePriceNotifyDisconnection();
|
||||||
|
} else if (priceNotifyLostConnection > 0 && isPriceNotifyConnected()) {
|
||||||
|
priceNotifyLostConnection = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block notification monitoring
|
||||||
|
if (getBlockNotifyInit() && !isBlockNotifyConnected()) {
|
||||||
|
handleBlockNotifyDisconnection();
|
||||||
|
} else if (blockNotifyLostConnection > 0 && isBlockNotifyConnected()) {
|
||||||
|
blockNotifyLostConnection = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for missed price updates
|
||||||
|
if ((getLastPriceUpdate(CURRENCY_USD) - getUptime()) > (preferences.getUInt("minSecPriceUpd", DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE) * 5)) {
|
||||||
|
Serial.println(F("Detected 5 missed price updates... restarting price handler."));
|
||||||
|
restartPriceNotify();
|
||||||
|
priceNotifyLostConnection = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for missed blocks
|
||||||
|
if ((getLastBlockUpdate() - getUptime()) > 45 * 60) {
|
||||||
|
checkMissedBlocks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void app_main() {
|
||||||
|
initArduino();
|
||||||
|
Serial.begin(115200);
|
||||||
|
setup();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (eventSourceTaskHandle != NULL) {
|
||||||
|
xTaskNotifyGive(eventSourceTaskHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getIsOTAUpdating()) {
|
||||||
|
handleFrontlight();
|
||||||
|
checkWiFiConnection();
|
||||||
|
monitorDataConnections();
|
||||||
|
|
||||||
|
if (getUptime() - getLastTimeSync() > 24 * 60 * 60) {
|
||||||
Serial.println(F("Last time update is longer than 24 hours ago, sync again"));
|
Serial.println(F("Last time update is longer than 24 hours ago, sync again"));
|
||||||
syncTime();
|
syncTime();
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
|
|
Loading…
Reference in a new issue