You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
3.0 KiB
HTML
76 lines
3.0 KiB
HTML
4 years ago
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
4 years ago
|
<meta charset="UTF-8">
|
||
4 years ago
|
<title>esp-iot</title>
|
||
|
<!-- PWA support -->
|
||
|
<link rel="manifest" href="/manifest.json"/>
|
||
|
<meta name="theme-color" content="#2F3BA2"/>
|
||
|
<meta name="description" content="short your url"/>
|
||
|
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0'/>
|
||
|
|
||
|
<link rel="stylesheet" type="text/css" href="/sym/dark.css"/>
|
||
|
|
||
|
<script>
|
||
4 years ago
|
const wsurl = 'ws://127.0.0.1:8081'
|
||
4 years ago
|
const socket = new WebSocket(wsurl)
|
||
|
|
||
|
socket.onopen = () => {
|
||
|
socket.send('new session')
|
||
|
}
|
||
|
socket.onerror = (error) => {
|
||
|
console.log(`WebSocket error: ${error}`)
|
||
|
}
|
||
|
socket.onclose = error => show_error('session timed out (refresh)')
|
||
|
socket.onmessage = (e) => {
|
||
|
console.log(e.data)
|
||
4 years ago
|
let msg = e.data.split(";", 3)
|
||
4 years ago
|
if (msg[0] === 'error') show_error(msg[1])
|
||
4 years ago
|
else if (msg[0] === 'device') {
|
||
|
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]}):`
|
||
4 years ago
|
}
|
||
|
}
|
||
|
function copy_url() {
|
||
|
document.getElementById('surl-input').select()
|
||
|
document.execCommand("copy")
|
||
|
}
|
||
|
function lurl_submit() {
|
||
|
socket.send('long_url;'+document.getElementById('longurl-input').value)
|
||
|
}
|
||
|
function show_error(msg) {
|
||
|
let error_style = document.getElementById('error-box').style
|
||
|
document.getElementById('error-message').innerText = msg
|
||
|
error_style.display = "block"
|
||
|
error_style.animation = "slide-from-left alternate 0.2s"
|
||
|
setTimeout(to => {error_style.animation = ""}, 200)
|
||
|
}
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="title">ESP-IoT</div>
|
||
4 years ago
|
<div class="devices">
|
||
|
<div id="led1" class="device_box">
|
||
|
<div class="title2" id="led1_title">LED 1:</div>
|
||
|
<button class="btn-green"
|
||
|
style="width: 10rem; position:relative; margin-top: 1rem; margin-left: calc(50% - 5rem);"
|
||
|
onclick="socket.send('led1;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('led1;off')">
|
||
|
<div class="btn-text">off</div>
|
||
|
</button>
|
||
|
</div>
|
||
4 years ago
|
</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">
|
||
4 years ago
|
<img class="icon" src="sym/ic_close_white_24px.svg">
|
||
4 years ago
|
</div>
|
||
|
<div id="error-message" class="btn-text">
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|