Removed loadInfo().

Fixed UI when no WS available.
This commit is contained in:
Blaz Kristan 2021-11-21 14:14:39 +01:00
parent 47caa2c3a0
commit 295663f6a6
11 changed files with 3543 additions and 3526 deletions

View File

@ -512,10 +512,10 @@ class Animated_Staircase : public Usermod {
JsonArray usermodEnabled = staircase.createNestedArray(F("Staircase")); // name JsonArray usermodEnabled = staircase.createNestedArray(F("Staircase")); // name
String btn = F("<button class=\"btn infobtn\" onclick=\"requestJson({staircase:{enabled:"); String btn = F("<button class=\"btn infobtn\" onclick=\"requestJson({staircase:{enabled:");
if (enabled) { if (enabled) {
btn += F("false}},false,false);loadInfo();\">"); btn += F("false}});\">");
btn += F("enabled"); btn += F("enabled");
} else { } else {
btn += F("true}},false,false);loadInfo();\">"); btn += F("true}});\">");
btn += F("disabled"); btn += F("disabled");
} }
btn += F("</button>"); btn += F("</button>");

View File

@ -279,10 +279,10 @@ public:
uiDomString += F(":{"); uiDomString += F(":{");
uiDomString += FPSTR(_enabled); uiDomString += FPSTR(_enabled);
if (enabled) { if (enabled) {
uiDomString += F(":false}});loadInfo();\">"); uiDomString += F(":false}});\">");
uiDomString += F("PIR <i class=\"icons\">&#xe325;</i>"); uiDomString += F("PIR <i class=\"icons\">&#xe325;</i>");
} else { } else {
uiDomString += F(":true}});loadInfo();\">"); uiDomString += F(":true}});\">");
uiDomString += F("PIR <i class=\"icons\">&#xe08f;</i>"); uiDomString += F("PIR <i class=\"icons\">&#xe08f;</i>");
} }
uiDomString += F("</button>"); uiDomString += F("</button>");

View File

@ -414,7 +414,7 @@ class MultiRelay : public Usermod {
uiDomString += i; uiDomString += i;
uiDomString += F(",on:"); uiDomString += F(",on:");
uiDomString += _relay[i].state ? "false" : "true"; uiDomString += _relay[i].state ? "false" : "true";
uiDomString += F("}});loadInfo();\">"); uiDomString += F("}});\">");
uiDomString += F("Relay "); uiDomString += F("Relay ");
uiDomString += i; uiDomString += i;
uiDomString += F(" <i class=\"icons\">&#xe08f;</i></button>"); uiDomString += F(" <i class=\"icons\">&#xe08f;</i></button>");

View File

@ -235,7 +235,7 @@
<div> <div>
<!--table> <!--table>
<tr> <tr>
<td class="keytd"--><button class="btn" onclick="loadInfo()">Refresh</button><!--/td> <td class="keytd"--><button class="btn" onclick="requestJson()">Refresh</button><!--/td>
<td class="valtd"--><button class="btn" onclick="toggleInfo()">Close Info</button><!--/td> <td class="valtd"--><button class="btn" onclick="toggleInfo()">Close Info</button><!--/td>
</tr> </tr>
<tr> <tr>

View File

@ -255,7 +255,8 @@ function onLoad()
loadFX(()=>{ loadFX(()=>{
loadFXData(); loadFXData();
loadPresets(()=>{ loadPresets(()=>{
if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS //if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS
requestJson();
}); });
}); });
}); });
@ -1354,23 +1355,21 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-r)"; gId('connind').style.backgroundColor = "var(--c-r)";
if (command && !reqsLegal) return; //stop post requests from chrome onchange event on page restore if (command && !reqsLegal) return; //stop post requests from chrome onchange event on page restore
if (!jsonTimeout) jsonTimeout = setTimeout(showErrorToast, 3000); if (!jsonTimeout) jsonTimeout = setTimeout(showErrorToast, 3000);
if (!command) command = {'v':true};
var req = null; var req = null;
var url = (loc?`http://${locip}`:'') + '/json/state'; var url = (loc?`http://${locip}`:'') + '/json/si';
var useWs = (ws && ws.readyState === WebSocket.OPEN); var useWs = (ws && ws.readyState === WebSocket.OPEN);
var type = command ? 'post':'get'; var type = command ? 'post':'get';
if (command) {
command.v = true; // force complete /json/si API response command.v = true; // force complete /json/si API response
command.time = Math.floor(Date.now() / 1000); command.time = Math.floor(Date.now() / 1000);
var t = gId('tt');
var t = gId('tt'); if (t.validity.valid && command.transition==null) {
if (t.validity.valid && command.transition==null) { var tn = parseInt(t.value*10);
var tn = parseInt(t.value*10); if (tn != tr) command.transition = tn;
if (tn != tr) command.transition = tn; }
} req = JSON.stringify(command);
if (req.length > 1000) useWs = false; //do not send very long requests over websocket
req = JSON.stringify(command); };
if (req.length > 1000) useWs = false; //do not send very long requests over websocket
if (useWs) { if (useWs) {
ws.send(req?req:'{"v":true}'); ws.send(req?req:'{"v":true}');
@ -1396,6 +1395,11 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-g)"; gId('connind').style.backgroundColor = "var(--c-g)";
if (!json) { showToast('Empty response', true); return; } if (!json) { showToast('Empty response', true); return; }
if (json.success) return; if (json.success) return;
if (json.info) {
lastinfo = json.info;
parseInfo();
if (isInfo) populateInfo();
}
var s = json.state ? json.state : json; var s = json.state ? json.state : json;
readState(s); readState(s);
reqsLegal = true; reqsLegal = true;
@ -1451,7 +1455,7 @@ function toggleInfo()
{ {
if (isNodes) toggleNodes(); if (isNodes) toggleNodes();
isInfo = !isInfo; isInfo = !isInfo;
if (isInfo) loadInfo(); if (isInfo) requestJson(); // loadInfo();
gId('info').style.transform = (isInfo) ? "translateY(0px)":"translateY(100%)"; gId('info').style.transform = (isInfo) ? "translateY(0px)":"translateY(100%)";
gId('buttonI').className = (isInfo) ? "active":""; gId('buttonI').className = (isInfo) ? "active":"";
} }

View File

@ -175,7 +175,7 @@
</div><br> </div><br>
<div id="kv">Loading...</div><br> <div id="kv">Loading...</div><br>
<div> <div>
<button class="btn" onclick="loadInfo()">Refresh</button> <button class="btn" onclick="requestJson()">Refresh</button>
<button class="btn" onclick="toggleInfo()">Close Info</button> <button class="btn" onclick="toggleInfo()">Close Info</button>
<button class="btn" onclick="toggleNodes()">Instance List</button> <button class="btn" onclick="toggleNodes()">Instance List</button>
<button class="btn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button> <button class="btn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button>

View File

@ -238,7 +238,8 @@ async function onLoad()
loadPalettesData(redrawPalPrev); loadPalettesData(redrawPalPrev);
loadFX(()=>{ loadFX(()=>{
loadPresets(()=>{ loadPresets(()=>{
if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS //if (isObj(lastinfo) && isEmpty(lastinfo)) loadInfo(requestJson); // if not filled by WS
requestJson();
}); });
}); });
}); });
@ -987,17 +988,21 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-r)"; gId('connind').style.backgroundColor = "var(--c-r)";
if (command && !reqsLegal) return; //stop post requests from chrome onchange event on page restore if (command && !reqsLegal) return; //stop post requests from chrome onchange event on page restore
if (!jsonTimeout) jsonTimeout = setTimeout(showErrorToast, 3000); if (!jsonTimeout) jsonTimeout = setTimeout(showErrorToast, 3000);
if (!command) command = {'v':true};
var req = null; var req = null;
var url = (loc?`http://${locip}`:'') + '/json/state'; var url = (loc?`http://${locip}`:'') + '/json/si';
var useWs = (ws && ws.readyState === WebSocket.OPEN); var useWs = (ws && ws.readyState === WebSocket.OPEN);
var type = command ? 'post':'get'; var type = command ? 'post':'get';
if (command) {
command.v = true; // force complete /json/si API response command.v = true; // force complete /json/si API response
command.time = Math.floor(Date.now() / 1000); command.time = Math.floor(Date.now() / 1000);
command.transition = tr; var t = gId('tt');
req = JSON.stringify(command); if (t.validity.valid && command.transition==null) {
if (req.length > 1000) useWs = false; //do not send very long requests over websocket var tn = parseInt(t.value*10);
if (tn != tr) command.transition = tn;
}
req = JSON.stringify(command);
if (req.length > 1000) useWs = false; //do not send very long requests over websocket
};
if (useWs) { if (useWs) {
ws.send(req?req:'{"v":true}'); ws.send(req?req:'{"v":true}');
@ -1023,6 +1028,11 @@ function requestJson(command=null)
gId('connind').style.backgroundColor = "var(--c-g)"; gId('connind').style.backgroundColor = "var(--c-g)";
if (!json) { showToast('Empty response', true); return; } if (!json) { showToast('Empty response', true); return; }
if (json.success) return; if (json.success) return;
if (json.info) {
lastinfo = json.info;
parseInfo();
if (isInfo) populateInfo();
}
var s = json.state ? json.state : json; var s = json.state ? json.state : json;
readState(s); readState(s);
reqsLegal = true; reqsLegal = true;
@ -1044,7 +1054,7 @@ function toggleInfo()
{ {
if (isNodes) toggleNodes(); if (isNodes) toggleNodes();
isInfo = !isInfo; isInfo = !isInfo;
if (isInfo) loadInfo(); if (isInfo) requestJson(); // loadInfo();
gId('info').style.transform = (isInfo) ? "translateY(0px)":"translateY(100%)"; gId('info').style.transform = (isInfo) ? "translateY(0px)":"translateY(100%)";
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2111201 #define VERSION 2111211
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG

View File

@ -124,6 +124,7 @@ void sendDataWs(AsyncWebSocketClient * client)
serializeState(state); serializeState(state);
JsonObject info = doc.createNestedObject("info"); JsonObject info = doc.createNestedObject("info");
serializeInfo(info); serializeInfo(info);
DEBUG_PRINTF("JSON buffer size: %u for WS request.\n", doc.memoryUsage());
size_t len = measureJson(doc); size_t len = measureJson(doc);
buffer = ws.makeBuffer(len); buffer = ws.makeBuffer(len);
if (!buffer) { if (!buffer) {