RSSI to web interface added

This commit is contained in:
Dmitry Borisenko
2020-11-16 13:58:26 +03:00
parent 2e73eac2f1
commit 3c3a4a33ca
5 changed files with 51 additions and 15 deletions

View File

@@ -7,11 +7,11 @@
"routerpass": "BELCHENKO", "routerpass": "BELCHENKO",
"timezone": 1, "timezone": 1,
"ntp": "pool.ntp.org", "ntp": "pool.ntp.org",
"mqttServer": "m12.cloudmqtt.com", "mqttServer": "wqtt.ru",
"mqttPort": 14053, "mqttPort": 8021,
"mqttPrefix": "/iotTest", "mqttPrefix": "/iotTest",
"mqttUser": "lbscvzuj", "mqttUser": "u_K1CK9Q",
"mqttPass": "bLxlveOgaF8F", "mqttPass": "YjyCloWS",
"scen": "1", "scen": "1",
"telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo", "telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo",
"telegonof": "0", "telegonof": "0",

View File

@@ -37,6 +37,10 @@
"type": "h4", "type": "h4",
"title": "Uptime: {{uptime}}" "title": "Uptime: {{uptime}}"
}, },
{
"type": "h4",
"title": "WiFi Signal: {{signal}}"
},
{ {
"type": "h4", "type": "h4",
"title": "Build version: {{firmware_version}}" "title": "Build version: {{firmware_version}}"

View File

@@ -10,3 +10,5 @@ bool startAPMode();
boolean RouterFind(String ssid); boolean RouterFind(String ssid);
String RSSIquality();

View File

@@ -11,8 +11,10 @@ void routerConnect() {
if (_ssid == "" && _password == "") { if (_ssid == "" && _password == "") {
WiFi.begin(); WiFi.begin();
} else { }
else {
WiFi.begin(_ssid.c_str(), _password.c_str()); WiFi.begin(_ssid.c_str(), _password.c_str());
WiFi.setOutputPower(20.5);
SerialPrint("I", "WIFI", "ssid: " + _ssid); SerialPrint("I", "WIFI", "ssid: " + _ssid);
} }
@@ -29,7 +31,8 @@ void routerConnect() {
if (WiFi.status() != WL_CONNECTED) { if (WiFi.status() != WL_CONNECTED) {
Serial.println(""); Serial.println("");
startAPMode(); startAPMode();
} else { }
else {
Serial.println(""); Serial.println("");
SerialPrint("I", "WIFI", "http://" + WiFi.localIP().toString()); SerialPrint("I", "WIFI", "http://" + WiFi.localIP().toString());
jsonWriteStr(configSetupJson, "ip", WiFi.localIP().toString()); jsonWriteStr(configSetupJson, "ip", WiFi.localIP().toString());
@@ -81,17 +84,17 @@ boolean RouterFind(String ssid) {
if (n == -2) { //Сканирование не было запущено, запускаем if (n == -2) { //Сканирование не было запущено, запускаем
SerialPrint("I", "WIFI", "start scanning"); SerialPrint("I", "WIFI", "start scanning");
WiFi.scanNetworks(true, false); //async, show_hidden WiFi.scanNetworks(true, false); //async, show_hidden
} }
else if (n == -1) { //Сканирование все еще выполняется else if (n == -1) { //Сканирование все еще выполняется
SerialPrint("I", "WIFI", "scanning in progress"); SerialPrint("I", "WIFI", "scanning in progress");
} }
else if (n == 0) { //ни одна сеть не найдена else if (n == 0) { //ни одна сеть не найдена
SerialPrint("I", "WIFI", "no networks found"); SerialPrint("I", "WIFI", "no networks found");
WiFi.scanNetworks(true, false); WiFi.scanNetworks(true, false);
} }
else if (n > 0) { else if (n > 0) {
for (int8_t i = 0; i < n; i++) { for (int8_t i = 0; i < n; i++) {
if (WiFi.SSID(i) == ssid) { if (WiFi.SSID(i) == ssid) {
@@ -107,3 +110,31 @@ boolean RouterFind(String ssid) {
boolean isNetworkActive() { boolean isNetworkActive() {
return WiFi.status() == WL_CONNECTED; return WiFi.status() == WL_CONNECTED;
} }
String RSSIquality() {
String res = "not connected";
if (WiFi.status() == WL_CONNECTED) {
int rssi = WiFi.RSSI();
if (rssi >= -50) {
res = "Excellent";
}
else if (rssi < -50 && rssi >= -60) {
res = "Very good";
}
else if (rssi < -60 && rssi >= -70) {
res = "Good";
}
else if (rssi < -70 && rssi >= -80) {
res = "Low";
}
else if (rssi < -80 && rssi > -100) {
res = "Very low";
}
else if (rssi <= -100) {
res = "No signal";
}
}
return res;
}

View File

@@ -94,18 +94,17 @@ void setup() {
SsdpInit(); SsdpInit();
#endif #endif
//esp_log_level_set("esp_littlefs", ESP_LOG_NONE); //esp_log_level_set("esp_littlefs", ESP_LOG_NONE);
ts.add( ts.add(
TEST, 1000 * 60, [&](void*) { TEST, 1000 * 60, [&](void*) {
SerialPrint("I", "System", printMemoryStatus()); SerialPrint("I", "System", printMemoryStatus());
jsonWriteStr(configSetupJson, "signal", RSSIquality());
}, },
nullptr, true); nullptr, true);
just_load = false; just_load = false;
initialized = true; initialized = true;
} }
void loop() { void loop() {