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();
}
}
#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());
}
➜ 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();
}
}
#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