Skip to content

Commit 0ad8696

Browse files
authored
WebUI status line for MQTT and TLS, added 'FUNC_WEB_STATUS' event (#23326)
* WebUI status line for MQTT and TLS, added 'FUNC_WEB_STATUS' event * add Berry support
1 parent 6344c46 commit 0ad8696

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77
### Added
88
- Command `JsonPP 0..7` to enable (>0) JSON Pretty Print on user interfaces and set number of indents
99
- Command `JsonPP <command>|backlog <command>;...` to enable JSON PP only once
10+
- WebUI status line for MQTT and TLS, added `FUNC_WEB_STATUS` event
1011

1112
### Breaking Changed
1213

tasmota/include/tasmota.h

+1
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ enum XsnsFunctions { FUNC_SETTINGS_OVERRIDE, FUNC_SETUP_RING1, FUNC_SETUP_RING2,
442442
FUNC_WEB_GET_ARG, FUNC_WEB_ADD_HANDLER, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN, FUNC_TIME_SYNCED,
443443
FUNC_DEVICE_GROUP_ITEM,
444444
FUNC_NETWORK_UP, FUNC_NETWORK_DOWN,
445+
FUNC_WEB_STATUS,
445446
FUNC_return_result = 200, // Insert function WITHOUT return results before here. Following functions return results
446447
FUNC_PIN_STATE, FUNC_MODULE_INIT, FUNC_ADD_BUTTON, FUNC_ADD_SWITCH, FUNC_BUTTON_PRESSED, FUNC_BUTTON_MULTI_PRESSED,
447448
FUNC_SET_DEVICE_POWER,

tasmota/my_user_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@
503503
#define WEB_USERNAME "admin" // Web server Admin mode user name
504504
// #define DISABLE_REFERER_CHK // [SetOption128] Disable HTTP API
505505
#define USE_ENHANCED_GUI_WIFI_SCAN // Enable Wi-Fi scan output with BSSID (+0k5 code)
506+
#define USE_WEB_STATUS_LINE // Enable upper status line in web UI (+0k5 code)
506507
// #define USE_ALPINEJS // Enable AlpineJS v2.8.2 (+8k8 code)
507508
// #define USE_WEBSEND_RESPONSE // Enable command WebSend response message (+1k code)
508509
// #define USE_WEBGETCONFIG // Enable restoring config from external webserver (+0k6)

tasmota/tasmota_support/support_command.ino

+10
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ void CmndStatus(void)
952952
CmndStatusResponse(0);
953953
}
954954

955+
// Status 1 - StatusPRM
955956
if ((0 == payload) || (1 == payload)) {
956957
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS1_PARAMETER "\":{\"" D_JSON_BAUDRATE "\":%d,\"" D_CMND_SERIALCONFIG "\":\"%s\",\"" D_CMND_GROUPTOPIC "\":\"%s\",\"" D_CMND_OTAURL "\":\"%s\",\""
957958
D_JSON_RESTARTREASON "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\",\"" D_JSON_STARTUPUTC "\":\"%s\",\"" D_CMND_SLEEP "\":%d,\""
@@ -970,6 +971,7 @@ void CmndStatus(void)
970971
CmndStatusResponse(1);
971972
}
972973

974+
// Status 2 - StatusFWR
973975
if ((0 == payload) || (2 == payload)) {
974976
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS2_FIRMWARE "\":{\"" D_JSON_VERSION "\":\"%s%s%s\",\"" D_JSON_BUILDDATETIME "\":\"%s\""
975977
#ifdef ESP8266
@@ -988,6 +990,7 @@ void CmndStatus(void)
988990
CmndStatusResponse(2);
989991
}
990992

993+
// Status 3 - StatusLOG
991994
if ((0 == payload) || (3 == payload)) {
992995
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS3_LOGGING "\":{\"" D_CMND_SERIALLOG "\":%d,\"" D_CMND_WEBLOG "\":%d,\"" D_CMND_MQTTLOG "\":%d,\""
993996
#ifdef USE_UFILESYS
@@ -1007,6 +1010,7 @@ void CmndStatus(void)
10071010
CmndStatusResponse(3);
10081011
}
10091012

1013+
// Status 4 - StatusMEM
10101014
if ((0 == payload) || (4 == payload)) {
10111015
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS4_MEMORY "\":{\"" D_JSON_PROGRAMSIZE "\":%d,\"" D_JSON_FREEMEMORY "\":%d,\"" D_JSON_HEAPSIZE "\":%d,\""
10121016
#ifdef ESP32
@@ -1037,6 +1041,7 @@ void CmndStatus(void)
10371041
CmndStatusResponse(4);
10381042
}
10391043

1044+
// Status 5 - StatusNET
10401045
if ((0 == payload) || (5 == payload)) {
10411046
#ifdef USE_IPV6
10421047
if (5 == payload) { WifiDumpAddressesIPv6(); }
@@ -1093,6 +1098,7 @@ void CmndStatus(void)
10931098
CmndStatusResponse(5);
10941099
}
10951100

1101+
// Status 6 - StatusMQT
10961102
if (((0 == payload) || (6 == payload)) && Settings->flag.mqtt_enabled) { // SetOption3 - Enable MQTT
10971103
uint32_t mqtt_tls = 0;
10981104
#ifdef USE_MQTT_TLS
@@ -1134,13 +1140,15 @@ void CmndStatus(void)
11341140
}
11351141
#endif // USE_ENERGY_MARGIN_DETECTION
11361142

1143+
// Status 8 / 10 - StatusSNS
11371144
if ((0 == payload) || (8 == payload) || (10 == payload)) {
11381145
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS10_SENSOR "\":"));
11391146
MqttShowSensor(true);
11401147
ResponseJsonEnd();
11411148
CmndStatusResponse((8 == payload) ? 8 : 10);
11421149
}
11431150

