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

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