add LED control example

command out all echos
This commit is contained in:
Markus Sattler
2015-11-26 15:19:07 +01:00
parent d5b0364f5c
commit 3aa0deac74
4 changed files with 159 additions and 17 deletions

View File

@ -2,11 +2,16 @@
<head>
<script>
var connection = new WebSocket('ws://10.11.2.2:81/test', ['arduino']);
var 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.onerror = function (error) {
@ -17,14 +22,26 @@ connection.onmessage = function (e) {
console.log('Server: ', e.data);
};
setInterval(function() {
connection.send('Time: ' + new Date());
}, 1000);
function sendRGB() {
var r = parseInt(document.getElementById('r').value).toString(16);
var g = parseInt(document.getElementById('g').value).toString(16);
var 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; }
var rgb = '#'+r+g+b;
console.log('RGB: ' + rgb);
connection.send(rgb);
}
</script>
</head>
<body>
Test Websocket.
LED Control:<br/>
<br/>
R: <input id="r" type="range" min="0" max="255" step="1" onchange="sendRGB();" /><br/>
G: <input id="g" type="range" min="0" max="255" step="1" onchange="sendRGB();" /><br/>
B: <input id="b" type="range" min="0" max="255" step="1" onchange="sendRGB();" /><br/>
</body>
</html>