Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by Travis

  1. Hello, looks like there's a minor error in the example code given for the index.html page for the "Node.js and Raspberry Pi - Webserver with WebSocket" page (which I'm very grateful was provided, btw). Half way through the article, there's an index.html example that has an extra html opening tag, and extra close body and html tags. It's not an issue for people who realize the issue, but figured the page could use a quick update if possible. Thank you for all the great content! Ref: https://www.w3schools.com/nodejs/nodejs_raspberrypi_webserver_websocket.asp <!DOCTYPE html> <html> <body> <h1>Control LED light</h1> <p><input type="checkbox" id="light"></p> <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script> <!-- include socket.io client side script --> <script> var socket = io(); //load socket.io-client and connect to the host that serves the page window.addEventListener("load", function(){ //when page loads var lightbox = document.getElementById("light"); lightbox.addEventListener("change", function() { //add event listener for when checkbox changes socket.emit("light", Number(this.checked)); //send button status to server (as 1 or 0) }); }); socket.on('light', function (data) { //get button status from client document.getElementById("light").checked = data; //change checkbox according to push button on Raspberry Pi socket.emit("light", data); //send push button status to back to server }); </script> </html> </body> </html>
  • Create New...