webSocket.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <html>
  2. <head>
  3. <script>
  4. var connection = new WebSocket('ws://10.11.2.1:81/', ['arduino']);
  5. connection.onopen = function () {
  6. connection.send('Message from Browser to ESP8266 yay its Working!! ' + new Date());
  7. connection.send('ping');
  8. /* setInterval(function() {
  9. connection.send('Time: ' + new Date());
  10. }, 20);
  11. */
  12. connection.send('Time: ' + new Date());
  13. };
  14. connection.onerror = function (error) {
  15. console.log('WebSocket Error ', error);
  16. };
  17. connection.onmessage = function (e) {
  18. console.log('Server: ', e.data);
  19. connection.send('Time: ' + new Date());
  20. };
  21. function sendRGB() {
  22. var r = parseInt(document.getElementById('r').value).toString(16);
  23. var g = parseInt(document.getElementById('g').value).toString(16);
  24. var b = parseInt(document.getElementById('b').value).toString(16);
  25. if(r.length < 2) { r = '0' + r; }
  26. if(g.length < 2) { g = '0' + g; }
  27. if(b.length < 2) { b = '0' + b; }
  28. var rgb = '#'+r+g+b;
  29. console.log('RGB: ' + rgb);
  30. connection.send(rgb);
  31. }
  32. </script>
  33. </head>
  34. <body>
  35. LED Control:<br/>
  36. <br/>
  37. R: <input id="r" type="range" min="0" max="255" step="1" onchange="sendRGB();" /><br/>
  38. G: <input id="g" type="range" min="0" max="255" step="1" onchange="sendRGB();" /><br/>
  39. B: <input id="b" type="range" min="0" max="255" step="1" onchange="sendRGB();" /><br/>
  40. </body>
  41. </html>