Fix Arduino OTA

This commit is contained in:
Djuri Baars 2024-03-17 00:59:06 +01:00
parent 626877d4ee
commit d46b07399f
4 changed files with 71 additions and 46 deletions

View file

@ -23,7 +23,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: build-outputs
name: prepared-outputs
path: .pio/**/*.bin
build:
@ -44,7 +44,7 @@ jobs:
steps:
- uses: actions/download-artifact@v4
with:
name: build-outputs
name: prepared-outputs
path: .pio
- name: Install esptools.py
run: pip install --upgrade esptool
@ -85,7 +85,7 @@ jobs:
- name: Create release
uses: ncipollo/release-action@v1
with:
artifacts: "*/*.bin,*/*.sha256"
artifacts: "**/*.bin,**/*.sha256"
allowUpdates: true
removeArtifacts: true
makeLatest: true

View file

@ -5,6 +5,7 @@ Preferences preferences;
const char *ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 3600;
TaskHandle_t OTAHandle = NULL;
#define STA_SSID ""
#define STA_PASS ""
@ -201,4 +202,22 @@ void setupOTA()
else if (error == OTA_END_ERROR) Serial.println("End Failed"); });
ArduinoOTA.begin();
}
xTaskCreatePinnedToCore(
OTAUpdateTask, // Task function
"OTAUpdateTask", // Task name
4096, // Stack size
NULL, // Task parameters
1, // Priority (higher value means higher priority)
&OTAHandle, // Task handle
0 // Core to run the task (0 or 1)
);
}
void OTAUpdateTask(void *pvParameters) {
for (;;) {
ArduinoOTA.handle(); // Handle OTA updates
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay to avoid high CPU usage
}
}

View file

@ -15,6 +15,8 @@ void setupTime();
void setupPreferences();
void setupWifi();
void setupOTA();
void OTAUpdateTask(void *pvParameters);
void wakeModemSleep();
void setModemSleep();

View file

@ -23,7 +23,7 @@ GxEPD2_BW<EPD_CLASS, EPD_CLASS::HEIGHT> display = EPD_CLASS(5, 3, 2, 1);
typedef void (*MethodPtr)(String);
MethodPtr methods[] = { nullptr, updateRow1, updateRow2, updateRow3 };
MethodPtr methods[] = {nullptr, updateRow1, updateRow2, updateRow3};
WiFiClientSecure client;
uint currentPrice = 0;
@ -45,7 +45,7 @@ void setup()
setupWifi();
setupTime();
if (!inPowerSaveMode())
if (!inPowerSaveMode())
{
setupWebserver();
setupOTA();
@ -57,8 +57,8 @@ void setup()
void loop()
{
ArduinoOTA.handle();
if (isUpdating) {
if (isUpdating)
{
return;
}
@ -93,47 +93,48 @@ void loop()
}
}
for (uint i = 1; i <= 3; i++) {
for (uint i = 1; i <= 3; i++)
{
String rowContent = "";
char keyName[5];
snprintf(keyName, sizeof(keyName), "row%d", i);
Serial.print(keyName);
Serial.print(" ");
Serial.println(preferences.getUInt(keyName));
switch (preferences.getUInt(keyName)) {
case LINE_BLOCKHEIGHT:
rowContent = getBlock();
break;
case LINE_MEMPOOL_FEES:
rowContent = getMempoolFees();
break;
case LINE_MEMPOOL_FEES_MEDIAN:
rowContent = "NOT IMPL";
break;
case LINE_HALVING_COUNTDOWN:
rowContent = "NOT IMPL";
break;
case LINE_SATSPERUNIT: {
uint satsPerDollar = int(round(1 / float(getPrice()) * 10e7));
rowContent = satsPerDollar;
break;
}
case LINE_FIATPRICE:
rowContent = getPrice();
break;
case LINE_MARKETCAP:
rowContent = "NOT IMPL";
break;
case LINE_TIME:
rowContent = "NOT IMPL";
break;
case LINE_DATE:
rowContent = "NOT IMPL";
break;
default:
rowContent = "DEFAULT";
switch (preferences.getUInt(keyName))
{
case LINE_BLOCKHEIGHT:
rowContent = getBlock();
break;
case LINE_MEMPOOL_FEES:
rowContent = getMempoolFees();
break;
case LINE_MEMPOOL_FEES_MEDIAN:
rowContent = "NOT IMPL";
break;
case LINE_HALVING_COUNTDOWN:
rowContent = "NOT IMPL";
break;
case LINE_SATSPERUNIT:
{
uint satsPerDollar = int(round(1 / float(getPrice()) * 10e7));
rowContent = satsPerDollar;
break;
}
case LINE_FIATPRICE:
rowContent = getPrice();
break;
case LINE_MARKETCAP:
rowContent = "NOT IMPL";
break;
case LINE_TIME:
rowContent = "NOT IMPL";
break;
case LINE_DATE:
rowContent = "NOT IMPL";
break;
default:
rowContent = "DEFAULT";
}
methods[i](rowContent);
@ -231,17 +232,20 @@ void loop()
delay(2 * 1000);
if (inPowerSaveMode()) {
if (inPowerSaveMode())
{
display.hibernate();
setModemSleep();
esp_sleep_enable_timer_wakeup(50 * 1000000);
esp_light_sleep_start();
display.init(0, false);
wakeModemSleep();
} else {
}
else
{
Serial.println(F("Sleeping"));
sleep(50);
// delay(50 * 1000);
// delay(50 * 1000);
Serial.println(F("Waking up"));
}
}