diff --git a/esp3d/src/core/espcmd/ESP0.cpp b/esp3d/src/core/espcmd/ESP0.cpp index 16e5009ee..cbb625882 100644 --- a/esp3d/src/core/espcmd/ESP0.cpp +++ b/esp3d/src/core/espcmd/ESP0.cpp @@ -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", diff --git a/esp3d/src/core/espcmd/ESP104.cpp b/esp3d/src/core/espcmd/ESP104.cpp index 2106943b0..23b5c5cad 100644 --- a/esp3d/src/core/espcmd/ESP104.cpp +++ b/esp3d/src/core/espcmd/ESP104.cpp @@ -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 diff --git a/esp3d/src/core/espcmd/ESP110.cpp b/esp3d/src/core/espcmd/ESP110.cpp index c16fb980b..a9aa0b5a3 100644 --- a/esp3d/src/core/espcmd/ESP110.cpp +++ b/esp3d/src/core/espcmd/ESP110.cpp @@ -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") { diff --git a/esp3d/src/core/espcmd/ESP400.cpp b/esp3d/src/core/espcmd/ESP400.cpp index baf91f25a..2dd8414aa 100644 --- a/esp3d/src/core/espcmd/ESP400.cpp +++ b/esp3d/src/core/espcmd/ESP400.cpp @@ -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\"}"); diff --git a/esp3d/src/core/settings_esp3d.cpp b/esp3d/src/core/settings_esp3d.cpp index 9f79bc40f..aa9e9a61f 100644 --- a/esp3d/src/core/settings_esp3d.cpp +++ b/esp3d/src/core/settings_esp3d.cpp @@ -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 diff --git a/esp3d/src/include/defines.h b/esp3d/src/include/defines.h index 472b7ca6d..5205e6805 100644 --- a/esp3d/src/include/defines.h +++ b/esp3d/src/include/defines.h @@ -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 diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index 071b25f94..979ecd711 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -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 diff --git a/esp3d/src/modules/display/advanceddisplay.cpp b/esp3d/src/modules/display/advanceddisplay.cpp index 4e0b7f0fd..f14993507 100644 --- a/esp3d/src/modules/display/advanceddisplay.cpp +++ b/esp3d/src/modules/display/advanceddisplay.cpp @@ -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; diff --git a/esp3d/src/modules/http/http_server.cpp b/esp3d/src/modules/http/http_server.cpp index bbeaadc17..4c2e4bca7 100644 --- a/esp3d/src/modules/http/http_server.cpp +++ b/esp3d/src/modules/http/http_server.cpp @@ -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 diff --git a/esp3d/src/modules/mks/mks_service.cpp b/esp3d/src/modules/mks/mks_service.cpp index 26f4a5041..7bbad9ba2 100644 --- a/esp3d/src/modules/mks/mks_service.cpp +++ b/esp3d/src/modules/mks/mks_service.cpp @@ -627,8 +627,8 @@ bool MKSService::sendNetworkFrame() //Wifi_key Segment strcpy((char *)&_frame[dataOffset], s.c_str()); dataOffset+=s.length(); - } else if (NetConfig::getMode() == ESP_WIFI_AP) { - log_esp3d("AP Mode"); + } else if (NetConfig::getMode() == ESP_WIFI_AP || (NetConfig::getMode() == ESP_AP_SETUP) { + log_esp3d("AP Mode"); /////////////////////////////////// //IP Segment //IP value @@ -671,61 +671,61 @@ bool MKSService::sendNetworkFrame() //Cloud Services port Segment //hard coded _frame[MKS_FRAME_DATA_OFFSET +4] = (telnet_server.port()) & 0xff; - _frame[MKS_FRAME_DATA_OFFSET +5] = ((telnet_server.port()) >> 8 ) & 0xff; - log_esp3d("Cloud port: %d", (telnet_server.port())); - - ////////////////////////////////// - //Cloud State Segment - //hard coded as disabled in upstream FW - _frame[dataOffset] = MKS_FRAME_CLOUD_DISABLED_STATE; - dataOffset++; - ////////////////////////////////// - //Cloud host len Segment - //Use ESP3D IP instead - s = NetConfig::localIPAddress().toString(); - _frame[dataOffset] = s.length(); - dataOffset++; - ////////////////////////////////// - //Cloud host Segment - //Use ESP3D IP instead - strcpy((char *)&_frame[dataOffset], s.c_str()); - dataOffset+=s.length(); - ////////////////////////////////// - //Cloud host port Segment - //use webserver port instead - _frame[dataOffset] = (HTTP_Server::port()) & 0xff; - dataOffset++; - _frame[dataOffset] = ((HTTP_Server::port())>> 8 ) & 0xff; - dataOffset++; - ////////////////////////////////// - //Module id len Segment - //Use hostname instead - _frame[dataOffset] = strlen(_moduleId); - dataOffset++; - ////////////////////////////////// - //Module id Segment - strcpy((char *)&_frame[dataOffset], _moduleId); - dataOffset+=strlen(_moduleId); - ////////////////////////////////// - //FW version len Segment - _frame[dataOffset] = strlen(FW_VERSION)+6; - dataOffset++; - ////////////////////////////////// - //FW version Segment - strcpy((char *)&_frame[dataOffset], "ESP3D_" FW_VERSION); - dataOffset+=strlen(FW_VERSION)+6; - ////////////////////////////////// - //Tail Segment - _frame[dataOffset] = MKS_FRAME_TAIL_FLAG; - - ////////////////////////////////// - //Data len Segment - //Calculated from above - _frame[MKS_FRAME_DATALEN_OFFSET] = (dataOffset-4) & 0xff; - _frame[MKS_FRAME_DATALEN_OFFSET+1] = ((dataOffset-4) >> 8) & 0xff; - log_esp3d("Size of data in frame %d ", dataOffset-4); + _frame[MKS_FRAME_DATA_OFFSET +5] = ((telnet_server.port()) >> 8 ) & 0xff; + log_esp3d("Cloud port: %d", (telnet_server.port())); + + ////////////////////////////////// + //Cloud State Segment + //hard coded as disabled in upstream FW + _frame[dataOffset] = MKS_FRAME_CLOUD_DISABLED_STATE; + dataOffset++; + ////////////////////////////////// + //Cloud host len Segment + //Use ESP3D IP instead + s = NetConfig::localIPAddress().toString(); + _frame[dataOffset] = s.length(); + dataOffset++; + ////////////////////////////////// + //Cloud host Segment + //Use ESP3D IP instead + strcpy((char *)&_frame[dataOffset], s.c_str()); + dataOffset+=s.length(); + ////////////////////////////////// + //Cloud host port Segment + //use webserver port instead + _frame[dataOffset] = (HTTP_Server::port()) & 0xff; + dataOffset++; + _frame[dataOffset] = ((HTTP_Server::port())>> 8 ) & 0xff; + dataOffset++; + ////////////////////////////////// + //Module id len Segment + //Use hostname instead + _frame[dataOffset] = strlen(_moduleId); + dataOffset++; + ////////////////////////////////// + //Module id Segment + strcpy((char *)&_frame[dataOffset], _moduleId); + dataOffset+=strlen(_moduleId); + ////////////////////////////////// + //FW version len Segment + _frame[dataOffset] = strlen(FW_VERSION)+6; + dataOffset++; + ////////////////////////////////// + //FW version Segment + strcpy((char *)&_frame[dataOffset], "ESP3D_" FW_VERSION); + dataOffset+=strlen(FW_VERSION)+6; + ////////////////////////////////// + //Tail Segment + _frame[dataOffset] = MKS_FRAME_TAIL_FLAG; + + ////////////////////////////////// + //Data len Segment + //Calculated from above + _frame[MKS_FRAME_DATALEN_OFFSET] = (dataOffset-4) & 0xff; + _frame[MKS_FRAME_DATALEN_OFFSET+1] = ((dataOffset-4) >> 8) & 0xff; + log_esp3d("Size of data in frame %d ", dataOffset-4); if (canSendFrame()) { - ESP3DOutput output(ESP_SERIAL_CLIENT); + ESP3DOutput output(ESP_SERIAL_CLIENT); if (output.write(_frame,dataOffset+1) == (dataOffset+1)) { log_esp3d("Ok"); sendFrameDone(); diff --git a/esp3d/src/modules/network/netconfig.cpp b/esp3d/src/modules/network/netconfig.cpp index 6b43f32fe..ddf46eb10 100644 --- a/esp3d/src/modules/network/netconfig.cpp +++ b/esp3d/src/modules/network/netconfig.cpp @@ -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) diff --git a/esp3d/src/modules/network/netconfig.h b/esp3d/src/modules/network/netconfig.h index d7c8510f5..5b64d4c3b 100644 --- a/esp3d/src/modules/network/netconfig.h +++ b/esp3d/src/modules/network/netconfig.h @@ -61,6 +61,7 @@ class NetConfig static void end(); static void handle(); static uint8_t getMode(); + static void setMode(uint8_t mode); static bool started() { return _started; diff --git a/esp3d/src/modules/network/netservices.cpp b/esp3d/src/modules/network/netservices.cpp index d5fc42ca6..5b610c4ae 100644 --- a/esp3d/src/modules/network/netservices.cpp +++ b/esp3d/src/modules/network/netservices.cpp @@ -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 diff --git a/esp3d/src/modules/update/update_service.cpp b/esp3d/src/modules/update/update_service.cpp index cfb5b4b2b..dc103ab0c 100644 --- a/esp3d/src/modules/update/update_service.cpp +++ b/esp3d/src/modules/update/update_service.cpp @@ -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 { diff --git a/esp3d/src/modules/wifi/wificonfig.cpp b/esp3d/src/modules/wifi/wificonfig.cpp index 669df6107..c26225100 100644 --- a/esp3d/src/modules/wifi/wificonfig.cpp +++ b/esp3d/src/modules/wifi/wificonfig.cpp @@ -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; diff --git a/esp3d/src/modules/wifi/wificonfig.h b/esp3d/src/modules/wifi/wificonfig.h index fb19af738..2e0b12ebc 100644 --- a/esp3d/src/modules/wifi/wificonfig.h +++ b/esp3d/src/modules/wifi/wificonfig.h @@ -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);