I have been following QuickPi’s tutorials on getting a USB Camera working with HomeKit. One thing that recently came up was getting HAP-NodeJS to load on boot. CameraCore.js is required and getting it to load on boot was key. Here are the steps and a mention of what was throwing me off.
This method uses rc.local and forever. You can learn more about forever here.
Make sure you have your Raspberry set to wait for the network on boot. You can do the in rapsi-config under the boot options. Ocne you do this then follow along with the rest of this tutorial.
Make sure you are in the home directory. Then install forever with the global. This can take 5 minutes to install so be patient.
cd ~ sudo npm install forever -g sudo nano /etc/rc.local
Now, using nano to edit rc.local we want to add a line of code before the “exit 0” line at the bottom of the file. We want forever to start up the CameraCore.js file.
sudo forever start /home/pi/HAP-NodeJS/CameraCore.js
NOTE: You can do the same thing with BridgedCore.js or Core.js if you are using them for any reason.
Save (Ctrl+O) and exit(Ctrl+W) the rc.local file once you are done. Don’t forget to reboot.
That is pretty much the extent of getting HAP-NodeJS to load on boot.
Unfortunately for me, even after this I could’t get CameraCore.js to load on boot. Or that is what I thought. My mistake was not checking if it was running as sudo.
You can use ‘forever list’ to tell you what processes are running. But as you see below nothing is running even after a reboot.
pi@TheaterCam:~ $ forever list info: No forever processes running
After pulling my hair out I figured out that since the rc.local command was run as sudo I had to use ‘forever list’ also as sudo.
pi@TheaterCam:~ $ sudo forever list info: Forever processes running data: uid command script forever pid id logfile uptime data:  j-_g /usr/local/bin/node /home/pi/HAP-NodeJS/CameraCore.js 1041 1138 /root/.forever/j-_g.log 0:0:13:3.917
As sudo I can see that in fact the CameraCore process is running.
One more bit of code that might help those of you to test and debug is running the rc.local from the terminal. If it is not working from the rc.local this is a nice option. You can do this by entering the following.
sudo sh /etc/rc.local
This was actually how I found out that the CameraCore process was already running. I got errors and the Raspberry Pi CPU resource meter was pinged out at 100%.
A final note, you can kill all forever process with the following.
sudo forever stopall