Skip to content

Commit

Permalink
Handle if spiffs full
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbles07 committed Dec 5, 2024
1 parent 0cec71c commit 6cd5e9f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
17 changes: 16 additions & 1 deletion examples/OneOpenAir/OneOpenAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,8 @@ int calculateMaxPeriod(int updateInterval) {
}

void offlineStorageUpdate() {
measurements.saveLocalStorage(*ag);
if (measurements.saveLocalStorage(*ag)) {
// blue
ag->ledBar.setColor(0, 0, 255, 0);
ag->ledBar.show();
delay(250);
Expand All @@ -1192,4 +1193,18 @@ void offlineStorageUpdate() {
delay(250);
ag->ledBar.setColor(0, 0, 0, 0);
ag->ledBar.show();
} else {
// red
ag->ledBar.setColor(255, 0, 0, 0);
ag->ledBar.show();
delay(250);
ag->ledBar.setColor(0, 0, 0, 0);
ag->ledBar.show();
delay(250);
ag->ledBar.setColor(255, 0, 0, 0);
ag->ledBar.show();
delay(250);
ag->ledBar.setColor(0, 0, 0, 0);
ag->ledBar.show();
}
}
13 changes: 11 additions & 2 deletions src/AgValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,15 @@ bool Measurements::resetLocalStorage() {
return true;
}

void Measurements::saveLocalStorage(AirGradient &ag) {
bool Measurements::saveLocalStorage(AirGradient &ag) {
int spiffUsed = (SPIFFS.usedBytes() / SPIFFS.totalBytes()) / 2;
Serial.printf("%d | %d\n", SPIFFS.totalBytes(), SPIFFS.usedBytes());
Serial.printf("SPIFF used %d%%\n", spiffUsed);
if (spiffUsed > 98) {
Serial.println("SPIFF used already on maximum");
return false;
}

File file;
if (!SPIFFS.exists(FILE_PATH)) {
file = SPIFFS.open(FILE_PATH, FILE_APPEND, true);
Expand All @@ -1089,7 +1097,7 @@ void Measurements::saveLocalStorage(AirGradient &ag) {

if (!file) {
Serial.println("Failed local storage file path");
return;
return false;
}

// Save new measurements
Expand All @@ -1101,6 +1109,7 @@ void Measurements::saveLocalStorage(AirGradient &ag) {
(int)round(_nox.update.avg));

Serial.println("Success save measurements to local storage");
return true;
}

char *Measurements::getLocalStorage() {
Expand Down
2 changes: 1 addition & 1 deletion src/AgValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Measurements {
Configuration &config);

bool resetLocalStorage();
void saveLocalStorage(AirGradient &ag);
bool saveLocalStorage(AirGradient &ag);
char *getLocalStorage();

/**
Expand Down

0 comments on commit 6cd5e9f

Please sign in to comment.