mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
rssi shows real rssi and wifistrength shows % in heartbeat
This commit is contained in:
@@ -439,14 +439,6 @@ void System::show_mem(const char * note) {
|
|||||||
|
|
||||||
// create the json for heartbeat
|
// create the json for heartbeat
|
||||||
bool System::heartbeat_json(JsonObject & doc) {
|
bool System::heartbeat_json(JsonObject & doc) {
|
||||||
int8_t rssi;
|
|
||||||
if (!ethernet_connected_) {
|
|
||||||
rssi = wifi_quality();
|
|
||||||
if (rssi == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ems_status = EMSESP::bus_status();
|
uint8_t ems_status = EMSESP::bus_status();
|
||||||
if (ems_status == EMSESP::BUS_STATUS_TX_ERRORS) {
|
if (ems_status == EMSESP::BUS_STATUS_TX_ERRORS) {
|
||||||
doc["status"] = FJSON("txerror");
|
doc["status"] = FJSON("txerror");
|
||||||
@@ -456,12 +448,9 @@ bool System::heartbeat_json(JsonObject & doc) {
|
|||||||
doc["status"] = FJSON("disconnected");
|
doc["status"] = FJSON("disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ethernet_connected_) {
|
|
||||||
doc["rssi"] = rssi;
|
|
||||||
}
|
|
||||||
doc["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
doc["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
||||||
doc["uptime_sec"] = uuid::get_uptime_sec();
|
|
||||||
|
|
||||||
|
doc["uptime_sec"] = uuid::get_uptime_sec();
|
||||||
doc["rxreceived"] = EMSESP::rxservice_.telegram_count();
|
doc["rxreceived"] = EMSESP::rxservice_.telegram_count();
|
||||||
doc["rxfails"] = EMSESP::rxservice_.telegram_error_count();
|
doc["rxfails"] = EMSESP::rxservice_.telegram_error_count();
|
||||||
doc["txread"] = EMSESP::txservice_.telegram_read_count();
|
doc["txread"] = EMSESP::txservice_.telegram_read_count();
|
||||||
@@ -473,6 +462,7 @@ bool System::heartbeat_json(JsonObject & doc) {
|
|||||||
if (EMSESP::dallas_enabled()) {
|
if (EMSESP::dallas_enabled()) {
|
||||||
doc["dallasfails"] = EMSESP::sensor_fails();
|
doc["dallasfails"] = EMSESP::sensor_fails();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
doc["freemem"] = ESP.getFreeHeap() / 1000L; // kilobytes
|
doc["freemem"] = ESP.getFreeHeap() / 1000L; // kilobytes
|
||||||
#endif
|
#endif
|
||||||
@@ -481,7 +471,15 @@ bool System::heartbeat_json(JsonObject & doc) {
|
|||||||
doc["adc"] = analog_;
|
doc["adc"] = analog_;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (doc.size() > 0);
|
#ifndef EMSESP_STANDALONE
|
||||||
|
if (!ethernet_connected_) {
|
||||||
|
int8_t rssi = WiFi.RSSI();
|
||||||
|
doc["rssi"] = rssi;
|
||||||
|
doc["wifistrength"] = wifi_quality(rssi);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send periodic MQTT message with system information
|
// send periodic MQTT message with system information
|
||||||
@@ -649,19 +647,12 @@ void System::led_monitor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the quality (Received Signal Strength Indicator) of the WiFi network as a %. Or -1 if disconnected.
|
// Return the quality (Received Signal Strength Indicator) of the WiFi network as a %
|
||||||
// High quality: 90% ~= -55dBm
|
// High quality: 90% ~= -55dBm
|
||||||
// Medium quality: 50% ~= -75dBm
|
// Medium quality: 50% ~= -75dBm
|
||||||
// Low quality: 30% ~= -85dBm
|
// Low quality: 30% ~= -85dBm
|
||||||
// Unusable quality: 8% ~= -96dBm
|
// Unusable quality: 8% ~= -96dBm
|
||||||
int8_t System::wifi_quality() {
|
int8_t System::wifi_quality(int8_t dBm) {
|
||||||
#ifdef EMSESP_STANDALONE
|
|
||||||
return 100;
|
|
||||||
#else
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int32_t dBm = WiFi.RSSI();
|
|
||||||
if (dBm <= -100) {
|
if (dBm <= -100) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -670,7 +661,6 @@ int8_t System::wifi_quality() {
|
|||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
return 2 * (dBm + 100);
|
return 2 * (dBm + 100);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print users to console
|
// print users to console
|
||||||
@@ -714,7 +704,7 @@ void System::show_system(uuid::console::Shell & shell) {
|
|||||||
shell.printfln(F("WiFi: Connected"));
|
shell.printfln(F("WiFi: Connected"));
|
||||||
shell.printfln(F("SSID: %s"), WiFi.SSID().c_str());
|
shell.printfln(F("SSID: %s"), WiFi.SSID().c_str());
|
||||||
shell.printfln(F("BSSID: %s"), WiFi.BSSIDstr().c_str());
|
shell.printfln(F("BSSID: %s"), WiFi.BSSIDstr().c_str());
|
||||||
shell.printfln(F("RSSI: %d dBm (%d %%)"), WiFi.RSSI(), wifi_quality());
|
shell.printfln(F("RSSI: %d dBm (%d %%)"), WiFi.RSSI(), wifi_quality(WiFi.RSSI()));
|
||||||
shell.printfln(F("MAC address: %s"), WiFi.macAddress().c_str());
|
shell.printfln(F("MAC address: %s"), WiFi.macAddress().c_str());
|
||||||
shell.printfln(F("Hostname: %s"), WiFi.getHostname());
|
shell.printfln(F("Hostname: %s"), WiFi.getHostname());
|
||||||
shell.printfln(F("IPv4 address: %s/%s"), uuid::printable_to_string(WiFi.localIP()).c_str(), uuid::printable_to_string(WiFi.subnetMask()).c_str());
|
shell.printfln(F("IPv4 address: %s/%s"), uuid::printable_to_string(WiFi.localIP()).c_str(), uuid::printable_to_string(WiFi.subnetMask()).c_str());
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class System {
|
|||||||
void system_check();
|
void system_check();
|
||||||
void measure_analog();
|
void measure_analog();
|
||||||
|
|
||||||
int8_t wifi_quality();
|
int8_t wifi_quality(int8_t dBm);
|
||||||
|
|
||||||
bool system_healthy_ = false;
|
bool system_healthy_ = false;
|
||||||
uint32_t led_flash_speed_ = LED_WARNING_BLINK_FAST; // default boot flashes quickly
|
uint32_t led_flash_speed_ = LED_WARNING_BLINK_FAST; // default boot flashes quickly
|
||||||
|
|||||||
Reference in New Issue
Block a user