Add new Setup Mode and new AP mode, fixes #715

This commit is contained in:
Luc 2022-02-06 17:43:11 +08:00
parent c8f7f4dee4
commit a4609aee69
16 changed files with 104 additions and 86 deletions

View File

@ -31,7 +31,7 @@ const char * help[]= {"[ESP] - display this help",
"[ESP103](IP=xxxx MSK=xxxx GW=xxxx) - display/set STA IP/Mask/GW",
#endif //WIFI_FEATURE || ETH_FEATURE
#if defined( WIFI_FEATURE) || defined( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
"[ESP104](State) - display/set sta fallback mode which can be BT, AP, OFF",
"[ESP104](State) - display/set sta fallback mode which can be BT, SETUP, OFF",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined (WIFI_FEATURE)
"[ESP105](SSID) - display/set AP SSID",
@ -40,7 +40,7 @@ const char * help[]= {"[ESP] - display this help",
"[ESP108](Chanel) - display/set AP chanel",
#endif //WIFI_FEATURE
#if defined( WIFI_FEATURE) || defined( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
"[ESP110](State) - display/set radio state which can be BT, WIFI-STA, WIFI-AP, ETH-STA, OFF",
"[ESP110](State) - display/set radio state which can be BT, WIFI-STA, WIFI-AP, WIFI-SETUP, ETH-STA, OFF",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined( WIFI_FEATURE) || defined (ETH_FEATURE)
"[ESP111](header)display current IP",

View File

@ -46,8 +46,8 @@ bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
output->printMSG("OFF");
} else if (wifiMode == ESP_BT) {
output->printMSG("BT");
} else if (wifiMode == ESP_WIFI_AP) {
output->printMSG("WIFI-AP");
} else if (wifiMode == ESP_AP_SETUP) {
output->printMSG("WIFI-SETUP");
} else {
output->printMSG("??");
}
@ -64,7 +64,7 @@ bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
(parameter == "BT") ||
#endif //BLUETOOTH_FEATURE
#if defined( WIFI_FEATURE)
(parameter == "WIFI-AP") ||
(parameter == "WIFI-SETUP") ||
#endif //WIFI_FEATURE
#if defined( ETH_FEATURE)
(parameter == "ETH-STA") || //(parameter == "ETH-SRV") ||
@ -76,7 +76,7 @@ bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
"BT or "
#endif //BLUETOOTH_FEATURE
#ifdef WIFI_FEATURE
"WIFI-AP or "
"WIFI-SETUP or "
#endif //WIFI_FEATURE
"OFF mode supported!");
return false;
@ -84,8 +84,8 @@ bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
int8_t bbuf = ESP_NO_NETWORK;
#ifdef WIFI_FEATURE
if(parameter == "WIFI-AP") {
bbuf = ESP_WIFI_AP;
if(parameter == "WIFI-SETUP") {
bbuf = ESP_AP_SETUP;
}
#endif //WIFI_FEATURE

View File

@ -54,6 +54,8 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
// output->printMSG("ETH-SRV");
} else if (wifiMode == ESP_ETH_STA) {
output->printMSG("ETH-STA");
} else if (wifiMode == ESP_AP_SETUP) {
output->printMSG("WIFI-SETUP");
} else {
output->printMSG("??");
}
@ -70,7 +72,7 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
(parameter == "BT") ||
#endif //BLUETOOTH_FEATURE
#if defined( WIFI_FEATURE)
(parameter == "WIFI-STA") || (parameter == "WIFI-AP") ||
(parameter == "WIFI-STA") || (parameter == "WIFI-AP") || (parameter == "WIFI-SETUP") ||
#endif //WIFI_FEATURE
#if defined( ETH_FEATURE)
(parameter == "ETH-STA") || //(parameter == "ETH-SRV") ||
@ -82,7 +84,7 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
"BT or "
#endif //BLUETOOTH_FEATURE
#ifdef WIFI_FEATURE
"WIFI-STA or WIFI-AP or "
"WIFI-STA or WIFI-AP or WIFI-SETUP or "
#endif //WIFI_FEATURE
#ifdef ETH_FEATURE
"ETH-STA or "
@ -99,6 +101,9 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
if(parameter == "WIFI-AP") {
bbuf = ESP_WIFI_AP;
}
if(parameter == "WIFI-SETUP") {
bbuf = ESP_AP_SETUP;
}
#endif //WIFI_FEATURE
#ifdef ETH_FEATURE
if(parameter == "ETH-STA") {

View File

@ -62,7 +62,7 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
output->print (Settings_ESP3D::read_byte(ESP_RADIO_MODE));
output->print ("\",\"H\":\"radio mode\",\"O\":[{\"none\":\"0\"}");
#ifdef WIFI_FEATURE
output->print (",{\"sta\":\"1\"},{\"ap\":\"2\"}");
output->print (",{\"sta\":\"1\"},{\"ap\":\"2\"},{\"setup\":\"5\"}");
#endif //WIFI_FEATURE
#ifdef BLUETOOTH_FEATURE
output->print (",{\"bt\":\"3\"}");
@ -147,7 +147,7 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
output->print (Settings_ESP3D::read_byte(ESP_STA_FALLBACK_MODE));
output->print ("\",\"H\":\"sta fallback mode\",\"O\":[{\"none\":\"0\"}");
#ifdef WIFI_FEATURE
output->print (",{\"ap\":\"2\"}");
output->print (",{\"setup\":\"5\"}");
#endif //WIFI_FEATURE
#ifdef BLUETOOTH_FEATURE
output->print (",{\"bt\":\"3\"}");

View File

@ -67,7 +67,7 @@
#if defined(STATION_WIFI_SSID) && defined(STATION_WIFI_PASSWORD)
#define DEFAULT_ESP_RADIO_MODE ESP_WIFI_STA
#else
#define DEFAULT_ESP_RADIO_MODE ESP_WIFI_AP
#define DEFAULT_ESP_RADIO_MODE ESP_AP_SETUP
#endif //STATION_WIFI_SSID && STATION_WIFI_PASSWORD
#else //WIFI_FEATURE
#define DEFAULT_STA_FALLBACK_MODE ESP_NO_NETWORK

View File

@ -77,6 +77,7 @@
#define ESP_WIFI_AP 2
#define ESP_BT 3
#define ESP_ETH_STA 4
#define ESP_AP_SETUP 5
//#define ESP_ETH_SRV 5
//SD mount point

View File

@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H
//version and sources location
#define FW_VERSION "3.0.0.a109"
#define FW_VERSION "3.0.0.a110"
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
#endif //_VERSION_ESP3D_H

View File

@ -319,6 +319,7 @@ bool Display::display_IP(bool force)
case ESP_WIFI_STA:
s = WiFi.localIP().toString();
break;
case ESP_AP_SETUP:
case ESP_WIFI_AP:
s = WiFi.softAPIP().toString();
break;

View File

@ -30,6 +30,7 @@
#endif //ARDUINO_ARCH_ESP8266
#include "http_server.h"
#include "../authentication/authentication_service.h"
#include "../network/netconfig.h"
#include "../../core/settings_esp3d.h"
#include "../filesystem/esp_filesystem.h"
#include "../websocket/websocket_server.h"
@ -79,7 +80,7 @@ void HTTP_Server::init_handlers()
}
#endif //SSDP_FEATURE
#ifdef CAPTIVE_PORTAL_FEATURE
if(WiFi.getMode() == WIFI_AP) {
if(NetConfig::getMode() == ESP_AP_SETUP) {
_webserver->on ("/generate_204", HTTP_ANY, handle_root);
_webserver->on ("/gconnectivitycheck.gstatic.com", HTTP_ANY, handle_root);
//do not forget the / at the end

View File

@ -627,7 +627,7 @@ bool MKSService::sendNetworkFrame()
//Wifi_key Segment
strcpy((char *)&_frame[dataOffset], s.c_str());
dataOffset+=s.length();
} else if (NetConfig::getMode() == ESP_WIFI_AP) {
} else if (NetConfig::getMode() == ESP_WIFI_AP || (NetConfig::getMode() == ESP_AP_SETUP) {
log_esp3d("AP Mode");
///////////////////////////////////
//IP Segment

View File

@ -221,6 +221,11 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
}
}
void NetConfig::setMode(uint8_t mode)
{
_mode=mode;
}
uint8_t NetConfig::getMode()
{
return _mode;
@ -272,11 +277,9 @@ bool NetConfig::begin()
return true;
}
#if defined (WIFI_FEATURE)
if ((espMode == ESP_WIFI_AP) || (espMode == ESP_WIFI_STA)) {
if ((espMode == ESP_AP_SETUP) || (espMode == ESP_WIFI_AP) || (espMode == ESP_WIFI_STA)) {
output.printMSG("Setup wifi");
res = WiFiConfig::begin(espMode);
//in case STA failed and fallback to AP mode
_mode = ESP_WIFI_AP;
}
#endif //WIFI_FEATURE
#if defined (ETH_FEATURE)

View File

@ -61,6 +61,7 @@ public:
static void end();
static void handle();
static uint8_t getMode();
static void setMode(uint8_t mode);
static bool started()
{
return _started;

View File

@ -192,7 +192,7 @@ bool NetServices::begin()
#endif //MDNS_FEATURE && ARDUINO_ARCH_ESP8266
#ifdef CAPTIVE_PORTAL_FEATURE
if(WiFi.getMode() == WIFI_AP) {
if(NetConfig::getMode() == ESP_AP_SETUP) {
// if DNSServer is started with "*" for domain name, it will reply with
// provided IP to all DNS request
if (dnsServer.start(DNS_PORT, "*", WiFi.softAPIP())) {
@ -349,7 +349,7 @@ void NetServices::end()
notificationsservice.end();
#endif //NOTIFICATION_FEATURE
#ifdef CAPTIVE_PORTAL_FEATURE
if(WiFi.getMode() == WIFI_AP) {
if(NetConfig::getMode() == ESP_AP_SETUP) {
dnsServer.stop();
}
#endif //CAPTIVE_PORTAL_FEATURE
@ -421,7 +421,7 @@ void NetServices::handle()
ArduinoOTA.handle();
#endif //OTA_FEATURE
#ifdef CAPTIVE_PORTAL_FEATURE
if (WiFi.getMode()== WIFI_AP ) {
if (NetConfig::getMode() == ESP_AP_SETUP) {
dnsServer.processNextRequest();
}
#endif //CAPTIVE_PORTAL_FEATURE

View File

@ -273,6 +273,8 @@ bool processingFileFunction (const char * section, const char * key, const char
b=ESP_WIFI_STA;
} else if (strcasecmp("WIFI-AP",value)==0) {
b=ESP_WIFI_AP;
} else if (strcasecmp("WIFI-SETUP",value)==0) {
b=ESP_AP_SETUP;
} else if (strcasecmp("ETH-STA",value)==0) {
b=ESP_ETH_STA;
} else if (strcasecmp("OFF",value)==0) {
@ -290,8 +292,8 @@ bool processingFileFunction (const char * section, const char * key, const char
done = true;
if (strcasecmp("BT",value)==0) {
b=ESP_BT;
} else if (strcasecmp("WIFI-AP",value)==0) {
b=ESP_WIFI_AP;
} else if (strcasecmp("WIFI-SETUP",value)==0) {
b=ESP_AP_SETUP;
} else if (strcasecmp("OFF",value)==0) {
b=ESP_NO_NETWORK;
} else {

View File

@ -224,7 +224,7 @@ bool WiFiConfig::StartSTA()
* Setup and start Access point
*/
bool WiFiConfig::StartAP()
bool WiFiConfig::StartAP(bool setupMode)
{
ESP3DOutput output(ESP_ALL_CLIENTS);
//Sanity check
@ -259,7 +259,10 @@ bool WiFiConfig::StartAP()
if (password.length() > 0) {
stmp +="' is started and protected by password";
} else {
stmp +=" is started not protected by passord";
stmp +=" is started not protected by password";
}
if (setupMode) {
stmp += " (setup mode)";
}
output.printMSG(stmp.c_str());
log_esp3d("%s",stmp.c_str());
@ -267,7 +270,7 @@ bool WiFiConfig::StartAP()
Hal::wait(100);
//Set static IP
log_esp3d("Use: %s / %s / %s", ip.toString().c_str(),ip.toString().c_str(),mask.toString().c_str());
if (!WiFi.softAPConfig(ip, gw, mask)) {
if (!WiFi.softAPConfig(ip, setupMode?ip:gw, mask)) {
output.printERROR("Set IP to AP failed");
} else {
output.printMSG(ip.toString().c_str());
@ -302,9 +305,9 @@ bool WiFiConfig::begin(int8_t & espMode)
output.printMSG("Starting WiFi");
}
int8_t wifiMode = espMode;
if (wifiMode == ESP_WIFI_AP) {
if (wifiMode == ESP_WIFI_AP || wifiMode == ESP_AP_SETUP) {
log_esp3d("Starting AP mode");
res = StartAP();
res = StartAP(wifiMode == ESP_AP_SETUP);
} else if (wifiMode == ESP_WIFI_STA) {
log_esp3d("Starting STA");
res = StartSTA();
@ -314,9 +317,10 @@ bool WiFiConfig::begin(int8_t & espMode)
output.printMSG("Starting fallback mode");
}
espMode = Settings_ESP3D::read_byte(ESP_STA_FALLBACK_MODE);
if (espMode == ESP_WIFI_AP) {
log_esp3d("Starting AP mode in safe mode");
res = StartAP();
NetConfig::setMode(espMode);
if (espMode == ESP_AP_SETUP) {
log_esp3d("Starting AP mode in setup mode");
res = StartAP(true);
} else {
//let setup to handle the change
res = true;

View File

@ -56,7 +56,7 @@ class WiFiConfig
public:
static bool isPasswordValid (const char * password);
static bool isSSIDValid (const char * ssid);
static bool StartAP();
static bool StartAP(bool setupMode = false);
static bool StartSTA();
static void StopWiFi();
static int32_t getSignal (int32_t RSSI);