Added the option to disable the service AP after MCU startup
parent
449bb07b58
commit
4692f10340
|
|
@ -193,13 +193,28 @@ const char page_wifi_html[] PROGMEM = R"rawliteral(
|
|||
<tr><td></td><td align="center"><button class="btn_save_w" onclick="setWifi(document.getElementById('wifi_ssid_id').value, document.getElementById('wifi_pass_id').value)">Save & Connect</button></td></tr>
|
||||
</table>
|
||||
</td><td></td></tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<center>
|
||||
<button class="btn_collapsible_wifi">Advanced Wi-Fi settings</button>
|
||||
</center>
|
||||
<div class="content_wifi">
|
||||
<br>
|
||||
<table id="wificfg_tb">
|
||||
<tr><td class="w1">Advanced Wi-Fi settings</td></tr>
|
||||
<tr><td class="w2" align="right">Enable service AP </td><td><label class="switch"><input type="checkbox" name="serviceap_enable" id="serviceapid" onchange="changeValue(this.checked, 'set_bool?serviceap_enable=', 'serviceap')"><span class="checkbox_slider round"></span></label></label> <span class="w1" id="status_serviceap"></span></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<script src="scripts.js"></script>
|
||||
<script>
|
||||
setTimeout(function(){GetDataAndPrintTableWiFi();}, 500);
|
||||
get_data("wifi");
|
||||
setupCollapsibleButtonsWiFi();
|
||||
</script>
|
||||
)rawliteral";
|
||||
|
||||
|
|
@ -629,6 +644,9 @@ cfg_bar li a:hover {
|
|||
table-layout: fixed;
|
||||
text-align: left;
|
||||
}
|
||||
#wificfg_tb {
|
||||
margin-left: 30%;
|
||||
}
|
||||
/* wifi_ntw table */
|
||||
#wifi_ntw {
|
||||
font: normal normal normal 12px/5px sans-serif;
|
||||
|
|
@ -840,6 +858,26 @@ cfg_bar li a:hover {
|
|||
background-color: #FA6831;
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* advanced wifi cfg */
|
||||
.content_wifi {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.btn_collapsible_wifi {
|
||||
width: 300px;
|
||||
height: 24px;
|
||||
text-align: center;
|
||||
font: normal normal bold 14px/5px sans-serif;
|
||||
color: #000000;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #343a40;
|
||||
}
|
||||
.btn_collapsible_wifi:hover {
|
||||
background-color: #FA6831;
|
||||
color: white;
|
||||
}
|
||||
)rawliteral";
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------ */
|
||||
|
|
@ -914,6 +952,8 @@ function get_data(val) {
|
|||
}
|
||||
|
||||
if (val == "wifi") {
|
||||
document.getElementById('serviceapid').checked = obj.serviceap;
|
||||
$("#status_serviceap").text((obj.serviceap == "true") ? "On" : "Off");
|
||||
$("#ssid").text(obj.ssid);
|
||||
$("#rssi").text(obj.rssi);
|
||||
$("#rssi_percentage").text(obj.rssi_percentage);
|
||||
|
|
@ -1292,6 +1332,18 @@ function setupCollapsibleButtons() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setupCollapsibleButtonsWiFi() {
|
||||
$(".btn_collapsible_wifi").click(function(){
|
||||
$(this).toggleClass("active");
|
||||
var content_wifi = $(this).parent().next();
|
||||
if (content_wifi.css("display") === "block") {
|
||||
content_wifi.css("display", "none");
|
||||
} else {
|
||||
content_wifi.css("display", "block");
|
||||
}
|
||||
});
|
||||
}
|
||||
)rawliteral";
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------ */
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ void Configuration::DefaultCfg() {
|
|||
SaveWifiCfgFlag(CFG_WIFI_SETTINGS_NOT_SAVED);
|
||||
SaveWifiPassword("");
|
||||
SaveWifiSsid("");
|
||||
SaveEnableServiceAp(FACTORY_CFG_ENABLE_SERVICE_AP);
|
||||
SaveBasicAuthUsername(FACTORY_CFG_WEB_AUTH_USERNAME);
|
||||
SaveBasicAuthPassword(FACTORY_CFG_WEB_AUTH_PASSWORD);
|
||||
SaveBasicAuthFlag(FACTORY_CFG_WEB_AUTH_ENABLE);
|
||||
|
|
@ -560,6 +561,17 @@ void Configuration::SaveWifiCfgFlag(uint8_t i_data) {
|
|||
Log->AddEvent(LogLevel_Verbose, "Save active wifi cfg flag: " + String(i_data));
|
||||
SaveUint8(EEPROM_ADDR_WIFI_ACTIVE_FLAG_START, i_data);
|
||||
}
|
||||
|
||||
/**
|
||||
@info save enable/disable service AP to EEPROM
|
||||
@param bool - status
|
||||
@return none
|
||||
*/
|
||||
void Configuration::SaveEnableServiceAp(bool i_data) {
|
||||
Log->AddEvent(LogLevel_Verbose, "Save Enable/disable service AP: " + String(i_data));
|
||||
SaveBool(EEPROM_ADDR_SERVICE_AP_ENABLE_START, i_data);
|
||||
}
|
||||
|
||||
/*
|
||||
@info save username fof BasicAuth to EEPROM
|
||||
@param string - username
|
||||
|
|
@ -931,6 +943,23 @@ String Configuration::LoadWifiPassowrd() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@info Load flag for enable/disable service AP from eeprom
|
||||
@param none
|
||||
@return bool - status
|
||||
*/
|
||||
bool Configuration::LoadEnableServiceAp() {
|
||||
bool ret = false;
|
||||
int tmp = EEPROM.read(EEPROM_ADDR_SERVICE_AP_ENABLE_START);
|
||||
|
||||
if ((255 == tmp) || (1 == tmp)) {
|
||||
ret = true;
|
||||
}
|
||||
Log->AddEvent(LogLevel_Info, "Enable Service AP: " + String(ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@info Read username for basic authentification from eeprom
|
||||
@param none
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ public:
|
|||
void SaveWifiSsid(String);
|
||||
void SaveWifiPassword(String);
|
||||
void SaveWifiCfgFlag(uint8_t);
|
||||
void SaveEnableServiceAp(bool);
|
||||
void SaveBasicAuthUsername(String);
|
||||
void SaveBasicAuthPassword(String);
|
||||
void SaveBasicAuthFlag(bool);
|
||||
|
|
@ -86,6 +87,7 @@ public:
|
|||
bool LoadRawGama();
|
||||
String LoadWifiSsid();
|
||||
String LoadWifiPassowrd();
|
||||
bool LoadEnableServiceAp();
|
||||
String LoadBasicAuthUsername();
|
||||
String LoadBasicAuthPassword();
|
||||
bool LoadBasicAuthFlag();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#define _MCU_CFG_H_
|
||||
|
||||
/* ---------------- BASIC MCU CFG --------------*/
|
||||
#define SW_VERSION "1.0.2-beta" ///< SW version
|
||||
#define SW_VERSION "1.0.2-rc1" ///< SW version
|
||||
#define SW_BUILD __DATE__ " " __TIME__ ///< build number
|
||||
#define CONSOLE_VERBOSE_DEBUG false ///< enable/disable verbose debug log level for console
|
||||
#define DEVICE_HOSTNAME "Prusa-ESP32cam" ///< device hostname
|
||||
|
|
@ -125,6 +125,7 @@
|
|||
#define FACTORY_CFG_GAIN_CTRL 1 ///< enable automatic gain
|
||||
#define FACTORY_CFG_AGC_GAIN 0 ///< automatic gain controll gain
|
||||
#define FACTORY_CFG_HOSTNAME "connect.prusa3d.com" ///< hostname for Prusa Connect
|
||||
#define FACTORY_CFG_ENABLE_SERVICE_AP 1 ///< enable service AP mode
|
||||
|
||||
/* ---------------- CFG FLAGS ------------------*/
|
||||
#define CFG_WIFI_SETTINGS_SAVED 0x0A ///< flag saved config
|
||||
|
|
@ -239,6 +240,9 @@
|
|||
#define EEPROM_ADDR_HOSTNAME_START (EEPROM_ADDR_LOG_LEVEL + EEPROM_ADDR_LOG_LEVEL_LENGTH)
|
||||
#define EEPROM_ADDR_HOSTNAME_LENGTH 51
|
||||
|
||||
#define EEPROM_ADDR_SERVICE_AP_ENABLE_START (EEPROM_ADDR_HOSTNAME_START + EEPROM_ADDR_HOSTNAME_LENGTH)
|
||||
#define EEPROM_ADDR_SERVICE_AP_ENABLE_LENGTH 1
|
||||
|
||||
#define EEPROM_SIZE (EEPROM_ADDR_REFRESH_INTERVAL_LENGTH + EEPROM_ADDR_FINGERPRINT_LENGTH + EEPROM_ADDR_TOKEN_LENGTH + \
|
||||
EEPROM_ADDR_FRAMESIZE_LENGTH + EEPROM_ADDR_BRIGHTNESS_LENGTH + EEPROM_ADDR_CONTRAST_LENGTH + \
|
||||
EEPROM_ADDR_SATURATION_LENGTH + EEPROM_ADDR_HMIRROR_LENGTH + EEPROM_ADDR_VFLIP_LENGTH + \
|
||||
|
|
@ -251,7 +255,7 @@
|
|||
EEPROM_ADDR_AWB_MODE_ENABLE_LENGTH + EEPROM_ADDR_BPC_ENABLE_LENGTH + EEPROM_ADDR_WPC_ENABLE_LENGTH + \
|
||||
EEPROM_ADDR_RAW_GAMA_ENABLE_LENGTH + EEPROM_ADDR_AEC2_LENGTH + EEPROM_ADDR_AE_LEVEL_LENGTH + \
|
||||
EEPROM_ADDR_AEC_VALUE_LENGTH + EEPROM_ADDR_GAIN_CTRL_LENGTH + EEPROM_ADDR_AGC_GAIN_LENGTH + EEPROM_ADDR_LOG_LEVEL_LENGTH + \
|
||||
EEPROM_ADDR_HOSTNAME_LENGTH ) ///< how many bits do we need for eeprom memory
|
||||
EEPROM_ADDR_HOSTNAME_LENGTH + EEPROM_ADDR_SERVICE_AP_ENABLE_LENGTH) ///< how many bits do we need for eeprom memory
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -635,6 +635,12 @@ void Server_InitWebServer_Sets() {
|
|||
response = true;
|
||||
}
|
||||
|
||||
if (request->hasParam("serviceap_enable")) {
|
||||
SystemLog.AddEvent(LogLevel_Verbose, F("Set service AP enable"));
|
||||
SystemWifiMngt.SetEnableServiceAp(Server_TransfeStringToBool(request->getParam("serviceap_enable")->value()));
|
||||
response = true;
|
||||
}
|
||||
|
||||
if (true == response) {
|
||||
request->send_P(200, F("text/html"), MSG_SAVE_OK);
|
||||
}
|
||||
|
|
@ -982,6 +988,7 @@ String Server_GetJsonData() {
|
|||
doc_json["wifi_mode"] = SystemWifiMngt.GetWiFiMode();
|
||||
doc_json["mdns"] = SystemWifiMngt.GetMdns();
|
||||
doc_json["service_ap_ssid"] = SystemWifiMngt.GetServiceApSsid();
|
||||
doc_json["serviceap"] = (SystemWifiMngt.GetEnableServiceAp() == true) ? "true" : "";
|
||||
doc_json["auth"] = (WebBasicAuth.EnableAuth == true) ? "true" : "";
|
||||
doc_json["auth_username"] = WebBasicAuth.UserName;
|
||||
doc_json["last_upload_status"] = Connect.GetBackendReceivedStatus();
|
||||
|
|
|
|||
|
|
@ -448,7 +448,9 @@ void System_TaskWifiManagement(void *pvParameters) {
|
|||
|
||||
/* wifi reconnect after signal lost */
|
||||
SystemWifiMngt.WiFiReconnect();
|
||||
|
||||
SystemLog.AddEvent(LogLevel_Info, "Free RAM: " + String(ESP.getFreeHeap()) + " bytes");
|
||||
SystemLog.AddEvent(LogLevel_Info, "Free SPIRAM: " + String(ESP.getFreePsram()) + " bytes");
|
||||
SystemLog.AddEvent(LogLevel_Info, "Temperature: " + String(temperatureRead()) + " *C");
|
||||
SystemLog.AddEvent(LogLevel_Verbose, "WiFiManagement task. Stack free size: " + String(uxTaskGetStackHighWaterMark(NULL)) + " bytes");
|
||||
|
||||
/* reset wdg */
|
||||
|
|
@ -473,9 +475,6 @@ void System_TaskMain(void *pvParameters) {
|
|||
/* for ota update */
|
||||
esp_task_wdt_reset();
|
||||
System_Main();
|
||||
SystemLog.AddEvent(LogLevel_Info, "Free RAM: " + String(ESP.getFreeHeap()) + " bytes");
|
||||
SystemLog.AddEvent(LogLevel_Info, "Free SPIRAM: " + String(ESP.getFreePsram()) + " bytes");
|
||||
SystemLog.AddEvent(LogLevel_Info, "Temperature: " + String(temperatureRead()) + " *C");
|
||||
SystemLog.AddEvent(LogLevel_Verbose, "System task. Stack free size: " + String(uxTaskGetStackHighWaterMark(NULL)) + " bytes");
|
||||
|
||||
/* reset wdg */
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ void WiFiMngt::LoadCfgFromEeprom() {
|
|||
WifiSsid = config->LoadWifiSsid();
|
||||
WifiPassword = config->LoadWifiPassowrd();
|
||||
mDNS_record = config->LoadMdnsRecord();
|
||||
EnableServiceAp = config->LoadEnableServiceAp();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,20 +54,30 @@ void WiFiMngt::LoadCfgFromEeprom() {
|
|||
void WiFiMngt::Init() {
|
||||
/* check WI-FI mode */
|
||||
system_led.setTimer(STATUS_LED_WIFI_AP);
|
||||
ServiceMode = true;
|
||||
log->AddEvent(LogLevel_Info, "WiFi MAC: " + WiFi.macAddress());
|
||||
|
||||
/* Set Wi-Fi networks */
|
||||
SetWifiEvents();
|
||||
CreateApSsid();
|
||||
log->AddEvent(LogLevel_Warning, F("Set WiFi AP mode"));
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
|
||||
if (true == GetEnableServiceAp()) {
|
||||
log->AddEvent(LogLevel_Info, F("Service AP mode enabled"));
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
ServiceMode = true;
|
||||
WiFi.softAPConfig(Service_LocalIp, Service_Gateway, Service_Subnet);
|
||||
WiFi.softAP(SericeApSsid.c_str(), SERVICE_WIFI_PASS, SERVICE_WIFI_CHANNEL);
|
||||
WiFiMode = "AP + Client";
|
||||
log->AddEvent(LogLevel_Info, "Service IP Address: http://" + WiFi.softAPIP().toString());
|
||||
|
||||
} else {
|
||||
log->AddEvent(LogLevel_Warning, F("Service AP mode disabled!"));
|
||||
WiFi.mode(WIFI_STA);
|
||||
ServiceMode = false;
|
||||
WiFiMode = "Client";
|
||||
}
|
||||
|
||||
esp_wifi_set_ps(WIFI_PS_NONE);
|
||||
WiFi.softAPConfig(Service_LocalIp, Service_Gateway, Service_Subnet);
|
||||
WiFi.softAP(SericeApSsid.c_str(), SERVICE_WIFI_PASS, SERVICE_WIFI_CHANNEL);
|
||||
WiFi.setHostname(DEVICE_HOSTNAME);
|
||||
WiFiMode = "AP + Client";
|
||||
log->AddEvent(LogLevel_Info, "Service IP Address: http://" + WiFi.softAPIP().toString());
|
||||
FirstConnected = false;
|
||||
//WiFi.setTxPower(WIFI_POWER_18_5dBm);
|
||||
|
||||
|
|
@ -639,6 +650,16 @@ String WiFiMngt::GetMdns() {
|
|||
return mDNS_record;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function for get status about enable service AP mode
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool WiFiMngt::GetEnableServiceAp() {
|
||||
return EnableServiceAp;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief function for get first time NTP sync status
|
||||
@param none
|
||||
|
|
@ -693,6 +714,16 @@ void WiFiMngt::SetStaPassword(String i_pass) {
|
|||
config->SaveWifiPassword(WifiPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set enable service AP mode after MCU boot
|
||||
*
|
||||
* @param i_data
|
||||
*/
|
||||
void WiFiMngt::SetEnableServiceAp(bool i_data) {
|
||||
EnableServiceAp = i_data;
|
||||
config->SaveEnableServiceAp(EnableServiceAp);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief function for connect to STA
|
||||
@param none
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ private:
|
|||
String SericeApSsid; ///< Service AP SSID
|
||||
bool FirstConnected; ///< flag about first connecting to WiFi network status
|
||||
bool NtpFirstSync; ///< flag about first NTP sync status
|
||||
bool EnableServiceAp; ///< flag about enable service AP mode
|
||||
|
||||
uint8_t WiFiStaNetworkBssid[6]; ///< BSSID of the network
|
||||
|
||||
|
|
@ -104,6 +105,7 @@ public:
|
|||
String GetWiFiMode();
|
||||
String GetWifiMac();
|
||||
String GetMdns();
|
||||
bool GetEnableServiceAp();
|
||||
bool GetkActifeWifiCfgFlag();
|
||||
bool GetNtpFirstTimeSync();
|
||||
bool GetFirstConnection();
|
||||
|
|
@ -111,6 +113,7 @@ public:
|
|||
void SetStaCredentials(String, String);
|
||||
void SetStaSsid(String);
|
||||
void SetStaPassword(String);
|
||||
void SetEnableServiceAp(bool);
|
||||
void ConnectToSta();
|
||||
void SetMdns(String);
|
||||
void SetFirstConnection(bool);
|
||||
|
|
|
|||
|
|
@ -48,11 +48,26 @@
|
|||
<tr><td></td><td align="center"><button class="btn_save_w" onclick="setWifi(document.getElementById('wifi_ssid_id').value, document.getElementById('wifi_pass_id').value)">Save & Connect</button></td></tr>
|
||||
</table>
|
||||
</td><td></td></tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<center>
|
||||
<button class="btn_collapsible_wifi">Advanced Wi-Fi settings</button>
|
||||
</center>
|
||||
<div class="content_wifi">
|
||||
<br>
|
||||
<table id="wificfg_tb">
|
||||
<tr><td class="w1">Advanced Wi-Fi settings</td></tr>
|
||||
<tr><td class="w2" align="right">Enable service AP </td><td><label class="switch"><input type="checkbox" name="serviceap_enable" id="serviceapid" onchange="changeValue(this.checked, 'set_bool?serviceap_enable=', 'serviceap')"><span class="checkbox_slider round"></span></label></label> <span class="w1" id="status_serviceap"></span></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<script src="scripts.js"></script>
|
||||
<script>
|
||||
setTimeout(function(){GetDataAndPrintTableWiFi();}, 500);
|
||||
get_data("wifi");
|
||||
setupCollapsibleButtonsWiFi();
|
||||
</script>
|
||||
|
|
@ -68,6 +68,8 @@ function get_data(val) {
|
|||
}
|
||||
|
||||
if (val == "wifi") {
|
||||
document.getElementById('serviceapid').checked = obj.serviceap;
|
||||
$("#status_serviceap").text((obj.serviceap == "true") ? "On" : "Off");
|
||||
$("#ssid").text(obj.ssid);
|
||||
$("#rssi").text(obj.rssi);
|
||||
$("#rssi_percentage").text(obj.rssi_percentage);
|
||||
|
|
@ -446,3 +448,15 @@ function setupCollapsibleButtons() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setupCollapsibleButtonsWiFi() {
|
||||
$(".btn_collapsible_wifi").click(function(){
|
||||
$(this).toggleClass("active");
|
||||
var content_wifi = $(this).parent().next();
|
||||
if (content_wifi.css("display") === "block") {
|
||||
content_wifi.css("display", "none");
|
||||
} else {
|
||||
content_wifi.css("display", "block");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,6 +287,9 @@ cfg_bar li a:hover {
|
|||
table-layout: fixed;
|
||||
text-align: left;
|
||||
}
|
||||
#wificfg_tb {
|
||||
margin-left: 30%;
|
||||
}
|
||||
/* wifi_ntw table */
|
||||
#wifi_ntw {
|
||||
font: normal normal normal 12px/5px sans-serif;
|
||||
|
|
@ -498,3 +501,23 @@ cfg_bar li a:hover {
|
|||
background-color: #FA6831;
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* advanced wifi cfg */
|
||||
.content_wifi {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.btn_collapsible_wifi {
|
||||
width: 300px;
|
||||
height: 24px;
|
||||
text-align: center;
|
||||
font: normal normal bold 14px/5px sans-serif;
|
||||
color: #000000;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #343a40;
|
||||
}
|
||||
.btn_collapsible_wifi:hover {
|
||||
background-color: #FA6831;
|
||||
color: white;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue