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

  Рет қаралды 51,009

StevesProjects

StevesProjects

Күн бұрын

Пікірлер: 186
@jnine3807
@jnine3807 3 жыл бұрын
this is thousands than the course i found it in the other utube channel. Thanks a lot!!
@highfidelityinc
@highfidelityinc 3 жыл бұрын
You're very welcome!
@Christophereneumann
@Christophereneumann 3 жыл бұрын
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!
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Yes it took me many months to figure out too. There are so many different web technologies out there, with many of them being obsolete, that it is very difficult to figure out what is relative and what is not. Glad to hear you found the video useful.
@Christophereneumann
@Christophereneumann 3 жыл бұрын
@@highfidelityinc I got so frustrated, I was just trying to connect one pi to another via bluetooth then wifi ad hoc then I stumbled across your video. There were WEEKS of falling down rabbit holes head first. Do you have a cashapp? I want to buy you a beer sir. And if you have time, I'd love to get your thoughts on something.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Thanks for the offer but really, you don't need to do anything. I am in a middle of a bunch of work related projects right now and don't have much free time right now.
@ArielFawkwes
@ArielFawkwes Жыл бұрын
Never been more excited for an hour long video in my life
@highfidelityinc
@highfidelityinc Жыл бұрын
Glad you found it interesting.
@cwdaniels4
@cwdaniels4 3 жыл бұрын
got to 25minutes and my Pi 3 with single Relay was working Beautifully. Thank you.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad it helped
@ThePhildrage
@ThePhildrage 3 жыл бұрын
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!
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad it helped
@technopy6659
@technopy6659 3 жыл бұрын
I just saw the multiple switches and multiple web tabs in 2:00 and i just said: WOOW!
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Good you hear you are impressed
@andykwan-d5m
@andykwan-d5m 3 жыл бұрын
the end result at the beginning definitely made it better, thanks
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Yes, it is something I wish more videos would do instead of waiting to the end to see the final result.
@nearlyphantom
@nearlyphantom 2 жыл бұрын
very helpful tutorial. i just need to combine two gpio pins. can u tell me what to edit in the code to do that?
@teodor9176
@teodor9176 3 жыл бұрын
Nice video. I hope to see more soon. Well explained and easy to follow! Cheers
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad to hear you liked it.
@MonteStudios
@MonteStudios Жыл бұрын
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: " node-v18.19.0-linux-armv7l.tar.gz " 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.
@highfidelityinc
@highfidelityinc Жыл бұрын
Glad it worked out for you. Yes, sometimes the latest version of Node has a bug and you have to revert to an earlier version. Usually happens when they first release a new major version.
@edyyrb
@edyyrb 2 жыл бұрын
cuando corroe node -v me manda "illegal instruction " y no puedo continuar
@AlfOfAllTrades
@AlfOfAllTrades 3 жыл бұрын
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!
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Yep, if people would just learn to follow the instructions, they will find that it works. It is always better to start with a clean install when trying to run the demo project. Good to hear you figured out the problem.
@AlfOfAllTrades
@AlfOfAllTrades 3 жыл бұрын
@@highfidelityinc I live by the old saying "When everything else fails, read the manual..." Some times it takes far more time, but occasionally you learn something you otherwise wouldn't have :) I think I will remember now, where to find the port setting...
@GoldenEye0006
@GoldenEye0006 3 жыл бұрын
Hi, have got some trouble with mine Raspberry Pi 1B. Does this program support the old Pi ? "Error: EBUSY: resource busy or locked, write" this error i get.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
I doubt if Node JS support the Raspberry Pi 1B as it is very old. Your only hope is to see what arm processor it uses as I describe in the video and then see if node JS has an older version that supports that arm processor. But even then, I doubt that socket IO even existed when that Pi was made. So you are probably SOL.
@GoldenEye0006
@GoldenEye0006 3 жыл бұрын
@@highfidelityinc it's the armv6l , normaly thats the same like Pi Zero, so i did follow the extra notes for the Pi zero.
@GoldenEye0006
@GoldenEye0006 3 жыл бұрын
I've did the exact same on Pi3+ and it's worked form the first time. So yeah the 1B is not a good solution.
@jsmythib
@jsmythib Жыл бұрын
Silver banded resistors. Family heirloom? :) Great content. Exactly what people need to 'hello world' this type of project. So many possibilities come into view.
@miguelcabral5757
@miguelcabral5757 Жыл бұрын
HI Steves, thank you, well explained. Great project i do that and works fine. But I need one think for you, I need to put that on startup because i dont have monitor to see what happen, do you have something our do you now something to do that? Thanks
@highfidelityinc
@highfidelityinc Жыл бұрын
Good to hear you found the video useful. In terms of your question, I personally prefer to use System-D to start programs automatically. I just downloaded a new updated document to my github that explains how to add a System-D process to start node JS automatically. See the last section of the document at github.com/StevesRandomProjects/PiGpioWebServer/blob/main/GPIO%20Webserver%20for%20Raspberry%20Pi%202023-07-15.pdf
@miguelcabral5757
@miguelcabral5757 Жыл бұрын
@@highfidelityinc works fine, thanks. I make same code upgrades, activated a bottom sequencing.
@jayweaver5574
@jayweaver5574 2 жыл бұрын
Hey? Where is the build/install instructions you mentioned? I don’t see them any where in the Git download?
@highfidelityinc
@highfidelityinc 2 жыл бұрын
It is right there at the top of the video description and I just confirmed it still works. Here is again: github.com/StevesRandomProjects/PiGpioWebServer
@amalamara7506
@amalamara7506 2 жыл бұрын
hi thanks for the video but i have a question how can i get the data from my raspberry pi and send them to my website using websockets?(ps my website is hosted on my pc and it's angular js)
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Sorry, I know very little about angular other than it is a framework developed by Google. And using websockets to communicate to another web server is way beyond the scope of this video. However, you may want to watch my follow up video where I have a demo program that uses a simple UDP connection to talk to another program.
@amalamara7506
@amalamara7506 2 жыл бұрын
@@highfidelityinc yes I'll watch it thank you❤
@rossridler4870
@rossridler4870 2 жыл бұрын
very nice video, it was very informative and well presented. I do have a question for you... is there a reason for the order in which you listed the GPIO ports (26, 20, 21, 16)? and also is there a way to get the buttons to slide back to the "off" position when the server disconnects or shuts down?
@highfidelityinc
@highfidelityinc 2 жыл бұрын
No particular reason why I chose GPIO ports 26, 20. 21, and 16 and in that order other than they are all on one end of the Pi's 40 pin header and were easy to locate and connect. Right off hand I don't know a way to have the buttons to slide back to off when the server disconnects. However, one possible way to do it is write a client side JavaScript procedure to ping the server every few seconds. If the server fails to respond after so many pings, use that same JavaScript procedure to turn all the switches off. Another way is to write a client javascript procedure to refresh the page every so many seconds -- the issue though is if the server is offline, your web browser with come back with a message that the page cannot be found rather than keeping the web page open.
@rossridler4870
@rossridler4870 2 жыл бұрын
I appreciate your response. I was truly wondering about your choice and sequence of the GPIO pins, I do see that the location of the pins make your choice a good one. The first switch does turn off but the other 3 switches don't and that may be because the exit command completes too quick. I have tried to use a script to have the exit command pause so the switches have the time to shut off with no success. Maybe you could figure out something, I would be grateful for the help.
@a.cetinyuce4122
@a.cetinyuce4122 9 ай бұрын
Hello, how can we make this file xx run automatically every time node webserver.js is opened?
@highfidelityinc
@highfidelityinc 9 ай бұрын
I am not sure exactly what you are asking. If if you are asking how to start the node webserver.js automatically, refer to the last section of the pdf documentation that is included in my github link at the top of the video description.
@a.cetinyuce4122
@a.cetinyuce4122 9 ай бұрын
@@highfidelityinc I'm sorry I didn't see it. Thanks
@michaelhinterndorfer4942
@michaelhinterndorfer4942 8 ай бұрын
Can i send other numbers then 1 or 0, bc i want to control a rgb stripe with a slider
@guytas
@guytas 8 ай бұрын
Hi, very nice projet. Can you tell me if that could be the way to go for me? I need a local web server (no internet access) that would constantly refresh a page that would show my total energy use of my house. I already wrote the python software that shows the energy on the pi itself but I wish to convert it to web server.
@highfidelityinc
@highfidelityinc 8 ай бұрын
I have a follow up video the explains one method of interfacing a Python program to a node JS web interface. kzbin.info/www/bejne/j6fWgIihibqmrsk This video is running two programs. The first is a python program that controls the GPIO and the second is a Node JS program to serve up the web pages. I cover how the interface between the two programs works. It also demo's other types of web interfaces such as gauges and text boxes although it is up to you to write the python code to control them.
@guytas
@guytas 8 ай бұрын
​@@highfidelityinc thanks.
@DanielleR-h5s
@DanielleR-h5s 5 ай бұрын
I tried to follow this tutorial and it has not be successful for me, I am not sure what is wrong but when trying to run the node webserver.js command i get a node:fs:2346 return binding.writeFileUtf8( ^ Error: EINVAL: invalid argument, write message and I have tried to fix the code with no success. Any suggestions?
@MrBartPawlowski
@MrBartPawlowski 10 ай бұрын
hey Steve, nice video! . One question, it this gone work on the PI itself in the browser? So if I connect the screen to the pi and run browser in kiosk mode it will give me gui ?
@highfidelityinc
@highfidelityinc 10 ай бұрын
You most certainly can connect a screen to the pi and run in kiosk mode while node is running in the background on the same pi. For the web address you type in your web browser, you would use the loopback address which would be either localhost or 127.0.0.1
@MrBartPawlowski
@MrBartPawlowski 10 ай бұрын
Thanks for replying, much appreciated!
@andredepaula8993
@andredepaula8993 3 жыл бұрын
Hi Steve. I got the error showed bellow when runing "node webserver.js" on RPi. Any tip of what could be happing?
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Hi Andre. I need a little more information to answer your question. In particular, what version of the RPI are you using (Module 4B, 3B, zero W, ?. Which version of Raspberry Pi OS are you using? Which version of Node JS and NPM?
@andredepaula8993
@andredepaula8993 3 жыл бұрын
Hi @@highfidelityinc Tks for your reply. I am using a "Raspberry Pi 4 Model B Rev 1.4" w/ 4GB, running "Raspbian GNU/Linux 11 (bullseye)", Node: v12.20.1 and NPM: '6.14.10'. Best regards, André
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Hi Andre, I was curious myself if the latest Bullseye version of Raspberry Pi OS still worked with the GPIO example project. So I just installed the 2021-10-30-raspios-bullseye-armhf-full OS on my Raspberry Pi 4 Model B Rev 1.1 4GB model and then followed the procedure in my documentation to install Node v12.20.1 (be sure to get the arm7l version if that is what the "uname -m" command reports), NPM v6.14.10, install the onoff and socket.io module, ran the setcap command, downloaded the demo code from my github and then ran the project. And GPIO demo ran the first time with no errors. So yes, the demo project still works with Bullseye. I should note however that the newer versions of Raspberry Pi OS full desktop versions already has another version node already installed. So after you install node and check the version with "node -v" and "npm -v", if it does not report the versions you just installed, it is very important to reboot the Pi before running the "npm init" command and ensure the version reported is correct before proceeding. Of course you should always start with a clean install and follow my instructions to the letter. Back when I made this video, the latest versions on node.js did not work. But that is no longer that case. Back in August 2021, I tested the demo project with Node v14.17.4 and npm v6.14.14 and they worked too. So it is no longer necessary to use node v12.20.1. I have not tested node v16 yet. I guess there could be something different with your revision of the Pi 4. That is unlikely, but, I would have to buy a new Pi 4 to confirm that. Also, all bets are off if you are trying to use the 64 bit version of Raspberry Pi OS. Good luck, Steve
@smangasimphiwe5852
@smangasimphiwe5852 Жыл бұрын
Thanks Steve 🤗 very insightful video! quick question, Any clue on how I can do the same using java springboot framework?
@highfidelityinc
@highfidelityinc Жыл бұрын
Sorry. I am not familiar with java springboot framework. Perhaps someone else who reads this can answer your question.
@FreClimbs
@FreClimbs 2 жыл бұрын
Hey Steve, thanks for the tutorial! I was wondering. Will this also work over 4G/5G or only when on the same Wifi network?
@highfidelityinc
@highfidelityinc 2 жыл бұрын
The 4G services that I have seen or used have all been behind some type of firewall or nat. 5G is probably the same. To access remotely, you will probably have to set up a remote server that has a public IP and then create a link between your 4/5G device and the remote server. One way to do that is to set up an OpenVPN server on your remote server and an OpenVPN client on the devices that is on your 4/5G network. Essentially you will be creating your own cloud service.
@FreClimbs
@FreClimbs 2 жыл бұрын
@@highfidelityinc i think "web rtc" could be a solution.
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Sorry for the late response -- been busy at work. I haven't used "web rtc" but just quick look at it appears it is some type of cloud service. So yes if you want to use it, go for it. For myself, I wouldn't consider it because it is just too easy to set up my own service. Every cloud service I have used has eventually failed -- be it a change in terms and condition, a change in the protocol, a data breach, going out of business, or etc.
@jesusitoavg7305
@jesusitoavg7305 2 жыл бұрын
You know, how can I implement a humedity sensor? And, can I add a database??
@highfidelityinc
@highfidelityinc 2 жыл бұрын
For a humidity sensor, I would use an off the shelf sensor that interfaces easily with the Pi. Search for humidity sensors on Mouser or DigiKey. I am using a Mouser 403-SHT40-AD1B-R2 temperature/humidity sensor on another project. It has an I2C interface that should work in the Pi's GPIO I2C pins. However this sensor is tiny. You will have to make a custom PCB and then mount the sensor using a hot plate, reflow oven, or hot air station. There is a I2C module in npm although I have not used it yet -- so I don't know if it works. Or you could use a Python I2C module and send that data to node (see my follow up video). For a database, something like MariaDB SQL database should work. But details on how to do both of these is way more involve that what I can describe in just a few lines. Good luck.
@icedmuons
@icedmuons 3 жыл бұрын
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.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Oh Boy, What you are asking (CGI) is something I don't know. And by no means am I a Node JS expert. But after a lot of persistence, I finally figured out how to do a basic web server that incorporated web sockets. I made the video because I figure others were were trying to do the same thing.
@artunzincir9235
@artunzincir9235 3 жыл бұрын
Thank you for great presentation, i want build more pins to control on pi i was tried but cant reach the solution.Would you shot the video another available time about this?:)
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Your welcome! I'll consider making future videos when time permits.
@alexandredambrun9598
@alexandredambrun9598 3 жыл бұрын
Nice tutorial ! Is it possible to send a video from a computer to the raspberry pi with this websocket/Node JS interface ? (with some code modifications)
@highfidelityinc
@highfidelityinc 3 жыл бұрын
I am sure it can be done but it would most certainly require you to write some type of custom program or use some off the shelf program for your computer (assuming your computer is not a raspberry pi). The most obvious way to stream video from your computer to a node JS server on your pi is to set up your computer to stream video when a browser to connects to it. Then use the html tag in your node JS webserver index.html file to link your computer video to the Pi's web page. That is what I did on the followup video kzbin.info/www/bejne/j6fWgIihibqmrsk . In that case I used motioneyeOS software on another Pi and then made a link to it in the index.html file on this followup video. You just need to replace that link with the link to your computer's web server.
@mrryan9407
@mrryan9407 3 жыл бұрын
For Some reason this isn't working after following you to point. Please advise.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Sorry, impossible to make suggestions for such a broad question. You need to leave a little more details. Like what version of Pi you are using, version of Raspberry Pi OS, version of node JS, and any error messages that occur during the install. Some versions of Raspberry pi OS are now coming with an older version of Node JS preinstall. So after you install node JS and you check the version, if it is not the same as you just installed, reboot the Pi to activate new version node JS before installing the npm packages.
@anthonyhattar2135
@anthonyhattar2135 2 жыл бұрын
currently only one pin is working (GPIO 26) I cannot get the others to work. Any advice?
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Hard to say. If you are using a HAT, it may be interfering with some of the GPIO pins or you may have another process that is using the same pin. Those types of things have bite me in the past.
@danielpalfi2000
@danielpalfi2000 3 жыл бұрын
Great video with all the files! Can you write down how can I add extra ports to the program? I have already copied the relevant part with the free port number in index.html; main.js; webserver.js but doesn't react.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Okay I was curious myself if you could run two node JS servers at the same time. And yes it does work. But instead of trying to combine both webservers into one webserver.js file, create a separate a second node JS server (e.g. webserver.js and webserver2.js) and start them both. Just make sure to use a different port for webserver2.js. I have webserver.js running on port 80 and webserver2.js running on port81. Both are running the same gpio example program except I changed the port number in webserver2.js to port 81. However, this gpio example program does not check if the state of the GPIO pin when changes from an external program (e.g. the other webserver). So when you change the state of the GPIO from webserver.js, it does not reflect that changed in webserver2.js. But both can and do change the state of the GPIO pin. You would have to add some add code if you want to keep the GPIO in sync in both programs -- I haven't tried that yet so you will have to figure this aspect on your own.
@prasenjitmaji3388
@prasenjitmaji3388 3 жыл бұрын
Thank you for explaining in detail :)
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad it was helpful!
@pranavguruprasad1834
@pranavguruprasad1834 3 жыл бұрын
Thank you, well explained. Most tutorials skip essential steps. For example, running the node web server. I once again appreciate your efforts.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad you found it helpful. Thanks for the feedback.
@smatinader3715
@smatinader3715 3 жыл бұрын
hello i am trying to use this to control some LEDs and iw ould like to know to i have to be logged on the same network wifi or i can control it from anywhere. 192.168.18.105 is it local or can i do this from a distant device not logged it to the same wifi ?
@highfidelityinc
@highfidelityinc 3 жыл бұрын
By default, the Pi can be access from any subnet unless you specifically set up the firewall rules in the Pi to do otherwise. So to answer your question, yes you can access the Pi from a distant device as long as there is a routeable path between the two. But one thing I would not do is open a port on your router and forward it directly to the Pi -- you will very quickly find hackers all over the world hacking into your Pi. The easiest safest way to access your Pi from a remote location is to buy a router with an OpenVPN server and access the Pi via an OpenVPN tunnel -- but that in itself is another whole topic.
@smatinader3715
@smatinader3715 3 жыл бұрын
@@highfidelityinc thank you for your reply
@bramrecourt7623
@bramrecourt7623 2 жыл бұрын
@stevesprojects, thanks great video! I have some problems running it on raspberry 2 b, or only working on a 4?
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Others have reported the earlier versions of the Pi do not work. So you will probably have to upgrade your Pi. I have tested the project on the Raspberry Pi models 4B, 3B+, 3B, and Zero W and it will work on those models. The first three use an arm7l processor which is still supported. The Zero W however uses an arm 6l processor which is not supported by newer versions of Node JS.
@jean-pierrecattoor8067
@jean-pierrecattoor8067 2 жыл бұрын
Hello, good tuto that works fine. I would like to start the server at the boot. I can't find how to do it. Can you help me? Thanks in advance
@highfidelityinc
@highfidelityinc 2 жыл бұрын
There are many ways that you can start a program automatically. Sparkfun.com has a great write up on the different ways to start a program automatically at learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup/all . My preferred method is via a SystemD process. If you are interested in using SystemD, you might look at the video I posted a few months ago on a Raspberry Pi OTA ATSC DVR. In that video I discuss how to start Kaffeine and MiniDNLA automatically using SystemD.
@robbals3173
@robbals3173 3 жыл бұрын
Hi Steve, first of all, great presentation!!! Thx for this working/useable project. Now, I now you're busy...but could you help (or point me in the right direction) to get a function in your code to start one of these leds at a certain time?
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Hi Rob, Thanks for the head up. Without doing some research, I don't have a good answer for your question. But you might want to subscribe to my channel. I am working on a follow up video on how to set up a communication link to another program such as Python. With that video, you can use your preferred programming language to implement your project yet retain node JS to handle just the web interface.
@zachsandvik1867
@zachsandvik1867 3 жыл бұрын
Hi Steve. You are my solution! ;-) you described exactly what I needed. Top notch. :-)
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad to help
@rithsinawatra9995
@rithsinawatra9995 5 ай бұрын
Can I connect with arduino?
@czerjaknorbert4610
@czerjaknorbert4610 Жыл бұрын
Hi! This video is wonderful ,it has a nice presentation and a very good documentation ,you did a very nice job explaining everything. I have a question , I'm trying to automate this site (to auto start the server , with the pi powers on ), I tried creating a service .... long story short it's not working() , I tried rc.local it's not working either, I'm stuck at this banal problem for like 3 days . How would you do this ? I'm still trying with services but i don't even know if it's possible ,I'm not very experienced with Linux , but I'm not new either.
@highfidelityinc
@highfidelityinc Жыл бұрын
Glad you found the video useful. In terms of your program not auto starting, my guess you are starting node before some service is available (such as the network adapter), you don't have your working directory pointed to the ~/webserver/gpio directory, or you are using a user other than pi when you start the node program. My prefer method of auto starting a program is SystemD. Sparkfun has excellent tutorial on auto starting a program. SystemD is one of the methods they discuss. learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup/all The main advantages of using SystemD are: 1) You can have system D automatically restart the program if it crashes. 2) You can specify to start the program only after certain processes, such at the network adapter, are available. 3) You can use systemD to check the status of the process and it will give you some error information if the process fails. Here is a .service file that I find works for me to auto start node. [Unit] Description=webserver service After=network.target [Service] ExecStart=node /home/pi/webserver/gpio/webserver.js WorkingDirectory=/home/pi/webserver/gpio StandardOutput=inherit StandardError=inherit Restart=always User=pi [Install] WantedBy=multi-user.target You might want to look at the "Installing Kaffeine software" section my video "Raspberry Pi OTA ATSC Tuner/DVR using Kaffeine and using minidlna to stream video to a Roku player". I used SystemD to start Kaffeine because I could delay starting the program until the hard drive was ready.
@llony89
@llony89 3 жыл бұрын
hola agoto todo el proceso tal como lo comenta pero me marca error cuando ejecuto node webserver.js que puedo hacer para solucionar la diferencia es que yo inatale node v 11.15.0 por el procesador que tengo que es el armv6 fs.js:119 throw err; ^ Error: EBUSY: resource busy or locked, write at Object.writeSync (fs.js:589:3) at Object.writeFileSync (fs.js:1220:26) at exportGpio (/home/pi/webserver/node_modules/onoff/onoff.js:18:8) at new Gpio (/home/pi/webserver/node_modules/onoff/onoff.js:172:36) at Object. (/home/pi/webserver/gpio/webserver.js:10:13) at Module._compile (internal/modules/cjs/loader.js:816:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10) at Module.load (internal/modules/cjs/loader.js:685:32) at Function.Module._load (internal/modules/cjs/loader.js:620:12) at Function.Module.runMain (internal/modules/cjs/loader.js:877:12) espero y puedas apoyar a identificar mi error o que me falto
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Sounds like you are trying to run this project on an Arm6 processor instead of a Arm7 and you are using an older version of node. If this is a Raspberry Pi Zero W, see updated documentations on my Github that has special instructions for the Pi Zero W. Also note that this project uses html5 technology (e.g websockets) -- older obsolete operating systems such as Windows XP do not support html5. Suggest you use the same hardware and software as I used and use a modern web browser. You have the best chance of success if you do exactly as what I did. After you get that working, you can experiment with other hardware and software.
@meghanarprakash7862
@meghanarprakash7862 Жыл бұрын
Does anybody know how to use node js in aarch64
@ashkanradnia1456
@ashkanradnia1456 3 жыл бұрын
Thanks for the video it is very comprehensive and useful! Do you know how this can be deployed to Heroku or glitch to control a raspberry pi via a remote server? I would appreciate it if you direct me to some sources to figure out the remote server part.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Sorry, I know nothing about Keroku or glitch.
@ThienTran-df2gs
@ThienTran-df2gs 3 жыл бұрын
create a nodejs server using socketio and deploy that to heroku then you can run a socketio client script in the raspberry receiving messages sent from the server and do whatever you want with raspberry
@miguelcirc
@miguelcirc 2 жыл бұрын
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.
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Glad it was helpful!
@kevinpankhurst1
@kevinpankhurst1 3 жыл бұрын
That was great, thank you for doing it.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Thanks for the feedback. Good to hear my efforts to make this video were not in vain.
@MAXI-cp7lk
@MAXI-cp7lk 3 жыл бұрын
Can this be used for controlling DC motors on a RPI 4 robot
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Sure, I see no reason why you couldn't use it for motor control. Of course you will probably need some type of motor driver to go between the GPIO pin and the motor.
@MAXI-cp7lk
@MAXI-cp7lk 3 жыл бұрын
@@highfidelityinc Thank you But, did I miss something? The GUI of your buttons. Was it done in Android Studio?
@MAXI-cp7lk
@MAXI-cp7lk 3 жыл бұрын
Oh my! I watch it all again and found the HTML code wonderful.
@marcoramos7386
@marcoramos7386 3 жыл бұрын
Greate video. It is possible to access it from another network?
@highfidelityinc
@highfidelityinc 3 жыл бұрын
By default, the Pi can be access from any subnet unless you specifically set up the firewall rules in the Pi to do otherwise. So to answer your question, yes you can access the Pi from a distant device as long as there is a routeable path between the two. But one thing I would not do is open a port on your router and forward it directly to the Pi -- you will very quickly find hackers all over the world hacking into your Pi. The easiest safest way to access your Pi from a remote location is to buy a router with an OpenVPN server and access the Pi via an OpenVPN tunnel -- but that in itself is another whole topic.
@lastnamewhite
@lastnamewhite 2 жыл бұрын
can't get it to work. started getting errors at 'setcap' instruction ... i've never got a websocket program to work so no big surprise here...thanks anyways... you did a great job on the project... i just cant get it to work on my setup
@highfidelityinc
@highfidelityinc 2 жыл бұрын
To confirm that this project still works, I just tested this demo project and found it still works with the latest software and hardware. I am using the following: 1) Raspberry Pi Model 4B 2) 32 bit Raspberry Pi OS version "2022-04-04-raspios-bullseye-armhf.img.xz" (Desktop WITHOUT recommended software). 3) Node JS v16.16.0 with npm v8.11.0 (do not updated to a newer version of npm when you run 'npm init'") I suggest you use the same hardware and software as above, start with a clean install and do not install anything else, and follow the instructions very carefully. Also be sure to look at the video description as I post updates on what works and what does not there. Good luck, Steve
@lastnamewhite
@lastnamewhite 2 жыл бұрын
@@highfidelityinc i've got a Raspberry Pi Model 3B+ maybe that's the difference. I've tried other tutorials but always run into a snag. w3schools has one very similar to yours... I get to the last page and it stops working... havent figured out why.
@highfidelityinc
@highfidelityinc 2 жыл бұрын
The Raspberry Pi Model 3B+ should be fine. Any Pi with an arm7l processor will probably work. I have both a Model 3B and 3B+ and never had issues with running node JS on them. Do NOT use the raspberry Pi OS desktop with recommended software -- Starting about a year ago, that version comes with another version of Node JS that will mess up your setup. All the setcap command does is allow node to use port 80 without running node as a root user. Be sure to use sudo with netcap command. You don't need to use the setcap command if you use any port over 1024 for the webserver port.
@lastnamewhite
@lastnamewhite 2 жыл бұрын
@@highfidelityinc thanks. I'm goin to be trying again. I followed the pdf but i guess i'm missing something. I really dont mind using 8000 or whatever port number for now, just like to get it working then figure out the details and changes
@highfidelityinc
@highfidelityinc 2 жыл бұрын
If I had to make a guess, I would say "setcap" command did not work for you because you did not install node in the proper directory. That could be because you tried to install Node via the "apt" package manager instead of downloading from Node JS from node.js.org. I made that mistake the first time I tried to use node. When you use "apt", it will put node in different directories. I could never get node to work from the "apt" package manager. Do not deviate from the instructions other then using a newer version of node and using the raspberry pi desktop without recommended software.
@fatchickencatcher
@fatchickencatcher 3 жыл бұрын
Really appreciated. Works and is a fantastic base for my home automation. Thanks Would you know how to add an MCP3008 ADC to this setup? I am at a loss. Every attempt, up to 30, fails.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
I never have tried using the MCP3008 but a quick google search for "mcp3008 node js raspberry pi" shows numerous hits. There is apparently a NPM package available for the MCP3008. This one looks promising: mikaelleven.wordpress.com/2015/12/13/getting-started-with-spi-analog-input-in-nodejs-using-raspberry-pi-and-mcp3008/ . Alternatively, if you prefer to program in your favorite programming language, you could do all the MCP3008 stuff in python, C, etc and then create a simple UDP, TCP, or SSH link link between the program. There is also methods of sharing data between different programs more directly although I haven't attempted that myself yet. But I have done a simple UDP link to another device (e.g. a Crestron home automation processor) and used the Pi for the html5 front end for the Crestron processor.
@fatchickencatcher
@fatchickencatcher 3 жыл бұрын
@@highfidelityinc Thanks Steve, yes I have used that page but it seems too old. I think Node has advanced and the examples do not work. It is the same for all the other pages that I have found. I will investigate your other suggestions. Node rpio claims that it works but I am not skilled enough to sort it out.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
You might want to check out my new video at kzbin.info/www/bejne/j6fWgIihibqmrsk . It describes how to set up a communication link to a Python program. So you could do your MCP3008 in Python (or your preferred programming language) and then send that to the Node Web server.
@harishbetrabet
@harishbetrabet 3 жыл бұрын
Nice video, well explained.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad you liked it!
@azelbane87
@azelbane87 Жыл бұрын
Thank you so much 4 this! MAGNIFICENT!!!MUCH NEEDED!! EXCELLENT 👌🏻👍🏽👌🏻
@highfidelityinc
@highfidelityinc Жыл бұрын
You're so welcome!
@b3nsh4
@b3nsh4 3 жыл бұрын
Nice video! I would prefer python/flask web framework over nodejs and map different endpoints as different functions /turnofLed1 /turnonLed2 and so.. What do you think?
@highfidelityinc
@highfidelityinc 3 жыл бұрын
By all means, if you want to do it in python/flask, go for it. The programming language I program in mainly is "C". I know very little if nothing about Python so python/flash was not a good choice for me. By sticking with Node JS, I just had to learn Javascript as I had to learn that anyway for client side. The main purpose of the video was to give others a working example using websocket in an html5 environment. I started this project with absolutely no knowledge of web development. So when I finally figured out a working solution (which turned out to be node JS), I decided to share it with others. Good luck with doing it in python.
@b3nsh4
@b3nsh4 3 жыл бұрын
@@highfidelityinc I really appreciate what you just showed and it's amazing. But tho I use flask, there won't be websockets. And I don't think I can use flask and socketio in this specific case. But this will be something I'll do in near time. Thank you again!
@highfidelityinc
@highfidelityinc 3 жыл бұрын
You might want to check out my new video at kzbin.info/www/bejne/j6fWgIihibqmrsk . It describes how to set up a communication link to a Python program.
@SA-oj3bo
@SA-oj3bo 3 жыл бұрын
Anyone knows about a tutorial explaining how to do this with python instead of nodeJS? Thx.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
While I have played around with some Python web servers, I haven't seen any examples that demo what I have done in this project with node JS. I am not even sure if it is possible to do web sockets in Python.
@SA-oj3bo
@SA-oj3bo 3 жыл бұрын
​@@highfidelityinc Hi Steve, I am trying now.. websockets exist in python but build on top of asyncio, so I first needed to understand asyncio which was new for me. Then have to run an extra server to serve the webpage first before the websockets server can be used. I can not find any example... I will try to run the low level or flask webserver and webscoket server in different threads.
@highfidelityinc
@highfidelityinc 3 жыл бұрын
By all means, if you want to do it in Python only, go for it. Hope you are successful.
@oscarpantoja7705
@oscarpantoja7705 2 жыл бұрын
Really good video! thnaks
@highfidelityinc
@highfidelityinc 2 жыл бұрын
You're welcome!
@kpm25
@kpm25 Жыл бұрын
Thanks a lot.. I'll give it a go..
@highfidelityinc
@highfidelityinc Жыл бұрын
You're welcome.
@siribvcm9653
@siribvcm9653 3 жыл бұрын
Thanks for the video sir. Because this i can solve my orangepi project
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Glad it helped
@ChylleSuu
@ChylleSuu 11 ай бұрын
Does this only work while on the same network?
@highfidelityinc
@highfidelityinc 11 ай бұрын
This project will work across subnets. So the web interface will work on other networks as long as the network equipment doesn't have any firewall rules to block that traffic.
@marwanalsouki9185
@marwanalsouki9185 3 жыл бұрын
Great presentation thank you
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Glad it was helpful!
@jayweaver5574
@jayweaver5574 2 жыл бұрын
i fixed my problem. was something wrong with my user account setup.
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Good to hear you figure out your issue.
@robvanmoorst3179
@robvanmoorst3179 2 жыл бұрын
Good presentation.
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Glad you liked it!
@jayweaver5574
@jayweaver5574 2 жыл бұрын
Ok I found it, In plane sight. Silly me. Thanks for the help.
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Glad I could help
@havbaba
@havbaba 3 жыл бұрын
In webserver.js function(handler) change: return res.end(content,'utf'); //display 404 on error to: return res.end(content,'utf8'); //display 404 on error This solves the error 404 error ;)
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Good catch. I have updated the code to correct the error. I should note that it looks like the error will only occur if you try to access a web page that does not exist. Thanks for finding this error.
@havbaba
@havbaba 3 жыл бұрын
Indeed, that's the case. Otherwise a very good and helpfull video! Love it and learned a lot about this in just 1 video!
@jorisdenengenieur1239
@jorisdenengenieur1239 3 жыл бұрын
Excellent video Steve. Can you create this without Java and just with Python? I'm not familiar with Java :-/
@highfidelityinc
@highfidelityinc 3 жыл бұрын
More power to you if you want to try to do it in Python. As I mentioned in the video/text, I tried several other webservers (Apache2/NGINX) first but had issues with getting websockets to work properly. Node JS (which is javascript) was the only one I could get to work. No matter what, you will have to learn javascript because that is programming language for the web browser. So while you might be able to implement the web server side in Python, you will still have to use JavaScript on the web browser side.
@jayweaver5574
@jayweaver5574 2 жыл бұрын
hey your video is out of focus here on my tablet
@highfidelityinc
@highfidelityinc 2 жыл бұрын
Looks fine on my computer monitor. Your tablet probably does not have enough resolution or its internet speed is too slow. Watch on a 1080p monitor and ensure you are streaming in 1080P mode. It should be clear then.
@kaddelack
@kaddelack Жыл бұрын
If you use Tailscale you can control this from anywhere in the world. You can also put a domain name to log straight in to the control page, all for free. I want to ask where I can download your code? I did similar project but your implementation is much better then mine :) Please share if you want to!
@highfidelityinc
@highfidelityinc Жыл бұрын
Look at the video description. The link to the code is near the top of the description. There are many ways to do remote access. I myself have an OpenVPN server built into my router. No cloud service required so I never have to worry about the cloud server going away someday.
@rajatchaudhary5060
@rajatchaudhary5060 3 жыл бұрын
Awesome content Sir, Want some guidance from you on this project. Can I have your email?
@highfidelityinc
@highfidelityinc 3 жыл бұрын
Good you hear you like it. I am extremely busy at work right now so I am not available for consultation right now.
@franciscojaviernunez8191
@franciscojaviernunez8191 8 ай бұрын
Hi, Thanks for yours videos. I tried to implement your solucion in a Raspberry pi 3B, and i have problem when i execute you webserver.js.Do you know where is the problem: node:fs:2342 return binding.writeFileUtf8( ^ Error: EINVAL: invalid argument, write at Object.writeFileSync (node:fs:2342:20) at exportGpio (/home/losvolaos/webserver/node_modules/onoff/onoff.js:18:8) at new Gpio (/home/losvolaos/webserver/node_modules/onoff/onoff.js:172:36) at Object. (/home/losvolaos/webserver/gpio/webserver.js:7:13) at Module._compile (node:internal/modules/cjs/loader:1368:14) at Module._extensions..js (node:internal/modules/cjs/loader:1426:10) at Module.load (node:internal/modules/cjs/loader:1205:32) at Module._load (node:internal/modules/cjs/loader:1021:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12) at node:internal/main/run_main_module:28:49 { errno: -22, code: 'EINVAL', syscall: 'write' } Node.js v21.7.2
@highfidelityinc
@highfidelityinc 8 ай бұрын
Difficult so say why it is not working for you. I just installed the ARM 64 bit version on an Raspberry Pi 4 running Raspberry Pi 64 bit OS back a week or two ago and didn't have issues. But the most common reason for the project not working is are: 1) A binding error is usually caused by some other service already running on you Pi that is already using port 80. Be sure to start with a clean installation to ensure no other web servers are running on your pi. 2) You tried to install node via the apt packet manager. Be sure to read the video description and the pdf on my github and following the instructions exactly. 3) The latest version of node may have a bug in it. Installing the previous major release will usually work when that happens. In particular, I would try v20.12.1(LTS). 4) I know the 32 bit version of Node JS has work on the Pi3B running 32 bit OS in the past. However I have not tried it with the 64 bit version so I cannot say for sure the 64 version works with the Pi3B
@franciscojaviernunez8191
@franciscojaviernunez8191 8 ай бұрын
@@highfidelityinc Thank you very much for the answer, I have a 64-bit Raspberry pi 3B. Is the latest version of your project on github or how can I access it? It seems that the problem occurs when accessing the onoff program. If you would like to help me I would love to have your help. Thank you so much!!
@highfidelityinc
@highfidelityinc 8 ай бұрын
@@franciscojaviernunez8191 Sorry, I have not idea why you cannot get it to run other than what I already mentioned. Of course if you are using a 64 bit OS, you need to use the 64 bit arm version of Node. It could be that the Pi3B just will not run the 64 bit version of node. Like I suggested, start with a clean install of the lite or basic desktop 32 bit OS and install absolutely no other software. Use long term support version (LTS) of node and do not update Node if it says there is a update -- many times that will break node. If that doesn't work, it could be a case like the original raspberry Pi zero W being too old to run the latest version of node. In which case you will have to use a very old version of Raspberry Pi OS and a very old version of Node.
@leebaker4263
@leebaker4263 6 ай бұрын
@@franciscojaviernunez8191 Did you ever get this working? I am also getting the same error on both my Pi 2B and Pi 4B, have tried multiple versions of nodejs and different OS (32 and 64 bit versions)
@leebaker4263
@leebaker4263 6 ай бұрын
I managed to get it working on a legacy OS, it looks like something in the latest OS has changed pin numbers and onoff no longer works
µCast #17: Control Hardware Remotely With Socket.IO
18:05
Add a web control panel to your project - the web server
30:50
Bytes N Bits
Рет қаралды 13 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
I Turned A Raspberry Pi Into A Node.js Web Server
7:50
PortEXE
Рет қаралды 114 М.
Tutorial: Control Raspberry Pi GPIO via HTTP Web Server
7:19
Software Sage
Рет қаралды 63 М.
Control Your Raspberry Pi Remotely Using Your Phone | RaspController
8:22
Making Raspberry Pi Web Controls
4:36
Tinkernut
Рет қаралды 189 М.
Raspberry Pi Servo Motor Control
17:36
ExplainingComputers
Рет қаралды 396 М.
Raspberry Pi Plant Watering (& Time Lapse)
23:41
ExplainingComputers
Рет қаралды 340 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН