Skip to content

Commit

Permalink
Add option to factory reset microcontroller (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyservin authored Feb 21, 2022
1 parent d97314b commit dc94f9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ char sensor[8] = "PMS7003";

/* ----------------- Hardware-specific config ---------------------- */
#define ESP_WAKEUP_PIN D0 // To reset ESP8266 after deep sleep
#define ESP_FACTORY_RESET D7 // To factory reset ESP8266
#define PMS_RX_PIN D4 // Rx from PMS (== PMS Tx)
#define PMS_TX_PIN D2 // Tx to PMS (== PMS Rx)
#define PMS_BAUD_RATE 9600 // PMS5003 uses 9600bps
27 changes: 22 additions & 5 deletions linka-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ void setup()
Serial.print("Device ID: ");
Serial.println(g_device_id, HEX);

// Check if we want to factory reset the sensor
check_reset();

// Ignore SSL certificate, required to use SSL without providing the SSL certificate
client.setInsecure();

Expand Down Expand Up @@ -491,8 +494,6 @@ void initWifi()
wc.addParameter(&api_url_param);
wc.addParameter(&ota_server_param);

//wc.resetSettings(); //helper to remove the stored wifi connection, comment out after first upload and re upload

// Check if we need to start captive portal
if (!wc.autoConnect()) {
Serial.println("\tUnable to connect to wifi, starting Configuration portal and checking periodically for wifi");
Expand Down Expand Up @@ -554,9 +555,6 @@ void initWifi()
*/
void initFS(void)
{
//clean FS, for testing
//LittleFS.format();

//read configuration from FS json
Serial.println("Mounting FS...");

Expand Down Expand Up @@ -671,3 +669,22 @@ void handleRemoteOta() {
}
}
}

/*
Check if factory reset was requested
*/
void check_reset()
{
pinMode(ESP_FACTORY_RESET, INPUT_PULLUP);

if ( digitalRead(ESP_FACTORY_RESET) == LOW) {
delay(200); // Wait 200ms and check if button is reset is still attempted
if ( digitalRead(ESP_FACTORY_RESET) == LOW) {
Serial.println("Resetting sensor to factory defaults");
LittleFS.format(); // Format Filesystem
WiFi.persistent(true);
WiFi.begin("0", "0"); // Hack to force wifi to be reset
wc.resetSettings(); // Reset WiFi Settings
}
}
}

0 comments on commit dc94f9d

Please sign in to comment.