Skip to content

Commit

Permalink
wifi connection status
Browse files Browse the repository at this point in the history
  • Loading branch information
dontsovcmc committed Sep 15, 2023
1 parent d69d7b8 commit c23c65a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
26 changes: 19 additions & 7 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,35 +2464,47 @@ void WiFiManager::handleClose(){
void WiFiManager::reportStatus(String &page){
// updateConxResult(WiFi.status()); // @todo: this defeats the purpose of last result, update elsewhere or add logic here
DEBUG_WM(DEBUG_DEV,F("[WIFI] reportStatus prev:"),getWLStatusString(_lastconxresult));
DEBUG_WM(DEBUG_DEV,F("[WIFI] reportStatus current:"),getWLStatusString(WiFi.status()));
uint8_t current_status = WiFi.status();
DEBUG_WM(DEBUG_DEV,F("[WIFI] reportStatus current:"),getWLStatusString(current_status));
String str;
if (WiFi_SSID() != ""){
if (WiFi.status()==WL_CONNECTED){
if (current_status==WL_CONNECTED){
str = FPSTR(HTTP_STATUS_ON);
str.replace(FPSTR(T_i),WiFi.localIP().toString());
str.replace(FPSTR(T_v),htmlEntities(WiFi_SSID()));
}
else {
str = FPSTR(HTTP_STATUS_OFF);
str.replace(FPSTR(T_v),htmlEntities(WiFi_SSID()));
if(_lastconxresult == WL_STATION_WRONG_PASSWORD){
if(current_status == WL_STATION_WRONG_PASSWORD){
// wrong password
str.replace(FPSTR(T_c),"D"); // class
str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFPW));
}
else if(_lastconxresult == WL_NO_SSID_AVAIL){
else if(current_status == WL_NO_SSID_AVAIL){
// connect failed, or ap not found
str.replace(FPSTR(T_c),"D");
str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFNOAP));
}
else if(_lastconxresult == WL_CONNECT_FAILED){
else if(current_status == WL_CONNECT_FAILED){
// connect failed
str.replace(FPSTR(T_c),"D");
str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFFAIL));
}
else if(current_status == WL_CONNECTION_LOST){
// was reboot, initializing
str.replace(FPSTR(T_c),"D");
str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_CONNECTION_LOST));
}
else if(current_status == WL_IDLE_STATUS){
// was reboot, initializing
str.replace(FPSTR(T_c),"D");
str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_IDLE_STATUS));
}
else{
str.replace(FPSTR(T_c),"");
str.replace(FPSTR(T_r),"");
String s = F("код: ") + String(current_status);
str.replace(FPSTR(T_c),"D");
str.replace(FPSTR(T_r), s);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ class WiFiManager
String getIpForm(String id, String title, String value);
public:
void getScanItemOut(String &page);
void reportStatus(String &page);
private:
void getStaticOut(String &page);
String getHTTPHead(const String &title);
Expand All @@ -749,7 +750,6 @@ class WiFiManager
String toStringIp(IPAddress ip);
boolean validApPassword();
String encryptionTypeStr(uint8_t authmode);
void reportStatus(String &page);
String getInfoData(String id);

// flags
Expand Down
42 changes: 40 additions & 2 deletions wm_strings_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ const char HTTP_FORM_SELECT[] PROGMEM = "<select class='it' id='{i}' name='
const char HTTP_FORM_SELECT_CUSTOM[] PROGMEM = "<select class='slct' id='{i}' name='{n}'>{c}</select>";

const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi?refresh=1' method='POST'><button name='refresh' value='1'>Обновить</button></form>";


const char HTTP_SAVED[] PROGMEM = "<h1>Настройка</h1>"
"<h3>Подключение к Wi-Fi</h3>"
"<div>Статус: <div id='wifistatus'><p>Подключение...</p></div></div>"
"<p>При успешном подключении через 5&ndash;10&nbsp;секунд погаснет светодиод.</p>"
"<p>Нажмите коротко на&nbsp;кнопку, чтобы Ватериус отправил показания на&nbsp;сайт.</p>"
"<p>Если не&nbsp;удалось подключиться, начните с&nbsp;начала.</p>"
Expand All @@ -88,12 +91,47 @@ const char HTTP_STATUS_ON[] PROGMEM = "<div class='msg P'><strong>Под
const char HTTP_STATUS_OFF[] PROGMEM = "<div class='msg {c}'><strong>Отключен</strong> от {v}{r}</div>";
const char HTTP_STATUS_OFFPW[] PROGMEM = "<br/>Ошибка аутентификации"; // STATION_WRONG_PASSWORD, no eps32
const char HTTP_STATUS_OFFNOAP[] PROGMEM = "<br/>Точка доступа не найдена"; // WL_NO_SSID_AVAIL
const char HTTP_STATUS_OFFFAIL[] PROGMEM = "<br/>Нет соединения"; // WL_CONNECT_FAILED
const char HTTP_STATUS_OFFFAIL[] PROGMEM = "<br/>Ошибка подключения"; // WL_CONNECT_FAILED
const char HTTP_STATUS_CONNECTION_LOST[] PROGMEM = "<br/>Связь потеряна"; // WL_CONNECTION_LOST
const char HTTP_STATUS_IDLE_STATUS[] PROGMEM = "<br/>Требуется повторная настройка"; // WL_IDLE_STATUS
const char HTTP_STATUS_NONE[] PROGMEM = "<div class='msg'>Не указана точка доступа</div>";

const char HTTP_BR[] PROGMEM = "<br/>";

const char HTTP_END_SCRIPT[] PROGMEM = "<script>function send(b,c,d){let a=new XMLHttpRequest;a.open(\"GET\",b),a.timeout=c,a.onreadystatechange=function(b){4===a.readyState&&200===a.status&&d(a.responseText)},a.send()}window.onload=function(){function a(){send(\"/wifisave\",7e3,function(a){clearInterval(b)})}a();var b=setInterval(a,8e3)};</script>";
// HTTP_END_SCRIPT
/*
function g(n) {
return document.getElementById(n)
}
function send(n, e, t) {
const o = new XMLHttpRequest;
o.open("GET", n), o.timeout = e, o.onreadystatechange = function(n) {
4 === o.readyState && 200 === o.status && t(o.responseText)
}, o.send()
}
window.onload = function() {
function n() {
send("/wifistatus", 2e3, (function(n) {
var e = JSON.parse(n);
Object.keys(e).forEach((function(n) {
g(n) && (g(n).innerHTML = e[n])
}))
}))
}
n();
setInterval(n, 2e3);
function a() {
send("/wifisave", 7e3, function(a) {
clearInterval(b)
})
}
a();
var b = setInterval(a, 8e3);
};
*/
const char HTTP_END_SCRIPT[] PROGMEM = "<script>function g(n){return document.getElementById(n)}function send(n,e,t){const o=new XMLHttpRequest;o.open(\"GET\",n),o.timeout=e,o.onreadystatechange=function(n){4===o.readyState&&200===o.status&&t(o.responseText)},o.send()}window.onload=function(){function n(){send(\"/wifistatus\",2e3,(function(n){var e=JSON.parse(n);Object.keys(e).forEach((function(n){g(n)&&(g(n).innerHTML=e[n])}))}))}function e(){send(\"/wifisave\",7e3,(function(n){clearInterval(t)}))}n(),setInterval(n,2e3),e();var t=setInterval(e,8e3)};</script>";


#ifndef WM_NOHELP
Expand Down

0 comments on commit c23c65a

Please sign in to comment.