1151+
// Status 11 - StatusSTS
11441152
if ((0 == payload) || (11 == payload)) {
11451153
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS11_STATUS "\":"));
11461154
MqttShowState();
@@ -1150,6 +1158,7 @@ void CmndStatus(void)
11501158

11511159
#ifndef FIRMWARE_MINIMAL
11521160
if (CrashFlag()) {
1161+
// Status 12 - StatusSTK
11531162
if ((0 == payload) || (12 == payload)) {
11541163
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS12_STATUS "\":"));
11551164
CrashDump();
@@ -1160,6 +1169,7 @@ void CmndStatus(void)
11601169
#endif // FIRMWARE_MINIMAL
11611170

11621171
#ifdef USE_SHUTTER
1172+
// Status 13
11631173
if ((0 == payload) || (13 == payload)) {
11641174
if (ShutterStatus()) { CmndStatusResponse(13); }
11651175
}

tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino

+50-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const char HTTP_HEAD_STYLE3[] PROGMEM =
251251

252252
"</head>"
253253
"<body>"
254-
"<div style='background:#%06x;text-align:left;display:inline-block;color:#%06x;min-width:340px;'>" // COLOR_BACKGROUND, COLOR_TEXT
254+
"<div style='background:#%06x;text-align:left;display:inline-block;color:#%06x;min-width:340px;position:relative;'>" // COLOR_BACKGROUND, COLOR_TEXT
255255
#ifdef FIRMWARE_MINIMAL
256256
#ifdef FIRMWARE_SAFEBOOT
257257
"<span style='text-align:center;color:#%06x;'><h3>" D_SAFEBOOT "</h3></span>" // COLOR_TEXT_WARNING
@@ -445,6 +445,18 @@ const char HTTP_END[] PROGMEM =
445445
const char HTTP_DEVICE_CONTROL[] PROGMEM = "<td style='width:%d%%'><button id='o%d' onclick='la(\"&o=%d\");'>%s%s</button></td>"; // ?o is related to WebGetArg(PSTR("o"), tmp, sizeof(tmp))
446446
const char HTTP_DEVICE_STATE[] PROGMEM = "<td style='width:%d%%;text-align:center;font-weight:%s;font-size:%dpx'>%s</td>";
447447

