Is E (134794) wifi:sta is connecting normal on serial monitor after disconnect to connect again?

hello i am working on esp32 wifi with one push button to turn off and turn on and i finished working on it but i have a little problem when i reconnect. when program starts, wifi turns on without pressing the push button then on the serial monitor appears Connected: 192.168.100.91 after that i click again the push button then the wifi is in a off condition Disconnected. My IP address is: 0.0.0.0 and when I turn it back on, here the root of the problem appears on the serial monitor E (134794) wifi:sta is connecting and its back to connected again. is that normal? or errors? If it's an error, what code should I use, please help, thanks in advance



#include <WiFi.h>
#include <OneButton.h>
#include <ExBreaker.h>
OneButton button(13,true);
int i=0;
int statuz = WL_IDLE_STATUS;
void doubleClick(){
  state =! state;
}

void setup() {

    button.attachDoubleClick(doubleClick);

    Serial.begin(115200);

}
void loop(){
  // keep watching the push button:
  button.tick();
  // You can implement other code in here or just wait a while
  delay(10);
     if( state== LOW){
      
    WiFi.begin();
   Serial.print("Connected: ");
   Serial.println(WiFi.localIP());
   }else if (state == 1){
    Disconnect(); 
} 
}

issuing a WiFi.disconnect(); would erase the known ssid/password and prevent automatic connection the next time you boot

1 Like

do you know code besides disconnect to turn off wifi?

If you want no radio, to turn Wi-Fi and Bluetooth off try

WiFi.mode(WIFI_OFF);
btStop();
1 Like

i just change WiFi.disconnect(); to WiFi.mode(WIFI_OFF); but still show E (134794) wifi:sta is connecting on serial monitor.

Post the code

main code

#include <WiFi.h>
#include <OneButton.h>
#include <ExBreaker.h>
OneButton button(13,true);
int i=0;
int statuz = WL_IDLE_STATUS;
int wstatus = WiFi.status();
void doubleClick(){
  state =! state;
}

void setup() {

    button.attachDoubleClick(doubleClick);
    Connect();
    Serial.begin(115200);

}
void loop(){
  // keep watching the push button:
  button.tick();
  // You can implement other code in here or just wait a while
  delay(10);
    if( state== 0){ 
     WiFi.begin();    
 Serial.println(WiFi.localIP());
   }if (state == 1){
    Disconnect(); 
} 
}

code void disconnect

void Disconnect(){  
  WiFi.mode(WIFI_OFF);
//  WiFi.disconnect(ssid, password);
  Serial.print(F("Disconnected. My IP address is: "));
  Serial.println(WiFi.localIP()); 
  
}

code void connect

void Connect(){  
//  WiFi.disconnect(false);
  WiFi.begin(ssid, password);
  
}

well, you call connect() in the setup(), why would you be surprised that the connexion is made?

Side notes:

Don't post snippets (Snippets R Us!)

➜ where is state declared?
➜ please make an habit to indent the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)

this looks nicer and easier to read, don't you think?

void loop() {
  // keep watching the push button:
  button.tick();
  
  // You can implement other code in here or just wait a while
  delay(10);
  
  if ( state == 0) {
    WiFi.begin();
    Serial.println(WiFi.localIP());
  }
  
  if (state == 1) {
    Disconnect();
  }
}

PS: state is likely a boolean, so you could do

if (state) {
  ...
} else {
  ...
}
1 Like

i change the code

#include <WiFi.h>
#include <OneButton.h>
#include <ExBreaker.h>
OneButton button(13, true);
int i = 0;
int statuz = WL_IDLE_STATUS;
int wstatus = WiFi.status();
void doubleClick() {
  state = ! state;
}

void setup() {

  button.attachDoubleClick(doubleClick);
  Connect();
  Serial.begin(115200);

}
void loop() {
  // keep watching the push button:
  button.tick();
  // You can implement other code in here or just wait a while
  delay(10);
  if ( state == 0) {
    WiFi.begin();
    Serial.println(WiFi.localIP());
  } else {

    Disconnect();
  }
}

still not fix the problem

serial monitor

15:42:25.334 -> E (175026) wifi:sta is connecting, return error
15:42:25.334 -> 0.0.0.0

state declared on library ExBreaker.h if i combine all just like this

#include <WiFi.h>
#include <OneButton.h>
#include <ExBreaker.h>
OneButton button(13, true);
const char *ssid = "Get";
const char *password = "12345678";
int state = 0; 
int i = 0;
int statuz = WL_IDLE_STATUS;
int wstatus = WiFi.status();
void doubleClick() {
  state = ! state;
}

void setup() {

  button.attachDoubleClick(doubleClick);
  Connect();
  Serial.begin(115200);

}
void loop() {
  // keep watching the push button:
  button.tick();
  // You can implement other code in here or just wait a while
  delay(10);
  if ( state == 0) {
    WiFi.begin();
    Serial.println(WiFi.localIP());
  } else {

    Disconnect();
  }
}

sorry for being dumb i dont know waht snippets is because im new here i hope you all understand

You probably just have to

This is a part of an answer, just like your code is only a part of the problem description.
Not so useful, don't you think?

1 Like