From b60d76bef4930bee3e525a6f4a81b75f95c247f6 Mon Sep 17 00:00:00 2001
From: fvanroie <15969459+fvanroie@users.noreply.github.com>
Date: Sat, 1 May 2021 19:36:09 +0200
Subject: [PATCH] Text localization information webpage
---
src/hasp/hasp.cpp | 20 ++++++++++----------
src/mqtt/hasp_mqtt_paho_single.cpp | 22 +++++++++++-----------
src/mqtt/hasp_mqtt_pubsubclient.cpp | 18 +++++++++---------
src/sys/net/hasp_ethernet_esp32.cpp | 20 ++++++++++----------
src/sys/net/hasp_wifi.cpp | 23 ++++++++++-------------
5 files changed, 50 insertions(+), 53 deletions(-)
diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp
index 94ea8b7d..dbd78ec9 100644
--- a/src/hasp/hasp.cpp
+++ b/src/hasp/hasp.cpp
@@ -581,13 +581,13 @@ void hasp_get_info(JsonDocument& doc)
JsonObject info = doc.createNestedObject(F(D_MANUFACTURER));
haspGetVersion(size_buf, sizeof(size_buf));
- info[F("Version")] = size_buf;
+ info[F(D_INFO_VERSION)] = size_buf;
buffer = __DATE__;
buffer += (" ");
buffer += __TIME__;
buffer += (" UTC"); // Github buildservers are in UTC
- info[F("Build DateTime")] = buffer;
+ info[F(D_INFO_BUILD_DATETIME)] = buffer;
unsigned long time = millis() / 1000;
uint16_t day = time / 86400;
@@ -617,21 +617,21 @@ void hasp_get_info(JsonDocument& doc)
itoa(sec, size_buf, DEC);
buffer += size_buf;
buffer += "s";
- info[F("Uptime")] = buffer;
+ info[F(D_INFO_UPTIME)] = buffer;
info = doc.createNestedObject(F("Device Memory"));
Parser::format_bytes(haspDevice.get_free_heap(), size_buf, sizeof(size_buf));
- info[F("Free Heap")] = size_buf;
+ info[F(D_INFO_FREE_HEAP)] = size_buf;
Parser::format_bytes(haspDevice.get_free_max_block(), size_buf, sizeof(size_buf));
- info[F("Free Block")] = size_buf;
- info[F("Fragmentation")] = haspDevice.get_heap_fragmentation();
+ info[F(D_INFO_FREE_BLOCK)] = size_buf;
+ info[F(D_INFO_FRAGMENTATION)] = haspDevice.get_heap_fragmentation();
#if ARDUINO_ARCH_ESP32
if(psramFound()) {
Parser::format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf));
- info[F("Free PSRam")] = size_buf;
+ info[F(D_INFO_PSRAM_FREE)] = size_buf;
Parser::format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf));
- info[F("PSRam Size")] = size_buf;
+ info[F(D_INFO_PSRAM_SIZE)] = size_buf;
}
#endif
@@ -641,8 +641,8 @@ void hasp_get_info(JsonDocument& doc)
Parser::format_bytes(mem_mon.total_size, size_buf, sizeof(size_buf));
info[F("Total")] = size_buf;
Parser::format_bytes(mem_mon.free_size, size_buf, sizeof(size_buf));
- info[F("Free")] = size_buf;
- info[F("Fragmentation")] = mem_mon.frag_pct;
+ info[F("Free")] = size_buf;
+ info[F(D_INFO_FRAGMENTATION)] = mem_mon.frag_pct;
info = doc.createNestedObject(F("HASP State"));
hasp_get_sleep_state(size_buf);
diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp
index 57f3a1c4..7b28e2bb 100644
--- a/src/mqtt/hasp_mqtt_paho_single.cpp
+++ b/src/mqtt/hasp_mqtt_paho_single.cpp
@@ -321,7 +321,7 @@ void mqttStart()
conn_opts.password = mqttPassword.c_str();
if((rc = MQTTClient_connect(mqtt_client, &conn_opts)) != MQTTCLIENT_SUCCESS) {
- printf("Failed to start connect, return code %d\n", rc);
+ printf("Failed to connect, return code %d\n", rc);
rc = EXIT_FAILURE;
// goto destroy_exit;
} else {
@@ -346,7 +346,7 @@ void mqttStop()
// disc_opts.onSuccess = onDisconnect;
// disc_opts.onFailure = onDisconnectFailure;
if((rc = MQTTClient_disconnect(mqtt_client, 1000)) != MQTTCLIENT_SUCCESS) {
- printf("Failed to start disconnect, return code %d\n", rc);
+ printf("Failed to disconnect, return code %d\n", rc);
rc = EXIT_FAILURE;
// goto destroy_exit;
}
@@ -397,21 +397,21 @@ void mqtt_get_info(JsonDocument& doc)
{
char mqttClientId[64];
- JsonObject info = doc.createNestedObject(F("MQTT"));
- info[F("Server")] = mqttServer;
- info[F("User")] = mqttUser;
- info[F("ClientID")] = haspDevice.get_hostname();
+ JsonObject info = doc.createNestedObject(F("MQTT"));
+ info[F(D_INFO_SERVER)] = mqttServer;
+ info[F(D_INFO_USERNAME)] = mqttUser;
+ info[F(D_INFO_CLIENTID)] = haspDevice.get_hostname();
if(mqttIsConnected()) { // Check MQTT connection
- info[F("Status")] = F("Connected");
+ info[F(D_INFO_STATUS)] = F(D_INFO_CONNECTED);
} else {
- info[F("Status")] = F("Disconnected, return code: ");
+ info[F(D_INFO_STATUS)] = F("" D_INFO_DISCONNECTED ", return code: ");
// +String(mqttClient.returnCode());
}
- info[F("Received")] = mqttReceiveCount;
- info[F("Published")] = mqttPublishCount;
- info[F("Failed")] = mqttFailedCount;
+ info[F(D_INFO_RECEIVED)] = mqttReceiveCount;
+ info[F(D_INFO_PUBLISHED)] = mqttPublishCount;
+ info[F(D_INFO_FAILED)] = mqttFailedCount;
}
#endif // USE_PAHO
diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp
index b25aaf2b..354fd6ab 100644
--- a/src/mqtt/hasp_mqtt_pubsubclient.cpp
+++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp
@@ -385,25 +385,25 @@ void mqtt_get_info(JsonDocument& doc)
String mac((char*)0);
mac.reserve(64);
- JsonObject info = doc.createNestedObject(F("MQTT"));
- info[F("Server")] = mqttServer;
- info[F("User")] = mqttUser;
+ JsonObject info = doc.createNestedObject(F("MQTT"));
+ info[F(D_INFO_SERVER)] = mqttServer;
+ info[F(D_INFO_USERNAME)] = mqttUser;
mac = halGetMacAddress(3, "");
mac.toLowerCase();
snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%s"), haspDevice.get_hostname(), mac.c_str());
- info[F("ClientID")] = mqttClientId;
+ info[F(D_INFO_CLIENTID)] = mqttClientId;
if(mqttIsConnected()) { // Check MQTT connection
- info[F("Status")] = F("Connected");
+ info[F(D_INFO_STATUS)] = F(D_INFO_CONNECTED);
} else {
- info[F("Status")] = F("Disconnected, return code: ");
+ info[F(D_INFO_STATUS)] = F("" D_INFO_DISCONNECTED ", return code: ");
// +String(mqttClient.returnCode());
}
- info[F("Received")] = mqttReceiveCount;
- info[F("Published")] = mqttPublishCount;
- info[F("Failed")] = mqttFailedCount;
+ info[F(D_INFO_RECEIVED)] = mqttReceiveCount;
+ info[F(D_INFO_PUBLISHED)] = mqttPublishCount;
+ info[F(D_INFO_FAILED)] = mqttFailedCount;
}
#if HASP_USE_CONFIG > 0
diff --git a/src/sys/net/hasp_ethernet_esp32.cpp b/src/sys/net/hasp_ethernet_esp32.cpp
index 87947064..00737dfe 100644
--- a/src/sys/net/hasp_ethernet_esp32.cpp
+++ b/src/sys/net/hasp_ethernet_esp32.cpp
@@ -25,13 +25,13 @@ void EthernetEvent(WiFiEvent_t event)
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_GOT_IP:
- LOG_TRACE(TAG_ETH, F("MAC Address %s"), ETH.macAddress().c_str());
+ LOG_TRACE(TAG_ETH, F(D_INFO_MAC_ADDRESS " %s"), ETH.macAddress().c_str());
ip = ETH.localIP();
LOG_TRACE(TAG_ETH, F("IPv4: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
if(ETH.fullDuplex()) {
- LOG_TRACE(TAG_ETH, F("FULL_DUPLEX"));
+ LOG_TRACE(TAG_ETH, F(D_INFO_FULL_DUPLEX));
}
- LOG_TRACE(TAG_ETH, F("LINK_SPEED %d Mbps"), ETH.linkSpeed());
+ LOG_TRACE(TAG_ETH, F(D_INFO_LINK_SPEED " %d Mbps"), ETH.linkSpeed());
eth_connected = true;
networkStart(); // Start network services
break;
@@ -76,19 +76,19 @@ void ethernet_get_info(JsonDocument& doc)
String buffer((char*)0);
buffer.reserve(64);
- JsonObject info = doc.createNestedObject(F("Ethernet"));
+ JsonObject info = doc.createNestedObject(F(D_INFO_ETHERNET));
buffer = ETH.linkSpeed();
buffer += F(" Mbps");
if(ETH.fullDuplex()) {
- buffer += F(" FULL_DUPLEX");
+ buffer += F(" " D_INFO_FULL_DUPLEX);
}
- info[F("Link Speed")] = buffer;
- info[F("IP Address")] = ETH.localIP().toString();
- info[F("Gateway")] = ETH.gatewayIP().toString();
- info[F("DNS Server")] = ETH.dnsIP().toString();
- info[F("MAC Address")] = ETH.macAddress();
+ info[F(D_INFO_LINK_SPEED)] = buffer;
+ info[F(D_INFO_IP_ADDRESS)] = ETH.localIP().toString();
+ info[F(D_INFO_GATEWAY)] = ETH.gatewayIP().toString();
+ info[F(D_INFO_DNS_SERVER)] = ETH.dnsIP().toString();
+ info[F(D_INFO_MAC_ADDRESS)] = ETH.macAddress();
}
#endif
\ No newline at end of file
diff --git a/src/sys/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp
index af74b724..a58ffde6 100644
--- a/src/sys/net/hasp_wifi.cpp
+++ b/src/sys/net/hasp_wifi.cpp
@@ -524,7 +524,7 @@ void wifi_get_info(JsonDocument& doc)
String buffer((char*)0);
buffer.reserve(64);
- JsonObject info = doc.createNestedObject(F("Wifi"));
+ JsonObject info = doc.createNestedObject(F(D_INFO_WIFI));
int8_t rssi = WiFi.RSSI();
buffer += String(rssi);
@@ -542,25 +542,22 @@ void wifi_get_info(JsonDocument& doc)
buffer += F("Very Bad)");
}
- info[F("SSID")] = String(WiFi.SSID());
- info[F("Signal Strength")] = buffer;
+ info[F(D_INFO_SSID)] = String(WiFi.SSID());
+ info[F(D_INFO_RSSI)] = buffer;
#if defined(STM32F4xx)
byte mac[6];
WiFi.macAddress(mac);
char macAddress[16];
snprintf_P(macAddress, sizeof(macAddress), PSTR("%02x%02x%02x"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- httpMessage += F("IP Address: ");
- httpMessage += String(WiFi.localIP());
- httpMessage += F("Gateway: ");
- httpMessage += String(WiFi.gatewayIP());
- httpMessage += F("MAC Address: ");
- httpMessage += String(macAddress);
+ info[F(D_INFO_IP_ADDRESS)] = String(WiFi.localIP());
+ info[F(D_INFO_GATEWAY)] = String(WiFi.gatewayIP());
+ info[F(D_INFO_MAC_ADDRESS)] = String(macAddress);
#else
- info[F("IP Address")] = WiFi.localIP().toString();
- info[F("Gateway")] = WiFi.gatewayIP().toString();
- info[F("DNS Server")] = WiFi.dnsIP().toString();
- info[F("MAC Address")] = WiFi.macAddress();
+ info[F(D_INFO_IP_ADDRESS)] = WiFi.localIP().toString();
+ info[F(D_INFO_GATEWAY)] = WiFi.gatewayIP().toString();
+ info[F(D_INFO_DNS_SERVER)] = WiFi.dnsIP().toString();
+ info[F(D_INFO_MAC_ADDRESS)] = WiFi.macAddress();
#endif
}