Make a web server with Websockets for Raspberry Pi. via instructables
in this instructable, I’ll show you how to create a lightweight and incredibly responsive web server with WebSockets.
I’ll use it to control a LED using an Arduino but the concept can be applied to many other projects.
Since this project does not use any on-board peripherals, it will work with just about any computer, but running it on a low power machine like the Raspberry PI makes sense for continuous operation.
Why use Node.Js or WebSockets?
There are a few tutorials on the web that show how to use a Raspberry Pi for home automation, but many use php and simple http requests to send data back to the server. This is fine for simply switching on and off some lights but quickly reaches it’s limitations when you want to run code server-side or if you want bidirectional communication.
Websockets have a few advantages over simple http requests:
Speed: A normal http request has to establish a connection before any transactions can happen which takes a lot of time. A websocket is always open and ready to send or receive data.
This means that the lag can be as low as your ping, so just a millisecond or two in most cases
Bidirectional: Websockets allow data to be sent in both directions, this also means that the server can trigger events in the client.
Each Friday is PiDay here at Adafruit! Be sure to check out our posts, tutorials and new Raspberry Pi related products. Adafruit has the largest and best selection of Raspberry Pi accessories and all the code & tutorials to get you up and running in no time!
Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.
Join us every Wednesday night at 8pm ET for Ask an Engineer!
Learn resistor values with Mho’s Resistance or get the best electronics calculator for engineers “Circuit Playground” – Adafruit’s Apps!
Maker Business — TechShop is closed, files bankruptcy
Wearables — Don’t shy away from intricacy
Electronics — Are you grounded?
Biohacking — Learning to See with Sound
No comments yet.
Sorry, the comment form is closed at this time.