Here is my wifi code, this is only code that controls wifi.
const char* ssid = wifii;
const char* password = "12345678";
IPAddress local_IP(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
WiFi.persistent(0);
WiFi.mode(WIFI_AP_STA);
WiFi.begin(_EEPROM.sta_ssid, _EEPROM.sta_password);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
apSwitchMillis = millis();
if (millis() - lcdMillis >= 5000) {
WiFi.softAPdisconnect (true);
lcdMillis = millis();
}
} else {
if (millis() - apSwitchMillis >= apTimeout) {
if (!apState) {
WiFi.softAP(ssid, password, 11, false, 8);
WiFi.softAPConfig(local_IP, local_IP, subnet);
apState = true;
}
apSwitchMillis = millis();
}
}
}
Notice every 5000ms i call WiFi.softAPdisconnect (true);
if i do not do this then the ap stays on. why do i have to keep calling it? does somthing actually keep changing the state of it. i should only have to call it 1 time after ap is turned off?
From the docs it says
Function will set currently configured SSID and password of the soft-AP to null values. The parameter wifioff
is optional. If set to true
it will switch the soft-AP mode off.
Function will return true
if operation was successful or false
if otherwise.
why would i want to set ssid and pw to null? why not just turn it off?
Here bug tracker of the function but i cant gather enough information from there to know if it has been fixed or if this is even what is going on.
opened 06:23PM - 04 Nov 17 UTC
closed 06:20PM - 17 Nov 17 UTC
dup of #2950 from feb 10 2017, this is more concise report of actual problem
… ### Basic Infos
softAPdisconnect seems to not work
#### Hardware
Hardware: ESP-12e (nodemcu v1)
Core Version: system_get_sdk_version(): 2.1.0(7106d38)
### Description
softap then sofapdisconnect, always returns false, ap stays on, and persists also
### Sketch
```cpp
/* Create a WiFi access point and provide a web server on it. */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
/* Set these to your desired credentials. */
const char *ssid = "ESPap";
const char *password = "thereisnospoon";
const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };
ESP8266WebServer server(80);
/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void handleRoot() {
server.send(200, "text/html", "<h1>You are connected</h1>");
}
void espInfo(Stream & consolePort){
consolePort.print(F("system_get_sdk_version(): "));
consolePort.println(ESP.getSdkVersion());
consolePort.print(F("system_get_boot_version(): "));
consolePort.println(ESP.getBootVersion());
}
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println();
espInfo(Serial);
WiFi.printDiag(Serial);
// WiFi.persistent(false);
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
// server.on("/", handleRoot);
// server.begin();
// Serial.println("HTTP server started");
Serial.println("Waiting for AP disconnect...");
delay(20000);
bool ret = WiFi.softAPdisconnect();
if(!ret) Serial.println("softAPdisconnect failed");
// delay(2000);
// ESP.eraseConfig();
// ESP.reset();
}
void loop() {
// server.handleClient();
Serial.println(modes[WiFi.getMode()]);
delay(1000);
}
```
### Debug Messages
```
system_get_sdk_version(): 2.1.0(7106d38)
system_get_boot_version(): 31
Mode: AP
PHY mode: N
Channel: 1
AP id: 0
Status: 255
Auto connect: 1
SSID (0):
Passphrase (0):
BSSID set: 0
Configuring access point...AP IP address: 192.168.4.1
Waiting for AP disconnect...
softAPdisconnect failed
AP
AP
AP
AP
AP
```
pylon
May 5, 2021, 6:10pm
#2
Your code doesn't compile, so I guess it wasn't never used exactly this way.
system
Closed
September 2, 2021, 6:10pm
#3
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.