Autoconnect only for SoftAP mode #294
-
Can I use Autoconnect only for work in softAP mode without block the main() ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
AutoConnect aims to establish a connection to any AP by the ESP module itself as a WiFi station. (ie. as a WiFi client) So it can't keep the ESP module in only SoftAP mode. It depends on the following logic sequence as a template: // For ESP8266, The same is true for ESP32 with the appropriate include directives.
#include <Arduino.h>
#include <ESP8266WiFi.h> // WiFi.h for ESP32
#include <ESP8266WebServer.h> // WebServer.h for ESP32
#include <AutoConnect.h>
AutoConnect portal;
AutoConnectConfig config;
const char* apSSID = "ap-esp";
const char* apPW = "ap-password";
IPAddress ipAP(192, 168, 1, 1);
IPAddress ipGW(192, 168, 1, 1);
IPAddress ipNM(255, 255, 255, 0);
// Start with SoftAP alone
void startAP() {
WiFi.mode(WIFI_AP);
delay(1000);
WiFi.softAPConfig(ipAP, ipGW, ipNM);
WiFi.softAP(apSSID, apPW);
do {
delay(100);
yield();
} while (!WiFi.softAPIP());
}
void setup() {
delay(1000);
startAP();
// Prevents to stop SoftAP due to AutoConnect::begin
config.preserveAPMode = true;
// Disabling autoRise prevents AutoConnect from trying to connect to any AP as WIFI_STA.
// However, WIFI_STA mode will be entered.
config.autoRise = false;
config.immediateStart = true;
portal.config(config);
portal.begin(); // Keeps AP mode but launches WIFI_STA
WiFi.enableSTA(false); // Shutdown STA
}
void loop() {
portal.handleClient();
} But it still launches WiFi_STA (it has the effect of initiating the WiFi station component of the ESP modules) |
Beta Was this translation helpful? Give feedback.
AutoConnect aims to establish a connection to any AP by the ESP module itself as a WiFi station. (ie. as a WiFi client) So it can't keep the ESP module in only SoftAP mode.
If you enable the AutoConnectConfig::preserveAPMode setting, AutoConnect maintains the AP mode state when you call the library. If you enable AutoConnectConfig::preserveAPMode and start SoftAP prior to AutoConnect::begin, AutoConnect will not interfere with that SoftAP.
Also, to disabe AutoConnectConfig::autoRise setting. This setting directs to AutoConnect not to start the captive portal. Please note that AutoConnect aims to establish a connection with any AP and will try to be a station always.
It depends on the foll…