448+
const char HTTP_STATUS_STICKER[] PROGMEM =
449+
"<span style='"
450+
"margin:2px;"
451+
"cursor:default;"
452+
"padding:1px 2px;"
453+
"border-color:#%06x;border-radius:5px;border-style:solid;border-width:1px;"
454+
"' "
455+
"%s" // optional 'title' attributes
456+
">"
457+
"%s"
458+
"</span>";
459+
448460
enum ButtonTitle {
449461
BUTTON_RESTART, BUTTON_RESET_CONFIGURATION,
450462
BUTTON_MAIN, BUTTON_CONFIGURATION, BUTTON_INFORMATION, BUTTON_FIRMWARE_UPGRADE, BUTTON_MANAGEMENT,
@@ -1151,6 +1163,36 @@ void WSContentStop(void) {
11511163
WSContentEnd();
11521164
}
11531165

1166+
#ifdef USE_WEB_STATUS_LINE
1167+
/*-------------------------------------------------------------------------------------------*/
1168+
// Display a Sticker in the Status bar (upper right) with a name (MQTT, TlS, VPN)
1169+
// and an optional tooltip text to indicate the duration of the connection (or -1 if none)
1170+
//
1171+
// Convert seconds to a string representing days, hours or minutes.
1172+
// The string will contain the most coarse time only, rounded down (61m == 01h, 01h37m == 01h).
1173+
void WSContentStatusSticker(const char *msg, int32_t seconds)
1174+
{
1175+
char title_attr[64] = "";
1176+
1177+
if (seconds > 0) {
1178+
static const uint32_t conversions[4] = {24 * 3600, 3600, 60, 1};
1179+
static const char units[4] = { 'd', 'h', 'm', 's'}; // day, hour, minute
1180+
1181+
char unit;
1182+
int32_t time_unit = seconds;
1183+
for(uint32_t i = 0; i < 4; ++i) {
1184+
unit = units[i];
1185+
if (time_unit >= conversions[i]) { // always pass even if 00m
1186+
time_unit = seconds / conversions[i];
1187+
break;
1188+
}
1189+
}
1190+
ext_snprintf_P(title_attr, sizeof(title_attr), PSTR(" title='Connected for %i%c'"), time_unit, unit);
1191+
}
1192+
WSContentSend_P(HTTP_STATUS_STICKER, 0xAAAAAA, title_attr, msg);
1193+
}
1194+
#endif // USE_WEB_STATUS_LINE
1195+
11541196
/*********************************************************************************************/
11551197

11561198
void WebRestart(uint32_t type) {
@@ -1884,6 +1926,13 @@ bool HandleRootStatusRefresh(void) {
18841926
WSContentSend_P(PSTR("\">"));
18851927
}
18861928

1929+
#ifdef USE_WEB_STATUS_LINE
1930+
// create a DIV for the upper status bar, positioned right-justified
1931+
WSContentSend_P(PSTR("<div style='font-size:9px;font-weight:bold;text-align:right;position:absolute;top:0;right:0;display:inline-flex;'>"));
1932+
XsnsXdrvCall(FUNC_WEB_STATUS);
1933+
WSContentSend_P(PSTR("</div>"));
1934+
#endif // USE_WEB_STATUS_LINE
1935+
18871936
WSContentSend_P(PSTR("{t}")); // <table style='width:100%'>
18881937
WSContentSeparator(3); // Reset seperator to ignore previous outputs
18891938
if (Settings->web_time_end) {

tasmota/tasmota_xdrv_driver/xdrv_02_9_mqtt.ino

+11
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,17 @@ bool Xdrv02(uint32_t function)
21162116
case FUNC_WEB_ADD_HANDLER:
21172117
WebServer_on(PSTR("/" WEB_HANDLE_MQTT), HandleMqttConfiguration);
21182118
break;
2119+
#ifdef USE_WEB_STATUS_LINE
2120+
case FUNC_WEB_STATUS:
2121+
// MqttConnectCount(), mqtt_tls
2122+
if (MqttIsConnected()) {
2123+
WSContentStatusSticker(PSTR("MQTT"), -1);
2124+
if (MqttTLSEnabled()) {
2125+
WSContentStatusSticker(PSTR("TLS"), -1);
2126+
}
2127+
}
2128+
break;
2129+
#endif // USE_WEB_STATUS_LINE
21192130
#endif // not FIRMWARE_MINIMAL
21202131
#endif // USE_WEBSERVER
21212132
case FUNC_COMMAND:

tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino

+5
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,11 @@ bool Xdrv52(uint32_t function)
10611061
WebServer_on("/bc", HandleBerryConsole);
10621062
WebServer_on("/tapp", HandleBerryBECLoader, HTTP_GET);
10631063
break;
1064+
#ifdef USE_WEB_STATUS_LINE
1065+
case FUNC_WEB_STATUS:
1066+
callBerryEventDispatcher(PSTR("web_status_line"), nullptr, 0, nullptr);
1067+
break;
1068+
#endif // USE_WEB_STATUS_LINE
10641069
#endif // USE_WEBSERVER
10651070
case FUNC_SAVE_BEFORE_RESTART:
10661071
callBerryEventDispatcher(PSTR("save_before_restart"), nullptr, 0, nullptr);

0 commit comments

Comments
 (0)