mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 23:12:34 +03:00
123
This commit is contained in:
@@ -134,9 +134,16 @@
|
|||||||
|
|
||||||
deviceList = [
|
deviceList = [
|
||||||
{
|
{
|
||||||
|
name: "Устройство 1",
|
||||||
|
id: "987654321",
|
||||||
|
ip: "192.168.88.230",
|
||||||
|
status: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Устройство 2",
|
||||||
id: "987654321",
|
id: "987654321",
|
||||||
ip: "192.168.88.231",
|
ip: "192.168.88.231",
|
||||||
name: "test ESP 2",
|
status: false,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -150,6 +157,7 @@
|
|||||||
if (debug) console.log(device.name, ws, device.ip, device.id);
|
if (debug) console.log(device.name, ws, device.ip, device.id);
|
||||||
wsConnect(ws, device.ip);
|
wsConnect(ws, device.ip);
|
||||||
wsEventAdd(ws);
|
wsEventAdd(ws);
|
||||||
|
device.ws = ws;
|
||||||
//if (device.ip === myip) {
|
//if (device.ip === myip) {
|
||||||
// if (debug) console.log("My device found in list:", device.name);
|
// if (debug) console.log("My device found in list:", device.name);
|
||||||
//}
|
//}
|
||||||
@@ -157,6 +165,15 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function markDeviceStatus(ws, status) {
|
||||||
|
deviceList.forEach((device) => {
|
||||||
|
if (device.ws === ws) {
|
||||||
|
device.status = status;
|
||||||
|
if (debug) console.log(device.name, ws, device.ip, device.id, device.status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function wsConnect(ws, ip) {
|
function wsConnect(ws, ip) {
|
||||||
socket[ws] = new WebSocket("ws://" + ip + "/ws");
|
socket[ws] = new WebSocket("ws://" + ip + "/ws");
|
||||||
}
|
}
|
||||||
@@ -166,6 +183,7 @@
|
|||||||
socket[ws].addEventListener("open", function (event) {
|
socket[ws].addEventListener("open", function (event) {
|
||||||
if (debug) console.log("WS CONNECTED! " + myip);
|
if (debug) console.log("WS CONNECTED! " + myip);
|
||||||
socketConnected = true;
|
socketConnected = true;
|
||||||
|
markDeviceStatus(ws, true);
|
||||||
//socket[ws].send("HELLO");
|
//socket[ws].send("HELLO");
|
||||||
});
|
});
|
||||||
socket[ws].addEventListener("message", function (event) {
|
socket[ws].addEventListener("message", function (event) {
|
||||||
@@ -178,11 +196,13 @@
|
|||||||
});
|
});
|
||||||
socket[ws].addEventListener("close", (event) => {
|
socket[ws].addEventListener("close", (event) => {
|
||||||
socketConnected = false;
|
socketConnected = false;
|
||||||
|
markDeviceStatus(ws, false);
|
||||||
wsConnect(ws);
|
wsConnect(ws);
|
||||||
console.log("ws close " + myip);
|
console.log("ws close " + myip);
|
||||||
});
|
});
|
||||||
socket[ws].addEventListener("error", function (event) {
|
socket[ws].addEventListener("error", function (event) {
|
||||||
socketConnected = false;
|
socketConnected = false;
|
||||||
|
markDeviceStatus(ws, false);
|
||||||
wsConnect(ws);
|
wsConnect(ws);
|
||||||
console.log(myip + " ws error: ", event);
|
console.log(myip + " ws error: ", event);
|
||||||
});
|
});
|
||||||
@@ -275,8 +295,19 @@
|
|||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div class="fixed m-0 h-10 w-full bg-gray-100 shadow-md">
|
<div class="fixed m-0 h-10 w-full bg-gray-100 shadow-md">
|
||||||
<div class="flex justify-end content-center px-6 py-1">
|
<div class="flex justify-end content-center">
|
||||||
<svg class="h-8 w-8 {socketConnected == true ? 'text-green-500' : 'text-red-500'}" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" /> <path d="M7 18a4.6 4.4 0 0 1 0 -9h0a5 4.5 0 0 1 11 2h1a3.5 3.5 0 0 1 0 7h-12" /></svg>
|
<div class="px-15 py-2">
|
||||||
|
<select>
|
||||||
|
{#each deviceList as device}
|
||||||
|
<option value={device}>
|
||||||
|
{device.name}
|
||||||
|
</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="px-10 py-1">
|
||||||
|
<svg class="h-8 w-8 {socketConnected == true ? 'text-green-500' : 'text-red-500'}" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" /> <path d="M7 18a4.6 4.4 0 0 1 0 -9h0a5 4.5 0 0 1 11 2h1a3.5 3.5 0 0 1 0 7h-12" /></svg>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -301,6 +332,9 @@
|
|||||||
<li>
|
<li>
|
||||||
<a class="menu__item" href="/log">{"Лог"}</a>
|
<a class="menu__item" href="/log">{"Лог"}</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a class="menu__item" href="/list">{"Устройства"}</a>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a class="menu__item" href="/about">{"О проекте"}</a>
|
<a class="menu__item" href="/about">{"О проекте"}</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -354,6 +388,16 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</Card>
|
</Card>
|
||||||
</Route>
|
</Route>
|
||||||
|
<Route path="/list">
|
||||||
|
<Card title={"Список устройств"}>
|
||||||
|
{#each deviceList as device}
|
||||||
|
<div>
|
||||||
|
<input class="focus:border-indigo-500" bind:value={device.name} />
|
||||||
|
<input class="focus:border-indigo-500" bind:value={device.ip} />
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</Card>
|
||||||
|
</Route>
|
||||||
<Route path="/about" />
|
<Route path="/about" />
|
||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user