Web server to control GPIO on a Raspberry Pi with websockets (see description for important notes)

preview_player
Показать описание
Control your Raspberry Pi's GPIO pins on any modern web browser using websockets and Node JS

Code at:

1) Use the 32bit Raspberry Pi OS Desktop WITHOUT recommend software. The full desktop version of OS now includes a version of node preinstalled that will not work with this project. When I originally made this video, the full desktop version did not include node preinstalled.
2) Use a newer version of node. See below to see what versions of node worked for me. As of August 2022, Node JS v16.16.0 with npm v8.11.0 works fine for me. For the most part, the newest version of node work although occasionally you may need to revert to an earlier package if bugs are introduced.

I did everything from an ssh connection from my Linux laptop to the Pi so I could film this video. But for those of you that use Windows, you will probably want to attach a keyboard, mouse, and display to your Pi and just do everything local on the Pi instead. Windows doesn't support the X-Windows System so you will probably find that geany does not work via an ssh connection.

One thing I have notice lately however is that another version of Node.JS is already installed on the full desktop version of Raspberry Pi OS with recommended software. I now recommend using the Desktop version without recommended software. As far as I can tell, installing another version of Node JS on top of it doesn't cause any issues other than you may have to reboot the Pi before the new version of node is active. So after you install node, check the version. If it reports a different version of node or npm than what you installed, reboot the pi before running the npm init command or installing the npm packages.

Others have reported that this project will not work on a Raspberry Pi 2. I myself own a Raspberry Pi model 3B, Model 3B+, Model 4B, Model 400, and Zero2W and have found this demo project works on all of them.

While I have gotten this project to work on a Raspberry Pi Zero W (arm 6l) using Node v11, this version of node hasn't been supported for years -- so with the latest versions of Raspberry Pi OS, node no longer works. You could revert to the same versions of raspberry Pi OS that I specified in the video (Pi OS 2020-12-02-raspios-buster-armhf-full) and then it will work. But it will not have any security updates so use at your own risk.

As of August 2022, Node JS v16.16.0 with npm v8.11.0 works fine for me.

As of August 7, 2021, the latest version Node (v14.17.4) and npm (v6.14.14) works on the Raspberry Pi 4. So you no longer need to use Node v12.x. However, if you are using a Raspberry Pi Zero W, you will have to use an even older version of Node and install a few more packages. See updated documentation on my github for special instructions if you are using a Zero W.

Update December 26, 2021. I've tested Node JS v16.13.1 with npm v8.1.2 and confirm that both the Raspberry Pi model 3B-Plus and model 4B works with this version of node. Works either with Raspberry Pi Buster or Bullseye OS's. You may consider using this newer version of Node as v12.x is getting quite old now.

Рекомендации по теме
Комментарии
Автор

absolutely superb. Exactly what i was looking for, well explained and documented. Thanks so much, this will enable me to build my camper van control panel!

ThePhildrage
Автор

this is thousands than the course i found it in the other utube channel. Thanks a lot!!

jnine
Автор

I've been forcefully bashing my head against inanimate hard objects for three months now trying to figure out what you so thoroughly explained here. Thank you so much!

Christophereneumann
Автор

got to 25minutes and my Pi 3 with single Relay was working Beautifully. Thank you.

cwdaniels
Автор

Thank you, well explained. Most tutorials skip essential steps. For example, running the node web server. I once again appreciate your efforts.

pranavguruprasad
Автор

Never been more excited for an hour long video in my life

ArielFawkwes
Автор

the end result at the beginning definitely made it better, thanks

andykwan-dm
Автор

I have Apache2 (as part of LAMP) installed on my pi, so port 80 was taken, creating error messages. Changed the port in webserver.js to 8080 and then everything worked fine. Of course, instead of actually watching the video all the way through, I went on the interwebs and searched, read and figured out how to change the port that way. It only took a few hours, instead of the 20 minutes it would have by finishing this video :D

Great informative video and fun stuff to play around with. Thanks!

AlfOfAllTrades
Автор

Nice video. I hope to see more soon. Well explained and easy to follow! Cheers

teodor
Автор

I just saw the multiple switches and multiple web tabs in 2:00 and i just said: WOOW!

technopy
Автор

Silver banded resistors. Family heirloom? :) Great content. Exactly what people need to 'hello world' this type of project. So many possibilities come into view.

jsmythib
Автор

Thank you so much 4 this! MAGNIFICENT!!!MUCH NEEDED!! EXCELLENT 👌🏻👍🏽👌🏻

azelbane
Автор

This is fantastic, works brilliantly so far with my 2x8 relay boards connected to the Pi's GPIOs. I'm trying to expand this into a larger home hobby board gaming project, but it seems the webserver doesn't have good support for CGI. Would love to pick your brain... as I haven't done any webdesign or javascripting since 1999.

icedmuons
Автор

Hi Steve. You are my solution! ;-) you described exactly what I needed. Top notch. :-)

zachsandvik
Автор

Thank you! Great explanation! I’m going to make similar project and its very useful. Instead off control only by buttons or slides, I want to activate relays connects on Raspberry sending orders from another Raspberry or Arduino client.

miguelcirc
Автор

That was great, thank you for doing it.

kevinpankhurst
Автор

December 2023 - Thanks for this video and the example files..

I tried all of this yesterday on a Raspberry Pi Model 3B and it all worked. I tried installing the latest version on NODE.JS but I could not get NODE.JS or NPM to correctly install then return their version numbers. I don't know if this is the problem you were encountering.

I was able to make it work with NODE.JS version: " " so I'm happy with that.

I'm planning on using a high (above port 1024) port number so I may not need the capability that " libcap2-bin " provides.

I then played with / tweaked the stylesheet a bit and again the framework you provided was very helpful.

Now to expand on all of this since I want digital inputs in addition to the digital outputs, so I'm going to try working on adding that next.

Thanks again.

MonteStudios
Автор

Thanks for the video sir. Because this i can solve my orangepi project

siribvcm
Автор

Ok I found it, In plane sight. Silly me.
Thanks for the help.

jayweaver
Автор

very helpful tutorial. i just need to combine two gpio pins. can u tell me what to edit in the code to do that?

nearlyphantom