Hello.
I use WiFi.begin(ssid,password) and have a problem that it always return 6, even when it has connected.
So what is my problem?
Why do you call WiFi.begin when it has connected? Use WiFi.begin once, and use WiFi.status to check the connection afterwards.
Because I want to set a new ssid and password.
Well, if you change the SSID and password, it doesn't come as a surprise to me that right after changing it, the WiFi is in a 'WL_DISCONNECTED' state.
You could use WiFi.waitForConnectResult()
to block all execution until the connection is established, or if you don't want to block, just poll WiFi.status()
in the loop.
Yes, but before I get the result, connection port closed.
leoncorleone:
Yes, but before I get the result, connection port closed.
What does that mean?
leoncorleone:
Yes, but before I get the result, connection port closed.
the ssid or password are not valid?
I mean, I'm going to set ssid and password by HTTP request locally, when I send the request to esp8266 that set ssid and password, the connection port closed and response not come back, when I use WiFi.begin().
What did you expect? If you disconnect the WiFi in the middle of an HTTP transaction, you won't get a response back.
Do you know that the WiFiManager library is a thing?
Or do you want to do something different?
Make the WiFi.begin outside the WebServer handler. In the handler store the ssid and password into variables and send a response. In loop() then make the WiFi.begin. For the result, pool from the browser with javascript.
That worked. thanks Juraj and thanks all.