1. Ensure that recalibration doesn't cause issues with failing to pause watchdog and clear flags
2. Ensure all credentials are purged on device deletion to avoid security issues 3. Clear calibration state (set to false) on device deletion.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#include "bmHTTP.hpp"
|
#include "bmHTTP.hpp"
|
||||||
#include "esp_http_client.h"
|
#include "esp_http_client.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "defines.h"
|
||||||
#define httpSrv "http://192.168.1.190:3000/"
|
#define httpSrv "http://192.168.1.190:3000/"
|
||||||
|
|
||||||
std::string webToken;
|
std::string webToken;
|
||||||
@@ -62,4 +64,28 @@ bool httpGET(std::string endpoint, std::string token, cJSON* &JSONresponse) {
|
|||||||
|
|
||||||
esp_http_client_cleanup(client);
|
esp_http_client_cleanup(client);
|
||||||
return success;
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteWiFiAndTokenDetails() {
|
||||||
|
nvs_handle_t wifiHandle;
|
||||||
|
if (nvs_open(nvsWiFi, NVS_READWRITE, &wifiHandle) == ESP_OK) {
|
||||||
|
if (nvs_erase_all(wifiHandle) == ESP_OK) {
|
||||||
|
printf("Successfully erased WiFi details\n");
|
||||||
|
nvs_commit(wifiHandle);
|
||||||
|
}
|
||||||
|
else printf("ERROR: Erase wifi failed\n");
|
||||||
|
nvs_close(wifiHandle);
|
||||||
|
}
|
||||||
|
else printf("ERROR: Failed to open WiFi section for deletion\n");
|
||||||
|
|
||||||
|
nvs_handle_t authHandle;
|
||||||
|
if (nvs_open(nvsAuth, NVS_READWRITE, &authHandle) == ESP_OK) {
|
||||||
|
if (nvs_erase_all(authHandle) == ESP_OK) {
|
||||||
|
printf("Successfully erased Auth details\n");
|
||||||
|
nvs_commit(authHandle);
|
||||||
|
}
|
||||||
|
else printf("ERROR: Erase auth failed\n");
|
||||||
|
nvs_close(authHandle);
|
||||||
|
}
|
||||||
|
else printf("ERROR: Failed to open Auth section for deletion\n");
|
||||||
}
|
}
|
||||||
@@ -7,4 +7,6 @@ extern std::string webToken;
|
|||||||
|
|
||||||
bool httpGET(std::string endpoint, std::string token, cJSON* &JSONresponse);
|
bool httpGET(std::string endpoint, std::string token, cJSON* &JSONresponse);
|
||||||
|
|
||||||
|
void deleteWiFiAndTokenDetails();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -40,6 +40,7 @@ bool Calibration::clearCalibrated() {
|
|||||||
printf("Error saving calibration status as false.\n");
|
printf("Error saving calibration status as false.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
nvs_commit(calibHandle);
|
||||||
nvs_close(calibHandle);
|
nvs_close(calibHandle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -56,6 +57,7 @@ bool Calibration::beginDownwardCalib(Encoder& topEnc) {
|
|||||||
if (nvs_set_i32(calibHandle, UpTicksTag, tempUpTicks) == ESP_OK) {
|
if (nvs_set_i32(calibHandle, UpTicksTag, tempUpTicks) == ESP_OK) {
|
||||||
printf("Saved UpTicks to NVS\n");
|
printf("Saved UpTicks to NVS\n");
|
||||||
UpTicks = tempUpTicks;
|
UpTicks = tempUpTicks;
|
||||||
|
nvs_commit(calibHandle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("Error saving UpTicks.\n");
|
printf("Error saving UpTicks.\n");
|
||||||
@@ -88,6 +90,7 @@ bool Calibration::completeCalib(Encoder& topEnc) {
|
|||||||
DownTicks = tempDownTicks;
|
DownTicks = tempDownTicks;
|
||||||
calibrated = true;
|
calibrated = true;
|
||||||
printf("Range: %d - %d\n", UpTicks.load(), tempDownTicks);
|
printf("Range: %d - %d\n", UpTicks.load(), tempDownTicks);
|
||||||
|
nvs_commit(calibHandle);
|
||||||
nvs_close(calibHandle);
|
nvs_close(calibHandle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ void Encoder::setupWatchdog() {
|
|||||||
|
|
||||||
void Encoder::pauseWatchdog() {
|
void Encoder::pauseWatchdog() {
|
||||||
feedWDog = false;
|
feedWDog = false;
|
||||||
esp_timer_stop(watchdog_handle);
|
if (watchdog_handle != NULL) esp_timer_stop(watchdog_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
Encoder::~Encoder() {
|
Encoder::~Encoder() {
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ void servoMainSwitch(uint8_t onOff) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool servoInitCalib() {
|
bool servoInitCalib() {
|
||||||
|
topEnc->pauseWatchdog();
|
||||||
|
|
||||||
|
// get ready for calibration by clearing all these listeners
|
||||||
|
bottomEnc->wandListen = false;
|
||||||
|
topEnc->wandListen = false;
|
||||||
|
topEnc->serverListen = false;
|
||||||
if (!calib.clearCalibrated()) return false;
|
if (!calib.clearCalibrated()) return false;
|
||||||
if (topEnc == nullptr || bottomEnc == nullptr) {
|
if (topEnc == nullptr || bottomEnc == nullptr) {
|
||||||
printf("ERROR: CALIBRATION STARTED BEFORE SERVO INITIALIZATION\n");
|
printf("ERROR: CALIBRATION STARTED BEFORE SERVO INITIALIZATION\n");
|
||||||
@@ -138,6 +144,7 @@ void servoSavePos() {
|
|||||||
if (nvs_set_i32(servoHandle, posTag, topCount) != ESP_OK)
|
if (nvs_set_i32(servoHandle, posTag, topCount) != ESP_OK)
|
||||||
printf("Error saving current position\n");
|
printf("Error saving current position\n");
|
||||||
else printf("Success - Current position saved as: %d\n", topCount);
|
else printf("Success - Current position saved as: %d\n", topCount);
|
||||||
|
nvs_commit(servoHandle);
|
||||||
nvs_close(servoHandle);
|
nvs_close(servoHandle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ static void socketio_event_handler(void *handler_args, esp_event_base_t base,
|
|||||||
statusResolved = true;
|
statusResolved = true;
|
||||||
} else {
|
} else {
|
||||||
printf("Device authentication failed\n");
|
printf("Device authentication failed\n");
|
||||||
|
calib.clearCalibrated();
|
||||||
|
deleteWiFiAndTokenDetails();
|
||||||
connected = false;
|
connected = false;
|
||||||
statusResolved = true;
|
statusResolved = true;
|
||||||
}
|
}
|
||||||
@@ -119,6 +121,8 @@ static void socketio_event_handler(void *handler_args, esp_event_base_t base,
|
|||||||
printf("Server message: %s\n", message->valuestring);
|
printf("Server message: %s\n", message->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
calib.clearCalibrated();
|
||||||
|
deleteWiFiAndTokenDetails();
|
||||||
connected = false;
|
connected = false;
|
||||||
statusResolved = true;
|
statusResolved = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user