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