From 9fd686a9cf41764ca36af35c71b88ca9094ffe66 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Fri, 9 Jun 2023 01:00:14 +0200 Subject: [PATCH] final --- src/App.svelte | 78 +++++++++++++++++++++++++---------------- src/pages/List.svelte | 32 +++++++++++++++-- src/pages/System.svelte | 16 --------- 3 files changed, 76 insertions(+), 50 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 6bb63aa..f5311ef 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -34,7 +34,7 @@ //******************************************************************************************************************************/ const debug = true; const LOG_MAX_MESSAGES = 100; - const reconnectTimeout = 120000; //период проверки соединения с устройством + const reconnectTimeout = 60000; //период проверки соединения с устройством const waitingAckTimeout = 12000; //время ожидания ответа от устройства const rebootingTimeout = 20000; const updatingTimeout = 130000; @@ -43,6 +43,9 @@ const blobDebug = false; const devMode = true; + let timeout = reconnectTimeout / 1000; + let percent; + //****************************************************variable section**********************************************************/ //******************************************************************************************************************************/ let myip = document.location.hostname; @@ -149,15 +152,15 @@ clearData(); } - if (currentPageName === "/list" || "/") { + currentPageName = currentPageName + "|"; + console.log("[i]", "user on page:", currentPageName); + + if (currentPageName === "/list|") { showDropdown = false; } else { showDropdown = true; } - currentPageName = currentPageName + "|"; - console.log("[i]", "user on page:", currentPageName); - if (currentPageName === "/|") { sendToAllDevices(currentPageName); } else { @@ -181,7 +184,6 @@ connectToAllDevices(); wsTestMsgTask(); //sortingLayout(); - ticker(); }); //****************************************************web sockets section******************************************************/ @@ -582,7 +584,7 @@ pageReady.connection = true; } - if (currentPageName === "/list|" && parsed.deviceListJson) { + if (currentPageName === "/list|" && parsed.deviceListJson && parsed.settingsJson) { clearParcedFlags(); if (debug) console.log("✔✔", "list page parced"); pageReady.list = true; @@ -610,7 +612,7 @@ //при последующих прилетах списка устройств мы переписываем в массиве только то что изменилось deviceList = combineArrays(deviceList, incDeviceList); } - //deviceList = incDeviceList; + firstDevListRequest = false; deviceList = deviceList; parsed.deviceListJson = true; @@ -929,25 +931,37 @@ wsSendMsg(ws, "/control|" + key + "/" + status); } - function wsTestMsgTask() { - setTimeout(wsTestMsgTask, reconnectTimeout); - if (!rebootingUpdatingInProgress) { - if (debug) console.log("[i]", "----timer tick----"); + function scale(number, inMin, inMax, outMin, outMax) { + return ((number - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin; + } - if (!firstTime) { - deviceList.forEach((device) => { - if (!getDeviceStatus(device.ws)) { - wsConnect(device.ws); - wsEventAdd(device.ws); - } else { - wsSendMsg(device.ws, "/tst|"); - ack(device.ws, false); - } - }); - } - firstTime = false; + function wsTestMsgTask() { + setTimeout(wsTestMsgTask, 1000); + timeout--; + percent = scale(timeout, reconnectTimeout / 1000, 0, 0, 100); + + if (timeout <= 0) { + timeout = reconnectTimeout / 1000; + //if (!rebootingUpdatingInProgress) { + if (debug) console.log("[i]", "----timer tick----"); + //if (!firstTime) { + + deviceList.forEach((device) => { + if (!device.status) { + wsConnect(device.ws); + wsEventAdd(device.ws); + } else { + wsSendMsg(device.ws, "/tst|"); + ack(device.ws, false); + } + }); + //} + //firstTime = false; + //} else { + // if (debug) console.log("[i]", "----timer skipped----"); + //} } else { - if (debug) console.log("[i]", "----timer skipped----"); + //console.log("[i]", timeout); } } @@ -1202,10 +1216,12 @@ } function rebootingTask() { - clearTimeout(myTimeout); - clearData(); - connectToAllDevices(); - rebootingUpdatingInProgress = false; + //перезапуск приложения + location.reload(); + //clearTimeout(myTimeout); + //clearData(); + //connectToAllDevices(); + //rebootingUpdatingInProgress = false; } function cancelAlarm(alarmKey) { @@ -1361,7 +1377,7 @@