|
|
|
@ -12,9 +12,10 @@
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="/sym/dark.css"/>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
const wsurl = 'ws://127.0.0.1:8081'
|
|
|
|
|
const wsurl = 'ws://10.8.0.2:8081'
|
|
|
|
|
const socket = new WebSocket(wsurl)
|
|
|
|
|
let devices;
|
|
|
|
|
let devices = [];
|
|
|
|
|
function element(id){ return document.getElementById(id)}
|
|
|
|
|
|
|
|
|
|
socket.onopen = () => {
|
|
|
|
|
socket.send('new session')
|
|
|
|
@ -30,16 +31,17 @@
|
|
|
|
|
else if (msg[0] === 'device') {
|
|
|
|
|
if (!devices.includes(msg[1])){
|
|
|
|
|
devices.push(msg[1])
|
|
|
|
|
e.data
|
|
|
|
|
let new_device = element('template_led').innerHTML.replace(`{{id}}`, msg[1])
|
|
|
|
|
element('devices').innerHTML += element('template_led').innerHTML.replaceAll(`{{id}}`, msg[1])
|
|
|
|
|
}
|
|
|
|
|
if (msg[2] === 'online') document.getElementById(msg[1]).style.display = "block"
|
|
|
|
|
else if (msg[2] === 'offline') document.getElementById(msg[1]).style.display = "none"
|
|
|
|
|
else document.getElementById('led1_title').innerText = `LED 1 (currently ${msg[1]}):`
|
|
|
|
|
if (msg[2] === 'online') element(msg[1]).style.backgroundColor = "#546E7A"
|
|
|
|
|
else if (msg[2] === 'offline') element(msg[1]).style.backgroundColor = "#BA3D3D"
|
|
|
|
|
else element(`${msg[1]}_title`).innerText = `${msg[1]} (currently ${msg[2]}):`
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function show_error(msg) {
|
|
|
|
|
let error_style = document.getElementById('error-box').style
|
|
|
|
|
document.getElementById('error-message').innerText = msg
|
|
|
|
|
let error_style = element('error-box').style
|
|
|
|
|
element('error-message').innerText = msg
|
|
|
|
|
error_style.display = "block"
|
|
|
|
|
error_style.animation = "slide-from-left alternate 0.2s"
|
|
|
|
|
setTimeout(to => {error_style.animation = ""}, 200)
|
|
|
|
@ -48,20 +50,22 @@
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="title">ESP-IoT</div>
|
|
|
|
|
<div class="devices">
|
|
|
|
|
<div id="led1" class="device_box">
|
|
|
|
|
<div class="title2" id="led1_title">LED 1:</div>
|
|
|
|
|
<div id="devices" class="devices">
|
|
|
|
|
<template id="template_led">
|
|
|
|
|
<div id="{{id}}" class="device_box">
|
|
|
|
|
<div class="title2">{{id}}</div>
|
|
|
|
|
<button class="btn-green"
|
|
|
|
|
style="width: 10rem; position:relative; margin-top: 1rem; margin-left: calc(50% - 5rem);"
|
|
|
|
|
onclick="socket.send('device;led1;on')">
|
|
|
|
|
onclick="socket.send('device;{{id}};on')">
|
|
|
|
|
<div class="btn-text">on</div>
|
|
|
|
|
</button>
|
|
|
|
|
<button class="btn-red"
|
|
|
|
|
style="width: 10rem; position:relative; margin-top: 1rem; margin-left: calc(50% - 5rem);"
|
|
|
|
|
onclick="socket.send('device;led1;off')">
|
|
|
|
|
onclick="socket.send('device;{{id}};off')">
|
|
|
|
|
<div class="btn-text">off</div>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="error-box" class="error">
|
|
|
|
|
<div onclick="this.parentNode.style.display = 'none'" style="position: absolute; top:5px; right: 5px;" class="sym_btn-invisible">
|
|
|
|
|