новое получение графиков

This commit is contained in:
Dmitry Borisenko
2022-09-23 02:26:22 +02:00
parent 1f87e18e9f
commit 6061673ab7

View File

@@ -39,12 +39,12 @@
let updatingTimeout = 120000; let updatingTimeout = 120000;
let opened = false; let opened = false;
let preventMove = false; let preventMove = false;
let devMode = false; let devMode = true;
//****************************************************variable section**********************************************************/ //****************************************************variable section**********************************************************/
//******************************************************************************************************************************/ //******************************************************************************************************************************/
let myip = document.location.hostname; let myip = document.location.hostname;
if (devMode) myip = "192.168.88.253"; if (devMode) myip = "192.168.88.248";
//Flags //Flags
let firstDevListRequest = true; let firstDevListRequest = true;
@@ -84,6 +84,11 @@
let itemsJsonFlag = false; let itemsJsonFlag = false;
let itemsJsonParced = false; let itemsJsonParced = false;
let chartJson = {};
let chartJsonFlag = false;
let chartTopic;
let chartJsonParced = false;
let scenarioJson = {}; let scenarioJson = {};
let scenarioJsonFlag = false; let scenarioJsonFlag = false;
let scenarioJsonParced = false; let scenarioJsonParced = false;
@@ -109,8 +114,6 @@
let incDeviceList = []; let incDeviceList = [];
let deviceListParced = false; let deviceListParced = false;
let statusJsonParced = false;
let deviceList = []; let deviceList = [];
deviceList = [ deviceList = [
{ {
@@ -161,6 +164,7 @@
var widgetsJsonBlob = new MyBlobBuilder(); var widgetsJsonBlob = new MyBlobBuilder();
var itemsJsonBlob = new MyBlobBuilder(); var itemsJsonBlob = new MyBlobBuilder();
var scenarioTxtBlob = new MyBlobBuilder(); var scenarioTxtBlob = new MyBlobBuilder();
var chartJsonBlob = new MyBlobBuilder();
var layoutJsonArray = []; var layoutJsonArray = [];
@@ -370,6 +374,7 @@
scenarioJsonReader.readAsText(bb); scenarioJsonReader.readAsText(bb);
scenarioJsonReader.onload = () => { scenarioJsonReader.onload = () => {
let scenarioJsonResult = scenarioJsonReader.result; let scenarioJsonResult = scenarioJsonReader.result;
if (IsJsonParse(scenarioJsonResult)) { if (IsJsonParse(scenarioJsonResult)) {
scenarioJson = JSON.parse(scenarioJsonResult); scenarioJson = JSON.parse(scenarioJsonResult);
scenarioJson = scenarioJson; scenarioJson = scenarioJson;
@@ -378,6 +383,7 @@
onParced(); onParced();
} }
}; };
scenarioTxtBlob.clear();
} }
//сборщик configJson пакетов //сборщик configJson пакетов
if (data === "/st/config.json") { if (data === "/st/config.json") {
@@ -390,6 +396,7 @@
configJsonReader.readAsText(bb); configJsonReader.readAsText(bb);
configJsonReader.onload = () => { configJsonReader.onload = () => {
let configJsonResult = configJsonReader.result; let configJsonResult = configJsonReader.result;
if (IsJsonParse(configJsonResult)) { if (IsJsonParse(configJsonResult)) {
configJson = JSON.parse(configJsonResult); configJson = JSON.parse(configJsonResult);
configJson = configJson; configJson = configJson;
@@ -398,6 +405,7 @@
onParced(); onParced();
} }
}; };
configJsonBlob.clear();
} }
//сборщик widgetsJson пакетов //сборщик widgetsJson пакетов
if (data === "/st/widgets.json") { if (data === "/st/widgets.json") {
@@ -410,6 +418,7 @@
widgetsJsonReader.readAsText(bb); widgetsJsonReader.readAsText(bb);
widgetsJsonReader.onload = () => { widgetsJsonReader.onload = () => {
let widgetsJsonResult = widgetsJsonReader.result; let widgetsJsonResult = widgetsJsonReader.result;
if (IsJsonParse(widgetsJsonResult)) { if (IsJsonParse(widgetsJsonResult)) {
widgetsJson = JSON.parse(widgetsJsonResult); widgetsJson = JSON.parse(widgetsJsonResult);
widgetsJson = widgetsJson; widgetsJson = widgetsJson;
@@ -418,6 +427,7 @@
onParced(); onParced();
} }
}; };
widgetsJsonBlob.clear();
} }
//сборщик itemsJson пакетов //сборщик itemsJson пакетов
if (data === "/st/items.json") { if (data === "/st/items.json") {
@@ -430,6 +440,7 @@
itemsJsonReader.readAsText(bb); itemsJsonReader.readAsText(bb);
itemsJsonReader.onload = () => { itemsJsonReader.onload = () => {
let itemsJsonResult = itemsJsonReader.result; let itemsJsonResult = itemsJsonReader.result;
if (IsJsonParse(itemsJsonResult)) { if (IsJsonParse(itemsJsonResult)) {
itemsJson = JSON.parse(itemsJsonResult); itemsJson = JSON.parse(itemsJsonResult);
itemsJson = itemsJson; itemsJson = itemsJson;
@@ -438,6 +449,7 @@
onParced(); onParced();
} }
}; };
itemsJsonBlob.clear();
} }
} }
//сборщик layoutJson пакетов //сборщик layoutJson пакетов
@@ -464,13 +476,33 @@
onParced(); onParced();
} }
} }
//сборщик chartJson пакетов
if (data === "/st/chart.json") {
chartJsonFlag = true;
}
if (data === "/end/chart.json") {
chartJsonFlag = false;
var bb = chartJsonBlob.getBlob();
let chartJsonReader = new FileReader();
chartJsonReader.readAsText(bb);
chartJsonReader.onload = () => {
let chartJsonResult = chartJsonReader.result;
chartJsonResult = chartJsonResult.substring(0, chartJsonResult.length - 1) + "]}";
if (IsJsonParse(chartJsonResult)) {
let arr = JSON.parse(chartJsonResult);
if (debug) console.log("✔", "chartJson parced", arr.topic);
updateWidgetArr(arr);
}
};
chartJsonBlob.clear();
}
//сборщик statusJson сообщений //сборщик statusJson сообщений
if (data.includes('"status"')) { if (data.includes('"status"')) {
if (IsJsonParse(data)) { if (IsJsonParse(data)) {
let statusJson = JSON.parse(data); let statusJson = JSON.parse(data);
if (Array.isArray(statusJson.status)) { if (Array.isArray(statusJson.status)) {
updateWidgetArr(statusJson); //updateWidgetArr(statusJson);
if (debug) console.log("[i] status (arr)", ws); //if (debug) console.log("[i] status (arr)", ws);
} else { } else {
updateWidget(statusJson); updateWidget(statusJson);
if (debug) console.log("[i] status (dgt)", ws, JSON.stringify(statusJson)); if (debug) console.log("[i] status (dgt)", ws, JSON.stringify(statusJson));
@@ -488,6 +520,7 @@
if (widgetsJsonFlag) widgetsJsonBlob.append(event.data); if (widgetsJsonFlag) widgetsJsonBlob.append(event.data);
if (itemsJsonFlag) itemsJsonBlob.append(event.data); if (itemsJsonFlag) itemsJsonBlob.append(event.data);
if (scenarioJsonFlag) scenarioTxtBlob.append(event.data); if (scenarioJsonFlag) scenarioTxtBlob.append(event.data);
if (chartJsonFlag) chartJsonBlob.append(event.data);
} }
//принимаем данные от всех устройств //принимаем данные от всех устройств
if (!layoutJsonArray[ws]) layoutJsonArray[ws] = new MyBlobBuilder(); if (!layoutJsonArray[ws]) layoutJsonArray[ws] = new MyBlobBuilder();
@@ -783,6 +816,8 @@
itemsJson = []; itemsJson = [];
itemsJsonBlob.clear(); itemsJsonBlob.clear();
chartJsonBlob.clear();
layoutJson = []; layoutJson = [];
layoutJsonArray = []; layoutJsonArray = [];
@@ -808,13 +843,13 @@
configJsonParced = false; configJsonParced = false;
widgetsJsonParced = false; widgetsJsonParced = false;
itemsJsonParced = false; itemsJsonParced = false;
chartJsonParced = false;
layoutJsonArrayParced = false; layoutJsonArrayParced = false;
layoutReceivingCompleted = false; layoutReceivingCompleted = false;
settingsJsonParced = false; settingsJsonParced = false;
errorsJsonParced = false; errorsJsonParced = false;
ssidJsonParced = false; ssidJsonParced = false;
paramsJsonParced = false; paramsJsonParced = false;
statusJsonParced = false;
deviceListParced = false; deviceListParced = false;
scenarioJsonParced = false; scenarioJsonParced = false;
clearFlags(); clearFlags();