Why my preferences giving me the wrong value after resetting it

I'm using ESP32 WIFI MODULE. My problem is that once when I've saved wifi credentials using preferences. Now what i want to do is when i press a reset button( which is push button in my case) all the wifi credentials should be erased but i dont why my preferences is showing me wrong value it is not erasing the value. I am using attchInterrput for push button(reset button).. Here is my code may this will give a more clearance...

#include <WiFi.h>
#include <WiFiManager.h>
#include <preferences.h>

#define buttonPin 32  //Reset button

bool configure = 0;

Preferences pref;
WiFiManager wifiManager;


void YFC_READ(){ // This is reading and updating the value of configure variable
  pref.begin("configure ", false);
  configure = pref.getBool("configure ", configure );
  pref.end();
}

void setup() 
{
  Serial.begin(115200);
  dht.begin(); 
  if (! rtc.begin()) 
  {
   Serial.println("Couldn't find RTC");
   abort();
  }    

  pinMode(dhtpin, INPUT);
 
  pinMode(LATCH, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(DATA, OUTPUT);
  pinMode(dig1, OUTPUT);
  pinMode(dig2, OUTPUT);
  pinMode(dig3, OUTPUT);
  pinMode(dig4, OUTPUT);
  pinMode(dp1, OUTPUT);
  pinMode(25,INPUT_PULLUP);
  pinMode(32,INPUT_PULLUP); // This one is the reset button and below is its interupt code
  digitalWrite(33, HIGH);
  
  digitalWrite(dig1, HIGH);
  digitalWrite(dig2, HIGH);
  digitalWrite(dig3, HIGH);
  digitalWrite(dig4, HIGH);

  attachInterrupt(buttonPin, freshMode, FALLING); // interrupt to reset button(push button)

  YFC_READ(); //This is reading the configure variable
  NVS_READ(); //This is for other variables
  initWiFi(); //simple method to print something of 7 segment led
  delay(1000);
  YFSE(); //simple method to print something of 7 segment led
  delay(3000);

  if(configure == 0){ // here for the first time i have to configure the wifi as configure variable is 0
    //exit after config instead of connecting
    wifiManager.setConfigPortalTimeout(45);
    while(WiFi.status() != WL_CONNECTED ){
      YFCND();
      wifiManager.autoConnect("WIFI_CLOCK");
    }
    if(WiFi.status() == WL_CONNECTED){
      YFCD(); //simple method to print something of 7 segment led
      delay(1500);
      timeClient.begin();
      timeClient.update();
      rtc.adjust(timeClient.getEpochTime());
      delay(500);
      configure = 1;
// here i'm updating the configure var so that next time i dont have to configure wifi again
      pref.begin("configure");
      pref.putBool("configure", configure); 
      pref.end();
      delay(500);
    }else{
      YFNC();delay(1500); //simple methods to print something on 7 segment
      IRTC();delay(1500);


    }
  }else if(configure == 1){ // here this will tell me to not to configure wifi again as configure = 1
    if(!wifiManager.autoConnect("WIFI_CLOCK") && (millis() - startTime <= 5000)){
      Serial.println("My confi is done, I'm waiting for WiFi..");
    }
    if(WiFi.status() == WL_CONNECTED){
      YFSC();delay(700);
      timeClient.begin();
      timeClient.update();
      rtc.adjust(timeClient.getEpochTime());
      delay(500);
    }else if(WiFi.status() != WL_CONNECTED){
      YFNC();
      delay(1500);
      IRTC();
      delay(1500);
      delay(1000);
    }
  }  
}

Here what i want is when I configure wifi on esp32 first time it will update the variable configure = 1, and store the result in preferences and when i press reset button it will erase the variables value and let me configure the wifi again.. but after pressing reset button I'm getting the variable value as 1 :frowning: please help

Thanksing you..

Your code does not compile.
preferences.h with lowercase P;
No library for DTH .... dht.begin();
No library for RTC .... rtc.begin()

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.