Skip to content

Commit

Permalink
Add new Setup Mode and new AP mode, fixes #715
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-github committed Feb 6, 2022
1 parent c8f7f4d commit a4609ae
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 88 deletions.
4 changes: 2 additions & 2 deletions esp3d/src/core/espcmd/ESP0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions esp3d/src/core/espcmd/ESP104.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("??");
}
Expand All @@ -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") ||
Expand All @@ -76,16 +76,16 @@ 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;
}

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

Expand Down
9 changes: 7 additions & 2 deletions esp3d/src/core/espcmd/ESP110.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("??");
}
Expand All @@ -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") ||
Expand All @@ -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 "
Expand All @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions esp3d/src/core/espcmd/ESP400.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}");
Expand Down Expand Up @@ -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\"}");
Expand Down
2 changes: 1 addition & 1 deletion esp3d/src/core/settings_esp3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions esp3d/src/include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion esp3d/src/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions esp3d/src/modules/display/advanceddisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion esp3d/src/modules/http/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
112 changes: 56 additions & 56 deletions esp3d/src/modules/mks/mks_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions esp3d/src/modules/network/netconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
}
}

void NetConfig::setMode(uint8_t mode)
{
_mode=mode;
}

uint8_t NetConfig::getMode()
{
return _mode;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions esp3d/src/modules/network/netconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions esp3d/src/modules/network/netservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions esp3d/src/modules/update/update_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit a4609ae

Please # to comment.