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

View file

@ -5,6 +5,7 @@ Preferences preferences;
const char *ntpServer = "pool.ntp.org"; const char *ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0; const long gmtOffset_sec = 0;
const int daylightOffset_sec = 3600; const int daylightOffset_sec = 3600;
TaskHandle_t OTAHandle = NULL;
#define STA_SSID "" #define STA_SSID ""
#define STA_PASS "" #define STA_PASS ""
@ -201,4 +202,22 @@ void setupOTA()
else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); else if (error == OTA_END_ERROR) Serial.println("End Failed"); });
ArduinoOTA.begin(); 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 setupPreferences();
void setupWifi(); void setupWifi();
void setupOTA(); void setupOTA();
void OTAUpdateTask(void *pvParameters);
void wakeModemSleep(); void wakeModemSleep();
void setModemSleep(); void setModemSleep();

View file

@ -57,8 +57,8 @@ void setup()
void loop() void loop()
{ {
ArduinoOTA.handle(); if (isUpdating)
if (isUpdating) { {
return; return;
} }
@ -93,16 +93,16 @@ void loop()
} }
} }
for (uint i = 1; i <= 3; i++)
{
for (uint i = 1; i <= 3; i++) {
String rowContent = ""; String rowContent = "";
char keyName[5]; char keyName[5];
snprintf(keyName, sizeof(keyName), "row%d", i); snprintf(keyName, sizeof(keyName), "row%d", i);
Serial.print(keyName); Serial.print(keyName);
Serial.print(" "); Serial.print(" ");
Serial.println(preferences.getUInt(keyName)); Serial.println(preferences.getUInt(keyName));
switch (preferences.getUInt(keyName)) { switch (preferences.getUInt(keyName))
{
case LINE_BLOCKHEIGHT: case LINE_BLOCKHEIGHT:
rowContent = getBlock(); rowContent = getBlock();
break; break;
@ -115,7 +115,8 @@ void loop()
case LINE_HALVING_COUNTDOWN: case LINE_HALVING_COUNTDOWN:
rowContent = "NOT IMPL"; rowContent = "NOT IMPL";
break; break;
case LINE_SATSPERUNIT: { case LINE_SATSPERUNIT:
{
uint satsPerDollar = int(round(1 / float(getPrice()) * 10e7)); uint satsPerDollar = int(round(1 / float(getPrice()) * 10e7));
rowContent = satsPerDollar; rowContent = satsPerDollar;
break; break;
@ -231,14 +232,17 @@ void loop()
delay(2 * 1000); delay(2 * 1000);
if (inPowerSaveMode()) { if (inPowerSaveMode())
{
display.hibernate(); display.hibernate();
setModemSleep(); setModemSleep();
esp_sleep_enable_timer_wakeup(50 * 1000000); esp_sleep_enable_timer_wakeup(50 * 1000000);
esp_light_sleep_start(); esp_light_sleep_start();
display.init(0, false); display.init(0, false);
wakeModemSleep(); wakeModemSleep();
} else { }
else
{
Serial.println(F("Sleeping")); Serial.println(F("Sleeping"));
sleep(50); sleep(50);
// delay(50 * 1000); // delay(50 * 1000);