Control your Raspberry Pi's GPIO pins on any modern web browser using websockets and Node JS
Code at:
github.com/Ste...
IMPORTANT NOTES: Do not install node.js via the "apt" package manager. This project will not work if you don't install node manually by downloading from node.js.org instead. Following the instructions exactly except for:
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.
For those of you who prefer to program in Python or another language, you may want to check out my follow up video • Web server with WebSoc... that discusses how to interface Node JS to Python and other languages/devices.
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 November 27, 2021. The demo project still works with the new bullseye version of Raspberry Pi OS dated Oct 30, 2021. I recommend using the desktop version without recommend software as the full version has a different version of node JS preinstalled. . I have tested node.js v16.13.0 and found it does NOT work. Recommend you now use node v14.17.4 as I know it works. Be sure to reboot the pi after installing node but before running "npm init". For now, stick with 32 bit OS -- This project will probably not work with the 64 bit versions of Raspberry Pi OS.
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.
Update August 15, 2022. I've test Node JS v16.16.0 with npm v8.11.0 and confirmed that the Raspberry Pi Model 4B works with this version of node. I used Raspberry Pi OS 32-bit Desktop (WITHOUT recommend software) "2022-04-04-raspios-bullseye-armhf.img.xz".
Негізгі бет Web server to control GPIO on a Raspberry Pi with websockets (see description for important notes)
No video
Пікірлер: 186