2021-09-16 02:00:52 +08:00
|
|
|
|
<script>
|
2022-02-22 20:20:59 +01:00
|
|
|
|
/*
|
|
|
|
|
|
Svelte IoT Manager app
|
|
|
|
|
|
created by Dmitry Borisenko
|
2023-06-08 22:37:43 +02:00
|
|
|
|
Vienna, Austria 1030, Juchgasse 5/17
|
|
|
|
|
|
+43 67761588253
|
2022-02-22 20:20:59 +01:00
|
|
|
|
*/
|
2022-02-19 23:35:30 +01:00
|
|
|
|
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//6+49 кб 09/06/2023
|
|
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//******************************************************import section*********************************************************/
|
|
|
|
|
|
//*****************************************************************************************************************************/
|
2021-09-16 02:00:52 +08:00
|
|
|
|
import { onMount } from "svelte";
|
|
|
|
|
|
import { Route, router, active } from "tinro";
|
2022-02-06 23:02:20 +01:00
|
|
|
|
router.mode.hash();
|
|
|
|
|
|
|
2022-02-07 02:08:21 +01:00
|
|
|
|
import Alarm from "./components/Alarm.svelte";
|
2022-02-08 16:47:26 +01:00
|
|
|
|
import Progress from "./components/Progress.svelte";
|
2022-10-07 22:29:04 +02:00
|
|
|
|
import Card from "./components/Card.svelte";
|
2021-12-26 01:34:29 +01:00
|
|
|
|
|
2023-06-17 22:26:52 +02:00
|
|
|
|
import ModalPass from "./components/ModalPass.svelte";
|
2022-02-06 23:02:20 +01:00
|
|
|
|
import DashboardPage from "./pages/Dashboard.svelte";
|
|
|
|
|
|
import ConfigPage from "./pages/Config.svelte";
|
|
|
|
|
|
import ConnectionPage from "./pages/Connection.svelte";
|
2022-02-08 21:42:40 +01:00
|
|
|
|
import ListPage from "./pages/List.svelte";
|
|
|
|
|
|
import SystemPage from "./pages/System.svelte";
|
2022-09-10 02:59:03 +02:00
|
|
|
|
import DevPage from "./pages/Dev.svelte";
|
2022-02-08 21:42:40 +01:00
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
|
//import UtilitiesPage from "./pages/Utilities.svelte";
|
|
|
|
|
|
//import LogPage from "./pages/Log.svelte";
|
|
|
|
|
|
//import AboutPage from "./pages/About.svelte";
|
2021-12-26 01:34:29 +01:00
|
|
|
|
|
2022-02-07 16:36:43 +01:00
|
|
|
|
import CloudIcon from "./svg/Cloud.svelte";
|
|
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//****************************************************constants section*********************************************************/
|
|
|
|
|
|
//******************************************************************************************************************************/
|
2022-10-09 17:03:41 +02:00
|
|
|
|
const debug = true;
|
|
|
|
|
|
const LOG_MAX_MESSAGES = 100;
|
2023-06-09 01:00:14 +02:00
|
|
|
|
const reconnectTimeout = 60000; //период проверки соединения с устройством
|
2023-06-13 21:06:04 +02:00
|
|
|
|
let preventReconnect = false;
|
2023-06-08 22:37:43 +02:00
|
|
|
|
const waitingAckTimeout = 12000; //время ожидания ответа от устройства
|
2022-11-22 15:07:41 +01:00
|
|
|
|
const rebootingTimeout = 20000;
|
|
|
|
|
|
const updatingTimeout = 130000;
|
2023-06-13 21:06:04 +02:00
|
|
|
|
let rebootTimer;
|
2022-02-01 16:01:19 +01:00
|
|
|
|
let opened = false;
|
|
|
|
|
|
let preventMove = false;
|
2023-06-17 22:26:52 +02:00
|
|
|
|
const blobDebug = false;
|
2023-06-13 21:06:04 +02:00
|
|
|
|
const devMode = true;
|
2021-12-14 20:55:53 +01:00
|
|
|
|
|
2023-06-09 01:00:14 +02:00
|
|
|
|
let timeout = reconnectTimeout / 1000;
|
|
|
|
|
|
let percent;
|
|
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//****************************************************variable section**********************************************************/
|
|
|
|
|
|
//******************************************************************************************************************************/
|
2022-08-16 00:56:12 +02:00
|
|
|
|
let myip = document.location.hostname;
|
2023-06-08 22:37:43 +02:00
|
|
|
|
if (devMode) myip = "192.168.1.238";
|
2021-12-14 20:55:53 +01:00
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//Flags
|
2022-02-13 23:13:08 +01:00
|
|
|
|
let firstDevListRequest = true;
|
2021-12-28 21:18:03 +01:00
|
|
|
|
let showInput = false;
|
2023-06-17 22:26:52 +02:00
|
|
|
|
let authorization = false;
|
2023-06-08 22:37:43 +02:00
|
|
|
|
let showDropdown = true;
|
2022-02-06 23:02:20 +01:00
|
|
|
|
|
2023-06-13 21:06:04 +02:00
|
|
|
|
let showAwaitingCircle = false;
|
2022-02-24 00:59:10 +01:00
|
|
|
|
|
2021-12-14 20:55:53 +01:00
|
|
|
|
//dashboard
|
|
|
|
|
|
let pages = [];
|
|
|
|
|
|
|
2022-09-25 17:49:24 +02:00
|
|
|
|
//ready
|
|
|
|
|
|
let pageReady = {
|
|
|
|
|
|
dash: false,
|
|
|
|
|
|
config: false,
|
|
|
|
|
|
connection: false,
|
|
|
|
|
|
list: false,
|
|
|
|
|
|
system: false,
|
|
|
|
|
|
dev: false,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-02-18 19:48:15 +01:00
|
|
|
|
//update esp
|
|
|
|
|
|
let versionsList = {};
|
|
|
|
|
|
let choosingVersion = undefined;
|
|
|
|
|
|
|
2022-08-23 15:13:50 +02:00
|
|
|
|
//JSON Files====================================
|
2022-02-01 16:01:19 +01:00
|
|
|
|
let itemsJson = [];
|
2022-10-09 14:31:07 +02:00
|
|
|
|
let widgetsJson = [];
|
|
|
|
|
|
let configJson = [];
|
2022-10-12 03:18:04 +02:00
|
|
|
|
let scenarioTxt = " ";
|
2022-02-02 23:37:15 +01:00
|
|
|
|
let settingsJson = {};
|
2022-02-05 02:13:46 +01:00
|
|
|
|
let ssidJson = {};
|
2022-10-09 14:31:07 +02:00
|
|
|
|
let errorsJson = {};
|
2022-02-07 23:40:00 +01:00
|
|
|
|
let deviceList = [];
|
2021-12-13 02:36:26 +01:00
|
|
|
|
deviceList = [
|
|
|
|
|
|
{
|
2022-02-07 23:40:00 +01:00
|
|
|
|
name: "--",
|
|
|
|
|
|
id: "--",
|
|
|
|
|
|
ip: myip,
|
2022-02-13 23:13:08 +01:00
|
|
|
|
ws: 0,
|
2022-02-07 02:08:21 +01:00
|
|
|
|
status: false,
|
|
|
|
|
|
},
|
2021-12-13 02:36:26 +01:00
|
|
|
|
];
|
2022-10-09 14:31:07 +02:00
|
|
|
|
|
2022-10-09 21:29:56 +02:00
|
|
|
|
let incDeviceList = [];
|
2022-10-09 14:31:07 +02:00
|
|
|
|
let layoutJson = [];
|
|
|
|
|
|
let paramsJson = {};
|
|
|
|
|
|
|
|
|
|
|
|
let parsed = {
|
|
|
|
|
|
itemsJson: false,
|
|
|
|
|
|
widgetsJson: false,
|
|
|
|
|
|
configJson: false,
|
|
|
|
|
|
scenarioTxt: false,
|
|
|
|
|
|
settingsJson: false,
|
|
|
|
|
|
ssidJson: false,
|
|
|
|
|
|
incDeviceList: false,
|
|
|
|
|
|
deviceListJson: false,
|
|
|
|
|
|
errorsJson: false,
|
|
|
|
|
|
statusJson: false,
|
|
|
|
|
|
paramsJson: false,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===============================================
|
2021-12-12 00:20:47 +01:00
|
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
|
//web sockets
|
|
|
|
|
|
let socket = [];
|
|
|
|
|
|
let socketConnected = false;
|
|
|
|
|
|
let selectedDeviceData = undefined;
|
|
|
|
|
|
let selectedWs = 0;
|
2023-06-11 17:01:57 +02:00
|
|
|
|
let originalWs = 0;
|
2022-02-13 00:37:58 +01:00
|
|
|
|
|
|
|
|
|
|
let newDevice = {};
|
|
|
|
|
|
let coreMessages = [];
|
|
|
|
|
|
|
2022-01-30 17:44:53 +01:00
|
|
|
|
//***********************************************************navigation********************************************************/
|
2021-12-16 00:18:40 +01:00
|
|
|
|
let currentPageName = undefined;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
|
2021-12-16 00:18:40 +01:00
|
|
|
|
router.subscribe(handleNavigation);
|
|
|
|
|
|
|
2022-01-30 17:44:53 +01:00
|
|
|
|
function handleNavigation() {
|
|
|
|
|
|
currentPageName = $router.path.toString();
|
2023-06-09 01:00:14 +02:00
|
|
|
|
currentPageName = currentPageName + "|";
|
2023-06-11 17:01:57 +02:00
|
|
|
|
|
2023-06-09 01:00:14 +02:00
|
|
|
|
console.log("[i]", "user on page:", currentPageName);
|
|
|
|
|
|
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//не нужно очищать переменные когда переходим на страницу разработчика
|
|
|
|
|
|
if (currentPageName != "/dev|") {
|
|
|
|
|
|
clearData();
|
2023-06-08 22:37:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//если мы на странице dashboard то рассылаем всем устройствам запрос данных
|
2022-02-26 01:09:17 +01:00
|
|
|
|
if (currentPageName === "/|") {
|
|
|
|
|
|
sendToAllDevices(currentPageName);
|
2023-06-11 17:01:57 +02:00
|
|
|
|
showDropdown = false;
|
|
|
|
|
|
//в остальных случаях шлем только выбранному устройству запрос данных
|
2022-02-26 01:09:17 +01:00
|
|
|
|
} else {
|
2023-06-11 17:01:57 +02:00
|
|
|
|
if (currentPageName === "/list|") {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//если мы перешли на страницу списка устройств отключаем выпадающий список
|
2023-06-11 17:01:57 +02:00
|
|
|
|
showDropdown = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showDropdown = true;
|
|
|
|
|
|
}
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//если мы на любой другой странице то запрашиваем данные
|
|
|
|
|
|
sendCurrentPageNameToSelectedWs();
|
2022-02-26 01:09:17 +01:00
|
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-13 21:06:04 +02:00
|
|
|
|
function sendCurrentPageNameToSelectedWs() {
|
2022-02-07 23:40:00 +01:00
|
|
|
|
if (selectedWs !== undefined) {
|
|
|
|
|
|
wsSendMsg(selectedWs, currentPageName);
|
2022-01-30 17:44:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-28 21:18:03 +01:00
|
|
|
|
|
2022-02-23 22:56:17 +01:00
|
|
|
|
//*******************************************************initialisation********************************************************************/
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
|
console.log("[i]", "mounted");
|
2023-06-11 17:01:57 +02:00
|
|
|
|
selectedDeviceDataRefresh();
|
2023-06-08 22:37:43 +02:00
|
|
|
|
//флаг первого запроса списка устройств
|
2022-02-23 22:56:17 +01:00
|
|
|
|
firstDevListRequest = true;
|
2023-06-08 22:37:43 +02:00
|
|
|
|
//вначале подключимся к известному нам ip этого устройства
|
2022-02-23 22:56:17 +01:00
|
|
|
|
connectToAllDevices();
|
|
|
|
|
|
wsTestMsgTask();
|
2022-10-07 22:29:04 +02:00
|
|
|
|
//sortingLayout();
|
2022-02-23 22:56:17 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//****************************************************web sockets section******************************************************/
|
2021-12-08 22:59:21 +01:00
|
|
|
|
function connectToAllDevices() {
|
2022-02-07 23:40:00 +01:00
|
|
|
|
getSelectedDeviceData(selectedWs);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
|
deviceList[i].ws = i;
|
|
|
|
|
|
if (deviceList[i].status === false || deviceList[i].status === undefined) {
|
|
|
|
|
|
wsConnect(i);
|
|
|
|
|
|
wsEventAdd(i);
|
2021-12-13 00:01:21 +01:00
|
|
|
|
}
|
2023-06-13 21:06:04 +02:00
|
|
|
|
}
|
2021-12-05 00:49:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-13 00:01:21 +01:00
|
|
|
|
function closeAllConnection() {
|
|
|
|
|
|
let s;
|
|
|
|
|
|
for (s in socket) {
|
|
|
|
|
|
socket[s].close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-13 21:06:04 +02:00
|
|
|
|
function printAllCreatedWs() {
|
|
|
|
|
|
if (socket) {
|
|
|
|
|
|
for (let i = 0; i < socket.length; i++) {
|
|
|
|
|
|
if (debug) console.log("[i]", "[ws]", "WebSocket client No: ", i);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-29 01:42:51 +02:00
|
|
|
|
var ackTimeoutsArr = [];
|
|
|
|
|
|
var startMillis = [];
|
|
|
|
|
|
var ping = [];
|
|
|
|
|
|
|
|
|
|
|
|
function ack(ws, st) {
|
|
|
|
|
|
if (!st) {
|
2022-11-21 00:38:58 +01:00
|
|
|
|
startMillis[ws] = Date.now();
|
2022-10-29 01:42:51 +02:00
|
|
|
|
ackTimeoutsArr[ws] = setTimeout(function () {
|
|
|
|
|
|
markDeviceStatus(ws, false);
|
|
|
|
|
|
}, waitingAckTimeout);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (ackTimeoutsArr[ws]) clearTimeout(ackTimeoutsArr[ws]);
|
|
|
|
|
|
if (startMillis[ws]) {
|
2022-11-21 00:38:58 +01:00
|
|
|
|
ping[ws] = Date.now() - startMillis[ws];
|
2022-10-29 01:42:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
|
if (deviceList[i].ws === ws) {
|
|
|
|
|
|
deviceList[i].ping = ping[ws];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
deviceList = deviceList;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-09 00:10:10 +01:00
|
|
|
|
function markDeviceStatus(ws, status) {
|
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
|
if (device.ws === ws) {
|
|
|
|
|
|
device.status = status;
|
2022-10-29 01:42:51 +02:00
|
|
|
|
device.ping = 0;
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (device.status === true) {
|
2022-11-21 00:38:58 +01:00
|
|
|
|
console.log("[i]", device.ip, ws, "status online");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("[i]", device.ip, ws, "status offline");
|
|
|
|
|
|
deleteWidget(ws);
|
|
|
|
|
|
sortingLayout(ws);
|
2021-12-09 22:35:04 +01:00
|
|
|
|
}
|
2021-12-09 00:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-06-11 17:01:57 +02:00
|
|
|
|
selectedDeviceDataRefresh();
|
2021-12-09 22:35:04 +01:00
|
|
|
|
deviceList = deviceList;
|
2022-10-29 01:42:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-21 00:38:58 +01:00
|
|
|
|
function deleteWidget(ws) {
|
|
|
|
|
|
layoutJson = layoutJson.filter((item) => item.ws !== ws);
|
2021-12-09 00:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-10 14:44:00 +01:00
|
|
|
|
function wsConnect(ws) {
|
|
|
|
|
|
let ip = getIP(ws);
|
|
|
|
|
|
if (ip === "error") {
|
|
|
|
|
|
if (debug) console.log("[e]", "device list wrong");
|
|
|
|
|
|
} else {
|
2021-12-25 00:20:49 +01:00
|
|
|
|
socket[ws] = new WebSocket("ws://" + ip + ":81");
|
2022-01-24 00:57:27 +01:00
|
|
|
|
socket.binaryType = "blob";
|
2022-02-15 15:22:54 +01:00
|
|
|
|
if (debug) console.log("[i]", ip, ws, "started connecting...");
|
2021-12-10 14:44:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getIP(ws) {
|
|
|
|
|
|
let ret = "error";
|
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
|
if (ws === device.ws) {
|
|
|
|
|
|
ret = device.ip;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return ret;
|
2021-12-06 01:21:55 +01:00
|
|
|
|
}
|
2021-12-07 22:14:59 +01:00
|
|
|
|
|
2021-12-08 22:59:21 +01:00
|
|
|
|
function wsEventAdd(ws) {
|
|
|
|
|
|
if (socket[ws]) {
|
2021-12-11 13:54:28 +01:00
|
|
|
|
let ip = getIP(ws);
|
2021-12-08 22:59:21 +01:00
|
|
|
|
socket[ws].addEventListener("open", function (event) {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//if (debug) console.log("[i]", ip, ws, "completed connecting");
|
2021-12-09 00:10:10 +01:00
|
|
|
|
markDeviceStatus(ws, true);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//при первом подключении запросим список устройств
|
|
|
|
|
|
if (firstDevListRequest && ws === 0) wsSendMsg(ws, "/devlist|");
|
2022-02-26 01:09:17 +01:00
|
|
|
|
//при подключении отправляем название страницы
|
2022-02-25 17:57:47 +01:00
|
|
|
|
if (currentPageName === "/|") {
|
2022-02-26 01:09:17 +01:00
|
|
|
|
//всем устройствам
|
2022-02-25 17:57:47 +01:00
|
|
|
|
wsSendMsg(ws, currentPageName);
|
|
|
|
|
|
} else {
|
2022-02-26 01:09:17 +01:00
|
|
|
|
//только выбранному
|
2022-02-25 17:57:47 +01:00
|
|
|
|
if (ws === selectedWs) {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
sendCurrentPageNameToSelectedWs();
|
2022-02-25 17:57:47 +01:00
|
|
|
|
}
|
2022-02-15 15:22:54 +01:00
|
|
|
|
}
|
2021-12-08 22:59:21 +01:00
|
|
|
|
});
|
2022-09-01 12:51:17 +02:00
|
|
|
|
|
|
|
|
|
|
//события веб сокетов
|
2021-12-08 22:59:21 +01:00
|
|
|
|
socket[ws].addEventListener("message", function (event) {
|
2022-01-24 00:57:27 +01:00
|
|
|
|
if (typeof event.data === "string") {
|
2022-01-25 01:41:29 +01:00
|
|
|
|
let data = event.data;
|
2022-10-29 01:42:51 +02:00
|
|
|
|
if (data === "/tstr|") {
|
2022-11-21 00:38:58 +01:00
|
|
|
|
//прилетело подтверждение значит устройство онлайн
|
2022-10-29 01:42:51 +02:00
|
|
|
|
ack(ws, true);
|
|
|
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
if (event.data instanceof Blob) {
|
2022-02-15 15:22:54 +01:00
|
|
|
|
//принимаем данные только для выбранного устройства
|
|
|
|
|
|
if (ws === selectedWs) {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
parseBlob(event.data, ws);
|
2022-02-15 15:22:54 +01:00
|
|
|
|
}
|
2022-10-09 21:29:56 +02:00
|
|
|
|
//собираем данные со всех устройств только в случае если пользователь на dashboard
|
|
|
|
|
|
if (currentPageName === "/|") {
|
|
|
|
|
|
parseAllBlob(event.data, ws);
|
|
|
|
|
|
}
|
2022-01-24 00:57:27 +01:00
|
|
|
|
}
|
2021-12-08 22:59:21 +01:00
|
|
|
|
});
|
|
|
|
|
|
socket[ws].addEventListener("close", (event) => {
|
2021-12-11 13:54:28 +01:00
|
|
|
|
if (debug) console.log("[e]", ip, "connection closed");
|
2022-10-29 01:42:51 +02:00
|
|
|
|
//socket[ws].close();
|
2021-12-09 00:10:10 +01:00
|
|
|
|
markDeviceStatus(ws, false);
|
2021-12-08 22:59:21 +01:00
|
|
|
|
});
|
|
|
|
|
|
socket[ws].addEventListener("error", function (event) {
|
2021-12-11 13:54:28 +01:00
|
|
|
|
if (debug) console.log("[e]", ip, "connection error");
|
2022-10-29 01:42:51 +02:00
|
|
|
|
//socket[ws].close();
|
2021-12-09 00:10:10 +01:00
|
|
|
|
markDeviceStatus(ws, false);
|
2021-12-08 22:59:21 +01:00
|
|
|
|
});
|
2021-12-10 14:44:00 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
if (debug) console.log("[e]", "socket not exist");
|
2021-12-06 01:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-07 22:14:59 +01:00
|
|
|
|
|
2023-06-13 21:06:04 +02:00
|
|
|
|
async function parseBlob(blob, ws) {
|
2022-10-09 14:31:07 +02:00
|
|
|
|
//получаем заголовок
|
|
|
|
|
|
var blobHeader = blob.slice(0, 6);
|
|
|
|
|
|
let header = await blobHeader.text();
|
2022-10-07 22:29:04 +02:00
|
|
|
|
//console.log("header: ", header);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
//получаем размер
|
|
|
|
|
|
var blobSize = blob.slice(7, 11);
|
|
|
|
|
|
let size = await blobSize.text();
|
2022-10-07 22:29:04 +02:00
|
|
|
|
//console.log("size: ", size);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
|
|
|
|
|
|
if (header === "itemsj") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
itemsJson = out.json;
|
|
|
|
|
|
parsed.itemsJson = true;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "itemsJson: ", itemsJson);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
parsed.itemsJson = false;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "itemsJson parse error");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (header === "widget") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
widgetsJson = out.json;
|
|
|
|
|
|
parsed.widgetsJson = true;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "widgetsJson: ", widgetsJson);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
parsed.widgetsJson = false;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "widgetsJson parse error");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (header === "config") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
configJson = out.json;
|
|
|
|
|
|
parsed.configJson = true;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "configJson: ", configJson);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
parsed.configJson = false;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "configJson parse error");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (header === "scenar") {
|
|
|
|
|
|
scenarioTxt = await getPayloadAsTxt(blob, size);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (blobDebug) console.log("[i]", "scenarioTxt: ", scenarioTxt);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (header === "settin") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
settingsJson = out.json;
|
|
|
|
|
|
parsed.settingsJson = true;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "settingsJson: ", settingsJson);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
parsed.settingsJson = false;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "settingsJson parse error");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (header === "ssidli") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
ssidJson = out.json;
|
|
|
|
|
|
parsed.ssidJson = true;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "ssidJson: ", ssidJson);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
parsed.ssidJson = false;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "ssidJson parse error");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//прием данных об ошибках
|
2022-10-09 14:31:07 +02:00
|
|
|
|
if (header === "errors") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
errorsJson = out.json;
|
|
|
|
|
|
parsed.errorsJson = true;
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//когда запустили обновление предотвращаем попытки проверки связи
|
|
|
|
|
|
if (errorsJson.upd === 1) {
|
|
|
|
|
|
preventReconnect = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//когда устройство обновилось переподключимся через 5ть секунд
|
|
|
|
|
|
if (errorsJson.upd === 5) {
|
|
|
|
|
|
preventReconnect = false;
|
|
|
|
|
|
timeout = 20;
|
|
|
|
|
|
}
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "errorsJson: ", errorsJson);
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
parsed.errorsJson = false;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "errorsJson parse error");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//приход списка устройств
|
2022-10-09 14:31:07 +02:00
|
|
|
|
if (header === "devlis") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
incDeviceList = [];
|
2022-10-09 14:31:07 +02:00
|
|
|
|
incDeviceList = out.json;
|
|
|
|
|
|
parsed.incDeviceList = true;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "incDeviceList: ", incDeviceList);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
await initDevList();
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
parsed.incDeviceList = false;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "incDeviceList parse error");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (header === "corelg") {
|
|
|
|
|
|
let txt = await getPayloadAsTxt(blob, size);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//console.log("[--]", ws, txt);
|
2022-10-09 17:03:41 +02:00
|
|
|
|
addCoreMsg(txt);
|
|
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
|
2023-06-17 22:26:52 +02:00
|
|
|
|
await onParced();
|
2022-10-07 22:29:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-09 21:29:56 +02:00
|
|
|
|
async function parseAllBlob(blob, ws) {
|
|
|
|
|
|
//получаем заголовок
|
|
|
|
|
|
var blobHeader = blob.slice(0, 6);
|
|
|
|
|
|
let header = await blobHeader.text();
|
|
|
|
|
|
//console.log("header: ", header);
|
|
|
|
|
|
//получаем размер
|
|
|
|
|
|
var blobSize = blob.slice(7, 11);
|
|
|
|
|
|
let size = await blobSize.text();
|
|
|
|
|
|
//console.log("size: ", size);
|
|
|
|
|
|
|
|
|
|
|
|
if (header === "status") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
let statusJson = out.json;
|
|
|
|
|
|
updateWidget(statusJson);
|
|
|
|
|
|
//if (blobDebug)
|
|
|
|
|
|
console.log("[✔]", "statusJson: ", statusJson);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (blobDebug) console.log("[e]", "statusJson parse error");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (header === "layout") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
let devLayout = out.json;
|
|
|
|
|
|
combineLayoutsInOne(ws, devLayout);
|
|
|
|
|
|
if (blobDebug) console.log("[✔]", "devLayout: ", devLayout);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (blobDebug) console.log("[e]", "devLayout parse error");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (header === "params") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
let devParams = out.json;
|
|
|
|
|
|
paramsJson = {
|
|
|
|
|
|
...paramsJson,
|
|
|
|
|
|
...devParams,
|
|
|
|
|
|
};
|
|
|
|
|
|
paramsJson = paramsJson;
|
|
|
|
|
|
updateAllStatuses(ws);
|
|
|
|
|
|
onParced();
|
|
|
|
|
|
if (blobDebug) console.log("[✔]", "devParams: ", devParams);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (blobDebug) console.log("[e]", "devParams parse error");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (header === "charta") {
|
|
|
|
|
|
let txt = await getPayloadAsTxt(blob, size);
|
|
|
|
|
|
txt = "[" + txt.substring(0, txt.length - 1) + "]";
|
|
|
|
|
|
let chartJson;
|
|
|
|
|
|
try {
|
|
|
|
|
|
chartJson = JSON.parse(txt);
|
|
|
|
|
|
if (blobDebug) console.log("[i]", "chart data json: ", chartJson);
|
|
|
|
|
|
} catch (e) {
|
2022-10-10 00:16:36 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "chart json data parce error, return");
|
2022-10-09 21:29:56 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
let addJson = {};
|
|
|
|
|
|
if (await getJsonAsJson(blob, size, out)) {
|
|
|
|
|
|
addJson = out.json;
|
|
|
|
|
|
if (blobDebug) console.log("[i]", "chart add json: ", addJson);
|
|
|
|
|
|
} else {
|
2022-10-10 00:16:36 +02:00
|
|
|
|
if (blobDebug) console.log("[e]", "chart json add-ns parce error, return");
|
2022-10-09 21:29:56 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let finalDataJson = {};
|
|
|
|
|
|
finalDataJson.status = chartJson;
|
|
|
|
|
|
|
|
|
|
|
|
finalDataJson = {
|
|
|
|
|
|
...finalDataJson,
|
|
|
|
|
|
...addJson,
|
|
|
|
|
|
};
|
2022-10-10 00:16:36 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "chartJson: ", finalDataJson);
|
2022-10-09 21:29:56 +02:00
|
|
|
|
apdateWidgetByArray(finalDataJson);
|
|
|
|
|
|
}
|
2022-10-10 00:16:36 +02:00
|
|
|
|
if (header === "chartb") {
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
if (await getPayloadAsJson(blob, size, out)) {
|
|
|
|
|
|
let status = out.json;
|
|
|
|
|
|
apdateWidgetByArray(status);
|
|
|
|
|
|
if (blobDebug) console.log("[✔]", "chart status: ", status);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (blobDebug) console.log("[e]", "status parse error");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-09 21:29:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-09 14:31:07 +02:00
|
|
|
|
async function getJsonAsJson(blob, size, out) {
|
|
|
|
|
|
let partBlob = blob.slice(12, size);
|
|
|
|
|
|
let txt = await partBlob.text();
|
|
|
|
|
|
try {
|
|
|
|
|
|
out.json = JSON.parse(txt);
|
|
|
|
|
|
out.parse = true;
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (debug) console.log("[e]", "json parce error: ", txt);
|
|
|
|
|
|
out.parse = false;
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
return out.parse;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getPayloadAsJson(blob, size, out) {
|
|
|
|
|
|
let partBlob = blob.slice(size, blob.length);
|
|
|
|
|
|
let txt = await partBlob.text();
|
|
|
|
|
|
try {
|
|
|
|
|
|
out.json = JSON.parse(txt);
|
|
|
|
|
|
out.parse = true;
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (debug) console.log("[e]", "json parse error: ", txt);
|
|
|
|
|
|
out.parse = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return out.parse;
|
|
|
|
|
|
}
|
2022-09-26 01:29:52 +02:00
|
|
|
|
|
2022-10-09 14:31:07 +02:00
|
|
|
|
async function getPayloadAsTxt(blob, size) {
|
2022-10-09 17:03:41 +02:00
|
|
|
|
let txtBlob = blob.slice(size, blob.length);
|
|
|
|
|
|
let txt = await txtBlob.text();
|
|
|
|
|
|
return txt;
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
2022-09-26 01:29:52 +02:00
|
|
|
|
|
2022-10-09 14:31:07 +02:00
|
|
|
|
async function onParced() {
|
2022-10-09 21:29:56 +02:00
|
|
|
|
if (currentPageName === "/|") {
|
|
|
|
|
|
pageReady.dash = true;
|
|
|
|
|
|
}
|
2022-09-26 01:29:52 +02:00
|
|
|
|
|
2022-10-09 14:31:07 +02:00
|
|
|
|
if (currentPageName === "/config|" && parsed.itemsJson && parsed.widgetsJson && parsed.configJson && parsed.settingsJson) {
|
|
|
|
|
|
clearParcedFlags();
|
|
|
|
|
|
pageReady.config = true;
|
2022-09-26 01:29:52 +02:00
|
|
|
|
if (debug) console.log("✔✔", "config page parced");
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
if (currentPageName === "/connection|" && parsed.ssidJson && parsed.settingsJson && parsed.errorsJson) {
|
2022-09-26 16:20:00 +02:00
|
|
|
|
clearParcedFlags();
|
|
|
|
|
|
if (debug) console.log("✔✔", "connection page parced");
|
|
|
|
|
|
pageReady.connection = true;
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (currentPageName === "/list|" && parsed.settingsJson) {
|
2022-09-26 16:20:00 +02:00
|
|
|
|
clearParcedFlags();
|
|
|
|
|
|
if (debug) console.log("✔✔", "list page parced");
|
|
|
|
|
|
pageReady.list = true;
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
|
|
|
|
|
|
if (currentPageName === "/system|" && parsed.errorsJson && parsed.settingsJson) {
|
2022-09-26 16:20:00 +02:00
|
|
|
|
clearParcedFlags();
|
|
|
|
|
|
getVersionsList();
|
|
|
|
|
|
if (debug) console.log("✔✔", "system page parced");
|
|
|
|
|
|
pageReady.system = true;
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
|
2022-10-12 03:18:04 +02:00
|
|
|
|
if (currentPageName === "/dev|" && parsed.errorsJson && parsed.settingsJson && parsed.configJson && parsed.itemsJson) {
|
|
|
|
|
|
clearParcedFlags();
|
|
|
|
|
|
if (debug) console.log("✔✔", "dev page parced");
|
|
|
|
|
|
pageReady.dev = true;
|
|
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-13 21:06:04 +02:00
|
|
|
|
async function initDevList() {
|
2022-10-09 14:31:07 +02:00
|
|
|
|
if (firstDevListRequest) {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//при первом запросе листа устройств запишем его целеком
|
2023-06-11 17:01:57 +02:00
|
|
|
|
devListOverride();
|
2022-10-09 14:31:07 +02:00
|
|
|
|
} else {
|
2023-06-08 22:37:43 +02:00
|
|
|
|
//при последующих прилетах списка устройств мы переписываем в массиве только то что изменилось
|
2023-06-11 17:01:57 +02:00
|
|
|
|
devListCombine();
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2022-10-09 14:31:07 +02:00
|
|
|
|
firstDevListRequest = false;
|
|
|
|
|
|
deviceList = deviceList;
|
|
|
|
|
|
parsed.deviceListJson = true;
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (blobDebug) console.log("[✔]", "deviceList parced");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
onParced();
|
2023-06-11 17:01:57 +02:00
|
|
|
|
selectedDeviceDataRefresh();
|
2023-06-08 22:37:43 +02:00
|
|
|
|
//затем подключимся к всему полученному списку устройств
|
2022-10-09 14:31:07 +02:00
|
|
|
|
connectToAllDevices();
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2023-06-13 21:06:04 +02:00
|
|
|
|
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//перезапись листа устройств
|
2023-06-13 21:06:04 +02:00
|
|
|
|
async function devListOverride() {
|
2023-06-11 17:01:57 +02:00
|
|
|
|
deviceList = incDeviceList;
|
|
|
|
|
|
sortList(deviceList);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//установим заведомо статус уже присутствующего устроства в true для того что бы предотвратить повторное подключение!!!
|
|
|
|
|
|
deviceList[0].status = true;
|
2023-06-11 17:01:57 +02:00
|
|
|
|
console.log("[i]", "[devlist]", "devlist overrided");
|
|
|
|
|
|
}
|
2023-06-13 21:06:04 +02:00
|
|
|
|
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//добавление только новых элементов в лист устройств (если такого ip не было)
|
2023-06-13 21:06:04 +02:00
|
|
|
|
async function devListCombine() {
|
2023-06-11 17:01:57 +02:00
|
|
|
|
deviceList = combineArrays(deviceList, incDeviceList);
|
|
|
|
|
|
sortList(deviceList);
|
|
|
|
|
|
console.log("[i]", "[devlist]", "devlist combined");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sortList(list) {
|
|
|
|
|
|
let firstDev = list.shift();
|
|
|
|
|
|
list.sort(function (a, b) {
|
|
|
|
|
|
if (a.name < b.name) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a.name > b.name) {
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
});
|
|
|
|
|
|
list.unshift(firstDev);
|
|
|
|
|
|
}
|
2022-09-25 17:49:24 +02:00
|
|
|
|
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//***********************************************************dashboard***************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
//слияние layout-ов всех устройств в общий layout
|
2022-10-09 21:29:56 +02:00
|
|
|
|
async function combineLayoutsInOne(ws, devLayout) {
|
|
|
|
|
|
for (let i = 0; i < devLayout.length; i++) {
|
|
|
|
|
|
devLayout[i].ws = ws;
|
|
|
|
|
|
}
|
|
|
|
|
|
layoutJson = layoutJson.concat(devLayout);
|
|
|
|
|
|
console.log("[2]", ws, "devLayout pushed to layout");
|
|
|
|
|
|
sortingLayout(ws);
|
2022-03-01 01:43:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-07 22:29:04 +02:00
|
|
|
|
function sortingLayout(ws) {
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//сортируем весь layout по алфавиту
|
|
|
|
|
|
layoutJson.sort(function (a, b) {
|
|
|
|
|
|
if (a.descr < b.descr) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a.descr > b.descr) {
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
});
|
|
|
|
|
|
//формируем json всех карточек
|
|
|
|
|
|
pages = [];
|
|
|
|
|
|
const newPage = Array.from(new Set(Array.from(layoutJson, ({ page }) => page)));
|
|
|
|
|
|
newPage.forEach(function (item, i, arr) {
|
|
|
|
|
|
pages = [
|
|
|
|
|
|
...pages,
|
|
|
|
|
|
JSON.parse(
|
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
|
page: item,
|
|
|
|
|
|
})
|
|
|
|
|
|
),
|
|
|
|
|
|
];
|
|
|
|
|
|
});
|
|
|
|
|
|
//сортируем карточки по алфавиту
|
|
|
|
|
|
pages.sort(function (a, b) {
|
|
|
|
|
|
if (a.page < b.page) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a.page > b.page) {
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
});
|
2022-09-25 17:49:24 +02:00
|
|
|
|
|
2022-09-18 18:11:50 +02:00
|
|
|
|
layoutJson = layoutJson;
|
2022-10-07 22:29:04 +02:00
|
|
|
|
console.log("[3]", ws, "layout sort, requested params...");
|
|
|
|
|
|
wsSendMsg(ws, "/params|");
|
2022-09-18 18:11:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function updateAllStatuses(ws) {
|
2022-03-01 01:43:55 +01:00
|
|
|
|
for (const [key, value] of Object.entries(paramsJson)) {
|
2022-09-18 18:11:50 +02:00
|
|
|
|
for (let i = 0; i < layoutJson.length; i++) {
|
|
|
|
|
|
let topic = layoutJson[i].topic;
|
2022-09-10 02:59:03 +02:00
|
|
|
|
if (topic) {
|
2022-09-19 05:03:43 +02:00
|
|
|
|
//layoutJson[i].ws = ws;
|
2022-09-10 02:59:03 +02:00
|
|
|
|
topic = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
|
|
|
|
|
|
if (key === topic) {
|
2022-09-18 18:11:50 +02:00
|
|
|
|
console.log("[i]", "updated =>" + topic, value);
|
|
|
|
|
|
layoutJson[i].status = value;
|
2022-09-10 02:59:03 +02:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2022-02-27 01:49:03 +01:00
|
|
|
|
}
|
2022-03-01 01:43:55 +01:00
|
|
|
|
}
|
2022-02-25 17:57:47 +01:00
|
|
|
|
}
|
2022-09-25 21:59:50 +02:00
|
|
|
|
wsSendMsg(ws, "/charts|");
|
2022-02-26 01:09:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//обработка интервально прилетающих статусов
|
|
|
|
|
|
function updateWidget(newStatusJson) {
|
2022-02-26 01:09:17 +01:00
|
|
|
|
for (let i = 0; i < layoutJson.length; i++) {
|
|
|
|
|
|
let topic = layoutJson[i].topic;
|
|
|
|
|
|
if (topic === newStatusJson.topic) {
|
2022-09-11 01:30:38 +02:00
|
|
|
|
layoutJson[i] = jsonConcat(layoutJson[i], newStatusJson);
|
2022-08-16 00:54:14 +02:00
|
|
|
|
//получен ответ - выключаем красный цвет
|
|
|
|
|
|
layoutJson[i].sent = false;
|
2022-02-26 01:09:17 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-02-25 17:57:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//если статус виджета это массив и его нужно накопить
|
2022-10-07 22:29:04 +02:00
|
|
|
|
//должна вызываться когда весь layout в сборе
|
|
|
|
|
|
async function apdateWidgetByArray(newStatusJson) {
|
2022-09-18 18:11:50 +02:00
|
|
|
|
console.log("[i]", "collecting arrays");
|
|
|
|
|
|
let error = true;
|
|
|
|
|
|
if (layoutJson.length > 0) {
|
|
|
|
|
|
for (let i = 0; i < layoutJson.length; i++) {
|
|
|
|
|
|
let topic = layoutJson[i].topic;
|
|
|
|
|
|
if (topic === newStatusJson.topic) {
|
|
|
|
|
|
error = false;
|
|
|
|
|
|
layoutJson[i] = jsonConcatEx(layoutJson[i], newStatusJson);
|
|
|
|
|
|
let prevArr = layoutJson[i].status; //который был в layout
|
|
|
|
|
|
let newArr = newStatusJson.status; //тот что получили
|
|
|
|
|
|
if (prevArr) {
|
|
|
|
|
|
//если что то было в layout то делаем слияние
|
|
|
|
|
|
prevArr = [...prevArr, ...newArr];
|
|
|
|
|
|
layoutJson[i].status = prevArr;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//если ничего не было то просто запишем новый
|
|
|
|
|
|
layoutJson[i].status = newArr;
|
|
|
|
|
|
}
|
|
|
|
|
|
//получен ответ - выключаем красный цвет
|
|
|
|
|
|
layoutJson[i].sent = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("[E]", "layoutJson missing");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (error) console.log("[E]", "topic not found ", newStatusJson.topic);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-11 01:30:38 +02:00
|
|
|
|
function jsonConcat(o1, o2) {
|
|
|
|
|
|
for (var key in o2) {
|
|
|
|
|
|
o1[key] = o2[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
return o1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//объединяем исклчая статус так как статус в данном случае накопительная переменная
|
|
|
|
|
|
function jsonConcatEx(o1, o2) {
|
|
|
|
|
|
for (var key in o2) {
|
|
|
|
|
|
if (key !== "status") {
|
|
|
|
|
|
o1[key] = o2[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return o1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-31 01:45:42 +01:00
|
|
|
|
function saveConfig() {
|
2022-02-09 16:43:24 +01:00
|
|
|
|
wsSendMsg(selectedWs, "/tuoyal|" + JSON.stringify(generateLayout()));
|
2022-09-18 19:26:23 +02:00
|
|
|
|
modify();
|
2022-02-09 16:43:24 +01:00
|
|
|
|
wsSendMsg(selectedWs, "/gifnoc|" + JSON.stringify(configJson));
|
2022-09-29 23:34:21 +02:00
|
|
|
|
|
|
|
|
|
|
wsSendMsg(selectedWs, "/oiranecs|" + scenarioTxt);
|
2022-01-17 00:08:26 +01:00
|
|
|
|
clearData();
|
2023-06-13 21:06:04 +02:00
|
|
|
|
sendCurrentPageNameToSelectedWs();
|
2022-01-17 00:08:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
|
function saveSett() {
|
|
|
|
|
|
var size = Object.keys(settingsJson).length;
|
2023-06-08 22:37:43 +02:00
|
|
|
|
console.log("[i]", "settingsJson length: " + size);
|
2022-02-12 03:07:59 +01:00
|
|
|
|
if (size > 5) {
|
2022-02-15 15:22:54 +01:00
|
|
|
|
jsonArrWrite(deviceList, "ip", getIP(selectedWs), "name", settingsJson.name);
|
|
|
|
|
|
deviceList = deviceList;
|
2022-02-12 03:07:59 +01:00
|
|
|
|
wsSendMsg(selectedWs, "/sgnittes|" + JSON.stringify(settingsJson));
|
|
|
|
|
|
} else {
|
2023-06-08 22:37:43 +02:00
|
|
|
|
window.alert("Ошибка размера settingsJson (возможно не был передан странице)");
|
2022-02-12 03:07:59 +01:00
|
|
|
|
}
|
2022-02-02 23:37:15 +01:00
|
|
|
|
clearData();
|
2023-06-13 21:06:04 +02:00
|
|
|
|
sendCurrentPageNameToSelectedWs();
|
2022-02-02 23:37:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 22:37:43 +02:00
|
|
|
|
function saveList() {
|
|
|
|
|
|
//при сохранении списка в память необходимо удалить все статусы
|
|
|
|
|
|
let devListForSave = Object.assign([], deviceList);
|
|
|
|
|
|
for (let i = 0; i < devListForSave.length; i++) {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
//delete devListForSave[i].status;
|
|
|
|
|
|
devListForSave[i].status = false;
|
2023-06-08 22:37:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
wsSendMsg(selectedWs, "/tsil|" + JSON.stringify(devListForSave));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-26 00:01:29 +02:00
|
|
|
|
function cleanLogs() {
|
2022-09-15 12:22:39 +02:00
|
|
|
|
wsSendMsg(selectedWs, "/clean|");
|
2022-08-26 00:01:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
|
function saveMqtt() {
|
|
|
|
|
|
var size = Object.keys(settingsJson).length;
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//console.log("[i]", "settingsJson length: " + size);
|
2022-02-12 03:07:59 +01:00
|
|
|
|
if (size > 5) {
|
|
|
|
|
|
wsSendMsg(selectedWs, "/sgnittes|" + JSON.stringify(settingsJson));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.alert("Ошибка");
|
|
|
|
|
|
}
|
|
|
|
|
|
clearData();
|
|
|
|
|
|
wsSendMsg(selectedWs, "/mqtt|");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-11 14:14:16 +02:00
|
|
|
|
function getInput() {
|
|
|
|
|
|
let input = {
|
|
|
|
|
|
name: "inputDate",
|
2022-09-13 22:44:37 +02:00
|
|
|
|
//descr: "Выберите дату",
|
2022-09-11 14:14:16 +02:00
|
|
|
|
widget: "input",
|
|
|
|
|
|
size: "small",
|
|
|
|
|
|
color: "orange",
|
|
|
|
|
|
type: "date",
|
|
|
|
|
|
};
|
|
|
|
|
|
return input;
|
|
|
|
|
|
}
|
2022-09-10 02:59:03 +02:00
|
|
|
|
|
2022-09-18 19:26:23 +02:00
|
|
|
|
function modify() {
|
2022-09-14 18:20:07 +02:00
|
|
|
|
for (let i = 0; i < configJson.length; i++) {
|
|
|
|
|
|
let config = configJson[i];
|
|
|
|
|
|
delete config["show"];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//по конфигу делаем виджеты
|
2022-01-31 01:45:42 +01:00
|
|
|
|
function generateLayout() {
|
|
|
|
|
|
let layout = [];
|
|
|
|
|
|
for (let i = 0; i < configJson.length; i++) {
|
2022-02-02 23:37:15 +01:00
|
|
|
|
let config = Object.assign({}, configJson[i]);
|
2022-01-31 01:45:42 +01:00
|
|
|
|
let setWidget = config.widget;
|
|
|
|
|
|
let error = true;
|
|
|
|
|
|
for (let w = 0; w < widgetsJson.length; w++) {
|
|
|
|
|
|
if (setWidget === widgetsJson[w].name) {
|
2022-02-02 23:37:15 +01:00
|
|
|
|
let widget = Object.assign({}, widgetsJson[w]);
|
2022-01-31 01:45:42 +01:00
|
|
|
|
widget.page = config.page;
|
|
|
|
|
|
widget.descr = config.descr;
|
2022-09-11 14:14:16 +02:00
|
|
|
|
|
2022-02-04 00:03:52 +01:00
|
|
|
|
widget.topic = settingsJson.root + "/" + config.id;
|
2022-09-27 01:24:37 +02:00
|
|
|
|
if (setWidget !== "nil") layout.push(widget);
|
2022-09-28 17:26:33 +02:00
|
|
|
|
//создаем графики с окнами ввода
|
|
|
|
|
|
if (widget.widget === "chart" && widget.type !== "bar") {
|
2022-09-11 14:14:16 +02:00
|
|
|
|
let input = getInput();
|
2022-09-10 02:59:03 +02:00
|
|
|
|
input.page = config.page;
|
2022-09-13 22:44:37 +02:00
|
|
|
|
input.topic = settingsJson.root + "/" + config.id + "-date";
|
|
|
|
|
|
input.descr = config.descr;
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//console.log("[i]", "topic ", widget.topic);
|
2022-09-10 02:59:03 +02:00
|
|
|
|
layout.push(input);
|
|
|
|
|
|
}
|
2022-01-31 01:45:42 +01:00
|
|
|
|
error = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-09-18 18:11:50 +02:00
|
|
|
|
if (error) console.log("[E]", "error, widget not found: " + setWidget);
|
2022-01-31 01:45:42 +01:00
|
|
|
|
}
|
2022-10-07 22:29:04 +02:00
|
|
|
|
|
|
|
|
|
|
//сортируем весь layout по алфавиту
|
|
|
|
|
|
layout.sort(function (a, b) {
|
|
|
|
|
|
if (a.descr < b.descr) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a.descr > b.descr) {
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < layout.length; i++) {
|
|
|
|
|
|
layout[i].order = i;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 00:42:28 +01:00
|
|
|
|
return layout;
|
2022-01-31 01:45:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-17 00:08:26 +01:00
|
|
|
|
function clearData() {
|
2022-02-02 23:37:15 +01:00
|
|
|
|
itemsJson = [];
|
2022-10-10 00:16:36 +02:00
|
|
|
|
widgetsJson = [];
|
|
|
|
|
|
configJson = [];
|
2022-10-12 03:18:04 +02:00
|
|
|
|
scenarioTxt = " ";
|
2022-02-23 22:56:17 +01:00
|
|
|
|
settingsJson = {};
|
2022-10-10 00:16:36 +02:00
|
|
|
|
//ssidJson = {};
|
2022-02-08 16:47:26 +01:00
|
|
|
|
errorsJson = {};
|
2022-10-10 00:16:36 +02:00
|
|
|
|
layoutJson = [];
|
|
|
|
|
|
paramsJson = {}; //?
|
2022-02-19 23:35:30 +01:00
|
|
|
|
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//incDeviceList = [];
|
2023-06-08 22:37:43 +02:00
|
|
|
|
|
2022-09-25 17:49:24 +02:00
|
|
|
|
for (const [key, value] of Object.entries(pageReady)) {
|
|
|
|
|
|
pageReady[key] = false;
|
|
|
|
|
|
}
|
2022-02-13 00:37:58 +01:00
|
|
|
|
|
|
|
|
|
|
clearParcedFlags();
|
|
|
|
|
|
|
2022-10-09 17:03:41 +02:00
|
|
|
|
if (debug) console.log("[i]", "all json files cleared");
|
2022-01-17 00:08:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
|
function clearParcedFlags() {
|
2022-10-07 22:29:04 +02:00
|
|
|
|
console.log("[i]", "parced flags cleared");
|
2022-10-09 14:31:07 +02:00
|
|
|
|
for (const [key, value] of Object.entries(parsed)) {
|
|
|
|
|
|
parsed[key] = false;
|
2022-09-25 17:49:24 +02:00
|
|
|
|
}
|
2022-02-26 01:09:17 +01:00
|
|
|
|
clearFlags();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clearFlags() {
|
2023-06-08 22:37:43 +02:00
|
|
|
|
//for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
|
//deviceList[i].pp = false;
|
|
|
|
|
|
//deviceList[i].lp = false;
|
|
|
|
|
|
//}
|
2022-02-13 00:37:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-08 22:59:21 +01:00
|
|
|
|
function wsPush(ws, topic, status) {
|
|
|
|
|
|
let msg = topic + " " + status;
|
2022-08-14 17:13:49 +02:00
|
|
|
|
if (debug) console.log("[i]", "ws: ", ws, msg);
|
2022-09-19 05:03:43 +02:00
|
|
|
|
//layoutJson = layoutJson;
|
2022-08-15 01:30:59 +02:00
|
|
|
|
let key = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
|
|
|
|
|
|
wsSendMsg(ws, "/control|" + key + "/" + status);
|
2021-12-08 22:59:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-09 01:00:14 +02:00
|
|
|
|
function scale(number, inMin, inMax, outMin, outMax) {
|
|
|
|
|
|
return ((number - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-07 22:14:59 +01:00
|
|
|
|
function wsTestMsgTask() {
|
2023-06-09 01:00:14 +02:00
|
|
|
|
setTimeout(wsTestMsgTask, 1000);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (!preventReconnect) {
|
|
|
|
|
|
timeout--;
|
|
|
|
|
|
percent = scale(timeout, reconnectTimeout / 1000, 0, 0, 100);
|
|
|
|
|
|
if (timeout <= 0) {
|
|
|
|
|
|
if (debug) console.log("[i]", "----timer tick----");
|
|
|
|
|
|
printAllCreatedWs();
|
|
|
|
|
|
timeout = reconnectTimeout / 1000;
|
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
|
if (device.status === false || device.status === undefined) {
|
|
|
|
|
|
wsConnect(device.ws);
|
|
|
|
|
|
wsEventAdd(device.ws);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wsSendMsg(device.ws, "/tst|");
|
|
|
|
|
|
ack(device.ws, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2021-12-10 16:07:09 +01:00
|
|
|
|
}
|
2021-12-08 22:59:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function wsSendMsg(ws, msg) {
|
|
|
|
|
|
if (socket[ws] && socket[ws].readyState === 1) {
|
|
|
|
|
|
socket[ws].send(msg);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (debug) console.log("[i]", getIP(ws), ws, "msg send success", msg);
|
2021-12-08 22:59:21 +01:00
|
|
|
|
} else {
|
2022-10-10 00:16:36 +02:00
|
|
|
|
if (debug) console.log("[e]", getIP(ws), ws, "msg not send");
|
2021-12-07 22:14:59 +01:00
|
|
|
|
}
|
2021-12-06 01:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-15 00:02:30 +01:00
|
|
|
|
function sendToAllDevices(msg) {
|
|
|
|
|
|
deviceList.forEach((device) => {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (device.status === true) {
|
2022-02-15 00:02:30 +01:00
|
|
|
|
wsSendMsg(device.ws, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//***********************************************************logging******************************************************************/
|
2021-12-07 22:14:59 +01:00
|
|
|
|
const addCoreMsg = (msg) => {
|
2022-02-19 23:35:30 +01:00
|
|
|
|
if (coreMessages.length >= LOG_MAX_MESSAGES) {
|
|
|
|
|
|
coreMessages.shift();
|
2021-12-05 00:49:36 +01:00
|
|
|
|
}
|
2022-02-19 23:35:30 +01:00
|
|
|
|
//const time = new Date().getTime();
|
2022-02-07 16:36:43 +01:00
|
|
|
|
coreMessages = [
|
|
|
|
|
|
...coreMessages,
|
|
|
|
|
|
{
|
|
|
|
|
|
msg,
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2021-12-07 22:14:59 +01:00
|
|
|
|
coreMessages.sort(function (a, b) {
|
2021-12-05 00:49:36 +01:00
|
|
|
|
if (a.time > b.time) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a.time < b.time) {
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2021-12-08 22:59:21 +01:00
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//***********************************************************dev list******************************************************************/
|
2022-02-07 23:40:00 +01:00
|
|
|
|
|
|
|
|
|
|
function combineArrays(A, B) {
|
|
|
|
|
|
var ids = new Set(A.map((d) => d.ip));
|
|
|
|
|
|
let output = [...A, ...B.filter((d) => !ids.has(d.ip))];
|
|
|
|
|
|
return output;
|
2022-02-07 16:36:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//всякий раз когда список устройств был обновлен
|
|
|
|
|
|
function selectedDeviceDataRefresh() {
|
|
|
|
|
|
//запишем в переменную selectedDeviceData выбранное устройство, что бы в коде было известно выбранное устройство
|
2022-02-07 23:40:00 +01:00
|
|
|
|
getSelectedDeviceData(selectedWs);
|
2021-12-09 22:35:04 +01:00
|
|
|
|
socketConnected = selectedDeviceData.status;
|
2022-02-07 23:40:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function devicesDropdownChange() {
|
2023-06-11 17:01:57 +02:00
|
|
|
|
if (currentPageName === "/list|") {
|
|
|
|
|
|
console.log("[i]", "user change dropdown on list page!!!");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
selectedDeviceDataRefresh();
|
|
|
|
|
|
clearData();
|
|
|
|
|
|
//запускаем навигацию что дать контроллеру запрос данных
|
|
|
|
|
|
handleNavigation();
|
|
|
|
|
|
if (debug) console.log("[i]", "user selected device:", selectedDeviceData.name);
|
|
|
|
|
|
if (selectedDeviceData.ip === myip) {
|
|
|
|
|
|
originalWs = selectedWs;
|
|
|
|
|
|
if (debug) console.log("[i]", "user selected original device", selectedDeviceData.name);
|
|
|
|
|
|
}
|
2021-12-13 00:01:21 +01:00
|
|
|
|
}
|
2021-12-09 22:35:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 22:37:43 +02:00
|
|
|
|
//функция которая записывает в переменную данные выбранного юзером устройства
|
2022-02-07 23:40:00 +01:00
|
|
|
|
function getSelectedDeviceData(ws) {
|
|
|
|
|
|
for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
|
let device = deviceList[i];
|
|
|
|
|
|
if (device.ws === ws) {
|
|
|
|
|
|
selectedDeviceData = device;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
|
function addDevInList() {
|
2021-12-12 00:20:47 +01:00
|
|
|
|
if (!showInput) {
|
|
|
|
|
|
if (newDevice.name !== undefined && newDevice.ip !== undefined && newDevice.id !== undefined) {
|
|
|
|
|
|
newDevice.status = false;
|
2023-06-11 17:01:57 +02:00
|
|
|
|
newDevice.ws = deviceList.length;
|
|
|
|
|
|
incDeviceList.push(newDevice);
|
|
|
|
|
|
devListCombine();
|
|
|
|
|
|
//onParced();
|
|
|
|
|
|
//selectedDeviceDataRefresh();
|
2021-12-12 00:20:47 +01:00
|
|
|
|
connectToAllDevices();
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (debug) console.log("[i]", "selected device: ", selectedDeviceData);
|
2023-06-11 17:01:57 +02:00
|
|
|
|
return true;
|
2021-12-12 00:20:47 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
if (debug) console.log("[e]", "wrong data");
|
2023-06-11 17:01:57 +02:00
|
|
|
|
return false;
|
2021-12-12 00:20:47 +01:00
|
|
|
|
}
|
2021-12-13 02:36:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-07 23:40:00 +01:00
|
|
|
|
function updateThisDeviceInList() {
|
|
|
|
|
|
for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
|
let device = deviceList[i];
|
|
|
|
|
|
if (device.ip === myip) {
|
|
|
|
|
|
device.name = settingsJson.name;
|
|
|
|
|
|
device.id = settingsJson.id;
|
|
|
|
|
|
settingsJson = settingsJson;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//****************************************************************json******************************************************************/
|
2021-12-14 20:55:53 +01:00
|
|
|
|
function getJsonObject(array, number) {
|
|
|
|
|
|
let num = 0;
|
|
|
|
|
|
let out = {};
|
|
|
|
|
|
array.forEach((object) => {
|
|
|
|
|
|
if (num === number) {
|
|
|
|
|
|
out = object;
|
|
|
|
|
|
}
|
|
|
|
|
|
num++;
|
|
|
|
|
|
});
|
|
|
|
|
|
return out;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const syntaxHighlight = (json) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
json = JSON.stringify(JSON.parse(json), null, 4);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
return json;
|
|
|
|
|
|
}
|
|
|
|
|
|
json = json.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
|
|
|
|
json = json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
|
|
|
|
|
|
return match;
|
|
|
|
|
|
});
|
|
|
|
|
|
return json;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-12-25 00:20:49 +01:00
|
|
|
|
function IsJsonParse(str) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
JSON.parse(str);
|
|
|
|
|
|
} catch (e) {
|
2022-02-27 01:49:03 +01:00
|
|
|
|
if (debug) console.log("[e]", "json parce error: ", str);
|
2021-12-25 00:20:49 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-17 22:19:14 +01:00
|
|
|
|
//пример как формировать массив json
|
|
|
|
|
|
function createWidgetsDropdown() {
|
|
|
|
|
|
let widgetsDropdown = [];
|
2022-01-22 00:15:22 +01:00
|
|
|
|
widgetsJson.forEach((widget) => {
|
2022-01-17 22:19:14 +01:00
|
|
|
|
widgetsDropdown.push({
|
|
|
|
|
|
id: widget.name,
|
|
|
|
|
|
val: widget.rus,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
widgetsDropdown = widgetsDropdown;
|
|
|
|
|
|
if (debug) console.log("[i]", widgetsDropdown);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-15 15:22:54 +01:00
|
|
|
|
function jsonArrWrite(jsonArr, idKey, idValue, paramKey, paramValue) {
|
|
|
|
|
|
for (let i = 0; i < jsonArr.length; i++) {
|
|
|
|
|
|
let obj = jsonArr[i];
|
|
|
|
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
|
|
|
|
if (key == idKey && value == idValue) {
|
|
|
|
|
|
obj[paramKey] = paramValue;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//**********************************************************post and get*****************************************************************/
|
2021-12-22 00:28:00 +01:00
|
|
|
|
//editRequest("192.168.88.235", "data data data data", "file.json")
|
|
|
|
|
|
|
|
|
|
|
|
function editRequest(url, data, filename) {
|
|
|
|
|
|
if (debug) console.log("[i]", "request for edit file");
|
|
|
|
|
|
var xmlHttp = new XMLHttpRequest();
|
|
|
|
|
|
var formData = new FormData();
|
2022-02-07 16:36:43 +01:00
|
|
|
|
formData.append(
|
|
|
|
|
|
"data",
|
|
|
|
|
|
new Blob([data], {
|
|
|
|
|
|
type: "text/json",
|
|
|
|
|
|
}),
|
|
|
|
|
|
"/" + filename
|
|
|
|
|
|
);
|
2021-12-22 00:28:00 +01:00
|
|
|
|
xmlHttp.open("POST", "http://" + url + "/edit");
|
|
|
|
|
|
xmlHttp.onload = function () {
|
|
|
|
|
|
//во время загрузки
|
|
|
|
|
|
};
|
|
|
|
|
|
xmlHttp.send(formData);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function handleSubmit(url) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log(url);
|
|
|
|
|
|
let res = await fetch(url, {
|
|
|
|
|
|
mode: "no-cors",
|
|
|
|
|
|
method: "GET",
|
|
|
|
|
|
});
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
|
console.log("OK", res.status);
|
|
|
|
|
|
//console.log(url);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("error", res.status);
|
|
|
|
|
|
//console.log(url);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getRequestJson(url) {
|
2022-02-18 19:48:15 +01:00
|
|
|
|
try {
|
|
|
|
|
|
let res = await fetch(url, {
|
|
|
|
|
|
mode: "no-cors",
|
|
|
|
|
|
method: "GET",
|
|
|
|
|
|
});
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
|
configSetupJson = await res.json();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("error", res.status);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
2021-12-22 00:28:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//**********************************************************modal*************************************************************************/
|
|
|
|
|
|
function onCheck() {
|
|
|
|
|
|
let width = screen.width;
|
2022-09-18 18:11:50 +02:00
|
|
|
|
//console.log("width", width);
|
2022-02-01 16:01:19 +01:00
|
|
|
|
if (width < 900) {
|
|
|
|
|
|
preventMove = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
preventMove = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************elements and presets dropdown************************************************************/
|
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
|
function ssidClick() {
|
2022-02-09 16:43:24 +01:00
|
|
|
|
wsSendMsg(selectedWs, "/scan|");
|
2022-02-05 02:13:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-08 16:47:26 +01:00
|
|
|
|
function rebootEsp() {
|
|
|
|
|
|
if (debug) console.log("[i]", "reboot...");
|
2022-02-09 16:43:24 +01:00
|
|
|
|
wsSendMsg(selectedWs, "/reboot|");
|
2022-11-22 15:07:41 +01:00
|
|
|
|
markDeviceStatus(selectedWs, false);
|
2023-06-13 21:06:04 +02:00
|
|
|
|
showAwaitingCircle = true;
|
|
|
|
|
|
rebootTimer = setTimeout(rebootingTask, rebootingTimeout);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function applicationReboot() {
|
|
|
|
|
|
console.log("[i]", "reboot svelte...");
|
|
|
|
|
|
for (const [key, value] of Object.entries(pageReady)) {
|
|
|
|
|
|
pageReady[key] = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
showAwaitingCircle = true;
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
location.reload();
|
|
|
|
|
|
}, 1000);
|
2022-02-08 16:47:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function rebootingTask() {
|
2023-06-09 01:00:14 +02:00
|
|
|
|
//перезапуск приложения
|
2023-06-11 17:01:57 +02:00
|
|
|
|
//location.reload();
|
2023-06-13 21:06:04 +02:00
|
|
|
|
clearTimeout(rebootTimer);
|
2023-06-11 17:01:57 +02:00
|
|
|
|
clearData();
|
|
|
|
|
|
connectToAllDevices();
|
2023-06-13 21:06:04 +02:00
|
|
|
|
showAwaitingCircle = false;
|
2022-02-08 16:47:26 +01:00
|
|
|
|
}
|
2022-02-09 16:43:24 +01:00
|
|
|
|
|
|
|
|
|
|
function cancelAlarm(alarmKey) {
|
|
|
|
|
|
console.log("[x]", alarmKey);
|
2022-02-11 16:49:34 +01:00
|
|
|
|
errorsJson[alarmKey] = 0;
|
|
|
|
|
|
wsSendMsg(selectedWs, '/rorre|{"' + alarmKey + '":0}');
|
2022-02-09 16:43:24 +01:00
|
|
|
|
}
|
2022-02-11 19:32:05 +01:00
|
|
|
|
|
2022-02-18 19:48:15 +01:00
|
|
|
|
//************************************************update esp firm************************************************************//
|
|
|
|
|
|
|
|
|
|
|
|
async function getVersionsList() {
|
2022-09-25 17:49:24 +02:00
|
|
|
|
versionsList = {};
|
|
|
|
|
|
if (settingsJson.serverip) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let url = settingsJson.serverip + "/iotm/ver.json";
|
|
|
|
|
|
console.log("url", url);
|
|
|
|
|
|
let res = await fetch(url, {
|
|
|
|
|
|
mode: "cors",
|
|
|
|
|
|
method: "GET",
|
|
|
|
|
|
});
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
|
versionsList = await res.json();
|
|
|
|
|
|
versionsList = versionsList[errorsJson.bn];
|
|
|
|
|
|
choosingVersion = errorsJson.bver;
|
|
|
|
|
|
console.log(JSON.stringify(versionsList));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
choosingVersion = undefined;
|
|
|
|
|
|
console.log("error, versions list not received", res.statusText);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
2022-02-18 19:48:15 +01:00
|
|
|
|
choosingVersion = undefined;
|
2022-09-25 17:49:24 +02:00
|
|
|
|
console.log("error, versions list not received");
|
|
|
|
|
|
console.log(e);
|
2022-02-18 19:48:15 +01:00
|
|
|
|
}
|
2022-09-25 17:49:24 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
console.log("error, server missing");
|
2022-02-18 19:48:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-13 21:06:04 +02:00
|
|
|
|
function startUpdate(all) {
|
2022-02-18 19:48:15 +01:00
|
|
|
|
if (choosingVersion !== undefined) {
|
2022-10-07 22:29:04 +02:00
|
|
|
|
//if (choosingVersion === errorsJson.bver) {
|
|
|
|
|
|
// window.alert("Эта версия уже установленна");
|
|
|
|
|
|
//} else {
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (confirm("После обновления устройство перезагрузится. Запустить обновление?")) {
|
2022-10-07 22:29:04 +02:00
|
|
|
|
console.log("start update...");
|
2023-06-13 21:06:04 +02:00
|
|
|
|
if (all) {
|
|
|
|
|
|
sendToAllDevices('/rorre|{"chver":' + choosingVersion + "}");
|
|
|
|
|
|
sendToAllDevices("/update|");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wsSendMsg(selectedWs, '/rorre|{"chver":' + choosingVersion + "}");
|
|
|
|
|
|
wsSendMsg(selectedWs, "/update|");
|
|
|
|
|
|
}
|
|
|
|
|
|
//showAwaitingCircle = true;
|
|
|
|
|
|
//rebootTimer = setTimeout(rebootingTask, updatingTimeout);
|
2022-02-18 19:48:15 +01:00
|
|
|
|
} else {
|
2022-10-07 22:29:04 +02:00
|
|
|
|
console.log("update canceled");
|
2022-02-18 19:48:15 +01:00
|
|
|
|
}
|
2022-10-07 22:29:04 +02:00
|
|
|
|
//}
|
2022-02-18 19:48:15 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
window.alert("Версия не выбрана или сервер недоступен");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-09-25 21:59:50 +02:00
|
|
|
|
|
|
|
|
|
|
function selectToMarker(str, found) {
|
|
|
|
|
|
let p = str.indexOf(found);
|
|
|
|
|
|
return str.substring(0, p);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function deleteBeforeDelimiter(str, found) {
|
|
|
|
|
|
let p = str.indexOf(found) + found.length;
|
|
|
|
|
|
return str.substring(p);
|
|
|
|
|
|
}
|
2022-10-07 22:29:04 +02:00
|
|
|
|
|
2022-10-29 01:42:51 +02:00
|
|
|
|
function getMillis() {
|
|
|
|
|
|
const d = new Date();
|
|
|
|
|
|
return d.getMilliseconds();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-14 00:52:42 +01:00
|
|
|
|
function moduleOrder(id, key, value) {
|
|
|
|
|
|
console.log("order: ", id, key, value);
|
|
|
|
|
|
let json = {
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
key: key,
|
|
|
|
|
|
value: value,
|
|
|
|
|
|
};
|
|
|
|
|
|
console.log(json);
|
|
|
|
|
|
wsSendMsg(selectedWs, "/order|" + JSON.stringify(json));
|
|
|
|
|
|
}
|
2023-06-17 22:26:52 +02:00
|
|
|
|
|
|
|
|
|
|
function checkPassword(pass) {
|
|
|
|
|
|
if (pass === settingsJson.passw) {
|
|
|
|
|
|
settingsJson.pass = false;
|
|
|
|
|
|
authorization = false;
|
|
|
|
|
|
saveSett();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-09-16 02:00:52 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
<div class="flex flex-col h-screen bg-gray-50">
|
2023-06-13 21:06:04 +02:00
|
|
|
|
{#if showAwaitingCircle}
|
2022-02-08 16:47:26 +01:00
|
|
|
|
<Progress />
|
|
|
|
|
|
{/if}
|
2023-06-17 22:26:52 +02:00
|
|
|
|
|
|
|
|
|
|
<!--{#if authorization}
|
|
|
|
|
|
<ModalPass checkPassword={(pass) => checkPassword(pass)} />
|
|
|
|
|
|
{/if}-->
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
<header class="h-10 w-full bg-gray-100 overflow-auto shadow-md">
|
2022-02-07 16:36:43 +01:00
|
|
|
|
<div class="flex content-center items-center justify-end">
|
2023-06-08 22:37:43 +02:00
|
|
|
|
{#if showDropdown}
|
|
|
|
|
|
<div class="px-15 py-1">
|
|
|
|
|
|
<select class="border border-indigo-500 border-4" bind:value={selectedWs} on:change={() => devicesDropdownChange()}>
|
|
|
|
|
|
{#each deviceList as device}
|
|
|
|
|
|
<option value={device.ws}>
|
|
|
|
|
|
{device.name}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
2022-08-31 22:25:22 +02:00
|
|
|
|
<!--<div class="pl-4 pr-1 py-1">-->
|
|
|
|
|
|
<!--<BookIcon color={socketConnected === true ? "text-green-500" : "text-red-500"} />-->
|
|
|
|
|
|
<!--</div>-->
|
2022-02-07 16:36:43 +01:00
|
|
|
|
<div class="pl-4 pr-4 py-1">
|
|
|
|
|
|
<CloudIcon color={socketConnected === true ? "text-green-500" : "text-red-500"} />
|
2021-12-09 00:10:10 +01:00
|
|
|
|
</div>
|
2021-12-06 01:21:55 +01:00
|
|
|
|
</div>
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
<nav class="flex">
|
2022-02-24 00:59:10 +01:00
|
|
|
|
<input class="w-0 h-0" bind:checked={opened} on:change={() => onCheck()} id="menu__toggle" type="checkbox" />
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
<label class="menu__btn" for="menu__toggle">
|
|
|
|
|
|
<span />
|
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
|
|
<ul class="menu__box">
|
|
|
|
|
|
<li>
|
|
|
|
|
|
<a class="menu__item" href="/">{"Управление"}</a>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
|
|
|
<a class="menu__item" href="/config">{"Конфигуратор"}</a>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
|
|
|
<a class="menu__item" href="/connection">{"Подключение"}</a>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<li>
|
2023-06-13 21:06:04 +02:00
|
|
|
|
<a class="menu__item" href="/system">{"Системные"}</a>
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</li>
|
|
|
|
|
|
<li>
|
2023-06-13 21:06:04 +02:00
|
|
|
|
<a class="menu__item" href="/list">{"Устройства"}</a>
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</li>
|
2022-09-10 02:59:03 +02:00
|
|
|
|
{#if devMode}
|
2023-06-13 21:06:04 +02:00
|
|
|
|
<!--<li>
|
2022-09-10 02:59:03 +02:00
|
|
|
|
<a class="menu__item" href="/dev">{"Разработчик"}</a>
|
2023-06-13 21:06:04 +02:00
|
|
|
|
</li>-->
|
2022-09-10 02:59:03 +02:00
|
|
|
|
{/if}
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</ul>
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
|
|
<main class="flex-1 overflow-y-auto p-0 {opened === true && !preventMove ? 'ml-36' : 'ml-0'}">
|
|
|
|
|
|
<ul class="menu__main">
|
|
|
|
|
|
<div class="bg-cover pt-0 px-4">
|
2022-11-21 00:38:58 +01:00
|
|
|
|
{#if !socketConnected && currentPageName != "/|"}
|
2023-06-09 01:00:14 +02:00
|
|
|
|
<Alarm title="Подключение через {timeout} сек." />
|
2022-02-05 02:13:46 +01:00
|
|
|
|
{:else}
|
|
|
|
|
|
<Route path="/">
|
2022-09-25 17:49:24 +02:00
|
|
|
|
<DashboardPage show={pageReady.dash} layoutJson={layoutJson} pages={pages} wsPush={(ws, topic, status) => wsPush(ws, topic, status)} />
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/config">
|
2023-06-08 22:37:43 +02:00
|
|
|
|
<ConfigPage show={pageReady.config} bind:configJson={configJson} bind:scenarioTxt={scenarioTxt} widgetsJson={widgetsJson} itemsJson={itemsJson} saveConfig={() => saveConfig()} cleanLogs={() => cleanLogs()} rebootEsp={() => rebootEsp()} moduleOrder={(id, key, value) => moduleOrder(id, key, value)} />
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/connection">
|
2022-09-25 17:49:24 +02:00
|
|
|
|
<ConnectionPage show={pageReady.connection} rebootEsp={() => rebootEsp()} ssidClick={() => ssidClick()} saveSett={() => saveSett()} saveMqtt={() => saveMqtt()} settingsJson={settingsJson} errorsJson={errorsJson} ssidJson={ssidJson} />
|
2022-02-13 00:37:58 +01:00
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/list">
|
2023-06-13 21:06:04 +02:00
|
|
|
|
<ListPage show={pageReady.list} deviceList={deviceList} settingsJson={settingsJson} saveSett={() => saveSett()} rebootEsp={() => rebootEsp()} showInput={showInput} addDevInList={() => addDevInList()} newDevice={newDevice} sendToAllDevices={(msg) => sendToAllDevices(msg)} saveList={() => saveList()} percent={percent} devListOverride={() => devListOverride()} applicationReboot={() => applicationReboot()} />
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Route>
|
2022-02-08 21:42:40 +01:00
|
|
|
|
<Route path="/system">
|
2023-06-13 21:06:04 +02:00
|
|
|
|
<SystemPage show={pageReady.system} errorsJson={errorsJson} settingsJson={settingsJson} saveSett={() => saveSett()} rebootEsp={() => rebootEsp()} cleanLogs={() => cleanLogs()} cancelAlarm={(alarmKey) => cancelAlarm(alarmKey)} versionsList={versionsList} bind:choosingVersion={choosingVersion} startUpdate={(all) => startUpdate(all)} coreMessages={coreMessages} />
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Route>
|
2022-09-10 02:59:03 +02:00
|
|
|
|
{#if devMode}
|
|
|
|
|
|
<Route path="/dev">
|
2023-06-08 22:37:43 +02:00
|
|
|
|
<!--<Card title="Кнопка">
|
2022-10-07 22:29:04 +02:00
|
|
|
|
<button class="btn-lg" on:click={() => test()}>{"Тест"}</button>
|
2023-06-08 22:37:43 +02:00
|
|
|
|
</Card>-->
|
2022-09-25 17:49:24 +02:00
|
|
|
|
<DevPage show={pageReady.dev} layoutJson={layoutJson} errorsJson={errorsJson} settingsJson={settingsJson} configJson={configJson} itemsJson={itemsJson} paramsJson={paramsJson} />
|
2022-09-13 22:44:37 +02:00
|
|
|
|
</Route>
|
2022-09-10 02:59:03 +02:00
|
|
|
|
{/if}
|
2022-02-05 02:13:46 +01:00
|
|
|
|
{/if}
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</main>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
|
2023-06-08 22:37:43 +02:00
|
|
|
|
<footer class="h-4 bg-gray-100 border-gray-300 shadow-lg">
|
2022-02-07 16:36:43 +01:00
|
|
|
|
<div class="flex justify-center content-center text-xxs text-gray-500">Developed by Dmitry Borisenko</div>
|
|
|
|
|
|
</footer>
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</div>
|
2021-09-16 02:00:52 +08:00
|
|
|
|
|
|
|
|
|
|
<style lang="postcss" global>
|
|
|
|
|
|
@tailwind base;
|
|
|
|
|
|
@tailwind components;
|
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
|
|
|
|
|
|
|
@layer components {
|
2022-02-07 16:36:43 +01:00
|
|
|
|
/*==================================================grids=====================================================*/
|
|
|
|
|
|
.grd-1col1 {
|
2021-10-16 20:49:17 +00:00
|
|
|
|
@apply grid grid-cols-1 justify-items-center;
|
|
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
.grd-2col1 {
|
2022-02-08 16:47:26 +01:00
|
|
|
|
@apply grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-2 xl:grid-cols-2 2xl:grid-cols-2 justify-items-center;
|
2022-02-07 16:36:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
.grd-2col2 {
|
|
|
|
|
|
@apply grid gap-4 grid-cols-2 justify-items-center;
|
|
|
|
|
|
}
|
|
|
|
|
|
.grd-3col1 {
|
|
|
|
|
|
@apply grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 2xl:grid-cols-3 justify-items-center;
|
|
|
|
|
|
}
|
2023-06-02 15:29:45 +02:00
|
|
|
|
.grd-4col1 {
|
|
|
|
|
|
@apply grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-4 justify-items-center;
|
|
|
|
|
|
}
|
2021-10-20 20:53:07 +08:00
|
|
|
|
/*=============================================card and items inside===============================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.crd-itm-psn {
|
2023-06-02 15:29:45 +02:00
|
|
|
|
@apply flex mb-2 h-6 items-center;
|
2021-10-20 20:53:07 +08:00
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.wgt-dscr-stl {
|
2021-10-20 20:53:07 +08:00
|
|
|
|
@apply pr-4 text-gray-500 font-bold;
|
|
|
|
|
|
}
|
2021-10-25 16:50:31 +07:00
|
|
|
|
/*====================================================others=====================================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.btn-i {
|
2021-10-25 16:50:31 +07:00
|
|
|
|
@apply py-2 px-4 bg-indigo-500 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-400 focus:ring-opacity-75;
|
|
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.wgt-adt-stl {
|
2021-10-27 05:11:28 +07:00
|
|
|
|
@apply text-center text-gray-500 font-bold;
|
2021-10-25 20:05:21 +07:00
|
|
|
|
}
|
2021-12-11 13:54:28 +01:00
|
|
|
|
/*====================================================table=====================================================*/
|
2022-02-07 02:08:21 +01:00
|
|
|
|
.tbl {
|
|
|
|
|
|
@apply table-fixed w-full select-none my-2;
|
|
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.tbl-hd {
|
2022-11-22 15:07:41 +01:00
|
|
|
|
@apply text-center px-1 break-words text-gray-500 font-bold truncate;
|
2021-12-11 13:54:28 +01:00
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
.tbl-bdy-lg {
|
2022-11-22 15:07:41 +01:00
|
|
|
|
@apply text-center px-1 break-words truncate;
|
2021-12-11 13:54:28 +01:00
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
.tbl-bdy-sm {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@apply px-1 break-words;
|
2021-12-28 01:06:01 +01:00
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
/*====================================================inputs=====================================================*/
|
|
|
|
|
|
.ipt-lg {
|
|
|
|
|
|
@apply h-4 sm:h-7 md:h-7 lg:h-7 xl:h-7 2xl:h-7 content-center mt-2 bg-gray-50 focus:bg-white border-2 border-gray-100 text-gray-700 leading-tight focus:outline-none text-center focus:border-indigo-500;
|
|
|
|
|
|
}
|
|
|
|
|
|
.ipt-sm {
|
|
|
|
|
|
@apply h-3 sm:h-6 md:h-6 lg:h-6 xl:h-6 2xl:h-6 content-center bg-gray-50 focus:bg-white border-2 border-gray-100 text-gray-700 leading-tight focus:outline-none text-center focus:border-indigo-500 rounded-sm;
|
2021-12-27 22:46:16 +01:00
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
.ipt-rnd {
|
|
|
|
|
|
@apply content-center px-2 h-8 bg-gray-50 border-2 border-gray-200 rounded w-full text-gray-700 leading-tight focus:outline-none focus:bg-white;
|
|
|
|
|
|
}
|
|
|
|
|
|
.ipt-big {
|
|
|
|
|
|
@apply content-center px-2 h-8 bg-gray-50 border-2 border-gray-200 rounded w-full text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-indigo-500;
|
2021-12-29 01:21:28 +01:00
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
/*====================================================text=====================================================*/
|
|
|
|
|
|
.txt-ita {
|
2021-12-29 01:21:28 +01:00
|
|
|
|
@apply inline-block italic align-top text-right text-gray-500;
|
2021-12-12 00:20:47 +01:00
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
.txt-pad {
|
2021-12-28 22:09:44 +01:00
|
|
|
|
@apply px-2 py-0 sm:py-0 md:py-0 lg:py-1 xl:py-2 2xl:py-2;
|
|
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
|
.txt-sz {
|
2021-12-29 01:21:28 +01:00
|
|
|
|
@apply text-xxs sm:text-base md:text-base lg:text-base xl:text-base 2xl:text-base;
|
2021-12-28 22:09:44 +01:00
|
|
|
|
}
|
2021-12-12 00:20:47 +01:00
|
|
|
|
/*====================================================buttons=====================================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.btn-lg {
|
2022-11-22 15:07:41 +01:00
|
|
|
|
@apply flex justify-center break-words content-center bg-blue-100 hover:bg-blue-200 text-gray-500 font-bold text-sm sm:text-base md:text-base lg:text-base xl:text-base 2xl:text-base h-6 sm:h-8 md:h-8 lg:h-8 xl:h-8 2xl:h-8 w-full mt-0 border border-gray-300 rounded truncate;
|
2021-12-12 00:20:47 +01:00
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.btn-tbl {
|
2021-12-29 01:21:28 +01:00
|
|
|
|
@apply flex justify-center content-center text-gray-500 font-bold w-6 h-auto border border-gray-300;
|
2021-12-25 23:13:15 +01:00
|
|
|
|
}
|
2021-12-28 01:06:01 +01:00
|
|
|
|
/*====================================================select=====================================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.slct-lg {
|
2022-02-08 16:47:26 +01:00
|
|
|
|
@apply flex w-full justify-center break-words content-center bg-blue-100 hover:bg-blue-200 text-gray-500 font-bold text-sm sm:text-base md:text-base lg:text-base xl:text-base 2xl:text-base h-6 sm:h-8 md:h-8 lg:h-8 xl:h-8 2xl:h-8 mb-0 border border-gray-300 rounded;
|
2021-12-28 01:06:01 +01:00
|
|
|
|
}
|
2021-09-16 02:00:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#menu__toggle {
|
2022-02-01 16:01:19 +01:00
|
|
|
|
position: relative;
|
2021-09-16 02:00:52 +08:00
|
|
|
|
opacity: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
#menu__toggle:checked ~ .menu__btn > span {
|
|
|
|
|
|
transform: rotate(45deg);
|
|
|
|
|
|
}
|
|
|
|
|
|
#menu__toggle:checked ~ .menu__btn > span::before {
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
transform: rotate(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
#menu__toggle:checked ~ .menu__btn > span::after {
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
transform: rotate(90deg);
|
|
|
|
|
|
}
|
|
|
|
|
|
#menu__toggle:checked ~ .menu__box {
|
|
|
|
|
|
visibility: visible;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#menu__toggle:checked ~ .menu__main {
|
2021-10-10 23:46:18 +08:00
|
|
|
|
margin-left: 150px; /* насколько сужать правую часть */
|
2021-10-16 06:33:15 +08:00
|
|
|
|
transition-duration: 0.25s;
|
2021-09-16 02:00:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu__btn {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
position: fixed;
|
2022-09-08 23:35:58 +02:00
|
|
|
|
z-index: 2;
|
2021-09-16 02:00:52 +08:00
|
|
|
|
top: 10px;
|
|
|
|
|
|
left: 20px;
|
|
|
|
|
|
width: 20px;
|
|
|
|
|
|
height: 20px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu__btn > span,
|
|
|
|
|
|
.menu__btn > span::before,
|
|
|
|
|
|
.menu__btn > span::after {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 2px;
|
|
|
|
|
|
background-color: #616161;
|
|
|
|
|
|
transition-duration: 0.25s;
|
|
|
|
|
|
}
|
|
|
|
|
|
.menu__btn > span::before {
|
|
|
|
|
|
content: "";
|
|
|
|
|
|
top: -8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.menu__btn > span::after {
|
|
|
|
|
|
content: "";
|
|
|
|
|
|
top: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu__box {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
visibility: hidden;
|
2022-09-08 23:35:58 +02:00
|
|
|
|
z-index: 1;
|
2021-09-16 02:00:52 +08:00
|
|
|
|
top: 0;
|
|
|
|
|
|
left: -100%;
|
|
|
|
|
|
width: 150px; /* размер выхода бокового меню */
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 80px 0;
|
|
|
|
|
|
list-style: none;
|
|
|
|
|
|
background-color: #eceff1;
|
|
|
|
|
|
box-shadow: 1px 0px 6px rgba(0, 0, 0, 0.2);
|
|
|
|
|
|
transition-duration: 0.25s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu__item {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
padding: 12px 24px;
|
|
|
|
|
|
color: rgba(51, 51, 51, 0.788);
|
|
|
|
|
|
font-family: "Roboto", sans-serif;
|
|
|
|
|
|
font-size: 15px; /* размер шрифта бокового меню */
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
|
transition-duration: 0.25s;
|
|
|
|
|
|
}
|
|
|
|
|
|
.menu__item:hover {
|
|
|
|
|
|
background-color: #cfd8dc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.upper__bar {
|
|
|
|
|
|
background-color: rgba(51, 51, 51, 0.144);
|
|
|
|
|
|
height: 70px;
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
z-index: -1;
|
|
|
|
|
|
top: 0px;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
box-shadow: 1px 0px 3px rgba(0, 0, 0, 0.2);
|
|
|
|
|
|
}
|
2021-09-16 03:36:40 +08:00
|
|
|
|
|
|
|
|
|
|
input[type="date"]::-webkit-calendar-picker-indicator {
|
2021-09-17 03:35:49 +08:00
|
|
|
|
margin-left: 5px;
|
|
|
|
|
|
margin-right: -8px;
|
2021-09-16 03:36:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
input[type="time"]::-webkit-calendar-picker-indicator {
|
2021-09-17 03:35:49 +08:00
|
|
|
|
margin-left: 5px;
|
|
|
|
|
|
margin-right: -8px;
|
2021-09-16 03:36:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
input[type="number"]::-webkit-outer-spin-button,
|
|
|
|
|
|
input[type="number"]::-webkit-inner-spin-button {
|
2021-09-17 03:35:49 +08:00
|
|
|
|
margin-left: 7px;
|
|
|
|
|
|
margin-right: -6px;
|
2021-09-16 03:36:40 +08:00
|
|
|
|
width: 30px;
|
|
|
|
|
|
height: 30px;
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
}
|
2021-10-19 05:54:52 +08:00
|
|
|
|
|
2021-10-19 21:59:48 +08:00
|
|
|
|
/* Toggle */
|
2021-10-19 05:54:52 +08:00
|
|
|
|
input:checked ~ .dot {
|
|
|
|
|
|
transform: translateX(100%);
|
2021-10-25 16:50:31 +07:00
|
|
|
|
/* background-color: #48bb78;*/
|
2021-10-19 05:54:52 +08:00
|
|
|
|
}
|
2022-09-29 00:56:22 +02:00
|
|
|
|
|
|
|
|
|
|
input[type="file"] {
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
2021-09-16 02:00:52 +08:00
|
|
|
|
</style>
|