Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wipe state function and associated request handler #3

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions arduino-bsec-wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ bool loadState(Bsec2 bsec);
*/
bool saveState(Bsec2 bsec);

/**
* @brief : This function wipes the state stored in EEPROM
*/
bool wipeState(void);

/* Create an object of the class Bsec2 */
Bsec2 envSensor;
#ifdef USE_EEPROM
Expand Down Expand Up @@ -889,7 +894,23 @@ bool saveState(Bsec2 bsec)
println("");

EEPROM.write(0, BSEC_MAX_STATE_BLOB_SIZE);
EEPROM.commit();
return EEPROM.commit();
#endif
return true;
}

bool wipeState()
{
#ifdef USE_EEPROM
/* Erase the EEPROM with zeroes */
println("Erasing EEPROM");

for (uint8_t i = 0; i <= BSEC_MAX_STATE_BLOB_SIZE; i++)
{
EEPROM.write(i, 0);
}

return EEPROM.commit();
#endif
return true;
}
Expand Down Expand Up @@ -1013,8 +1034,20 @@ bool processOneRequest(WiFiClient &client){
break;
}
} else if(req.getVerb() == Verb::Post){
println("Updating state from post body");
println("Updating state from post body not yet implemented");
client.println(req.getBody());
} else if(req.getVerb() == Verb::Delete){
println("Wiping state!");
bool wiped = wipeState();
printHead(client, 200, "text/html");
client.println("<!DOCTYPE HTML>");
client.println("<html><head></head><body>");
if(wiped) {
client.println("<p>Wiped state!</p>");
} else {
client.println("<p>Could not wipe state!</p>");
}
client.println("</body></html>");
}
} else if(req.getPath() == "/reset") {
if(req.getVerb() == Verb::Post){
Expand Down
Loading