mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2026-07-10 10:31:00 +02:00
52 lines
1.5 KiB
HTML
52 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<link rel="icon" href="data:,">
|
|
<title>WebSocket LED Control</title>
|
|
<script>
|
|
let connection = new WebSocket('ws://10.11.2.1:81/', ['arduino']);
|
|
|
|
connection.onopen = function () {
|
|
connection.send('Message from Browser to ESP8266 yay its Working!! ' + new Date());
|
|
connection.send('ping');
|
|
|
|
/* setInterval(function() {
|
|
connection.send('Time: ' + new Date());
|
|
}, 20);
|
|
*/
|
|
connection.send('Time: ' + new Date());
|
|
};
|
|
|
|
connection.onerror = function (error) {
|
|
console.log('WebSocket Error ', error);
|
|
};
|
|
|
|
connection.onmessage = function (e) {
|
|
console.log('Server: ', e.data);
|
|
connection.send('Time: ' + new Date());
|
|
};
|
|
|
|
function sendRGB() {
|
|
let r = parseInt(document.getElementById('r').value).toString(16);
|
|
let g = parseInt(document.getElementById('g').value).toString(16);
|
|
let b = parseInt(document.getElementById('b').value).toString(16);
|
|
if (r.length < 2) { r = '0' + r; }
|
|
if (g.length < 2) { g = '0' + g; }
|
|
if (b.length < 2) { b = '0' + b; }
|
|
let rgb = '#'+r+g+b;
|
|
console.log('RGB: ' + rgb);
|
|
connection.send(rgb);
|
|
}
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
<p>LED Control:</p><br/>
|
|
|
|
<p>R: <input id="r" type="range" min="0" max="255" step="1" onchange="sendRGB();"></p>
|
|
<p>G: <input id="g" type="range" min="0" max="255" step="1" onchange="sendRGB();"></p>
|
|
<p>B: <input id="b" type="range" min="0" max="255" step="1" onchange="sendRGB();"></p>
|
|
</body>
|
|
</html>
|