Some simple node.js based scripts for recording my hedge-hogs running around at night.
- Raspberry Pi 2
- Raspberry No-IR camera
- Wi-Pi or some kind of network connection.
- Somewhere to store the videos (i mounted my NAS).
- Flash regular Raspbian onto an SD card (not Noobs) and boot it up. I used a tool called 'rufus' to do this on windows.
- Run
raspi-configto the camera on. - Clone this repo into the
~/home directory. - Run
sudo apt-get update && sudo apt-get upgrade
From the node docs:
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejsI mounted my network storage solution, you can do that by adding this to /etc/fstab
//<ip>/<share> /mnt/nas-videos cifs username=<someuser>,password=<password> 0 0
Use sudo so it can be installed globaly.
sudo npm install -g pm2Then lets add PM2 to run on startup
sudo pm2 startup ubuntuThis will ask you to run a more specific command. Copy and paste this command.
PM2 is now going to start when the pi boots up, so we can piggy-back by auto starting hogcam when PM2 starts:
pi@raspberrypi:~/hogcam $ pm2 start ~/hogcam/index.js --name="hogcam" --watch
[PM2] Starting /home/pi/hogcam/index.js in fork_mode (1 instance)
[PM2] Done.
ββββββββββββ¬βββββ¬βββββββ¬ββββββ¬βββββββββ¬ββββββββββ¬βββββββββ¬ββββββββββββββ¬βββββββββββ
β App name β id β mode β pid β status β restart β uptime β memory β watching β
ββββββββββββΌβββββΌβββββββΌββββββΌβββββββββΌββββββββββΌβββββββββΌββββββββββββββΌβββββββββββ€
β hogcam β 0 β fork β 836 β online β 0 β 0s β 17.605 MB β enabled β
ββββββββββββ΄βββββ΄βββββββ΄ββββββ΄βββββββββ΄ββββββββββ΄βββββββββ΄ββββββββββββββ΄βββββββββββ
Use `pm2 show <id|name>` to get more details about an appI've enabled --watch here so I can edit index.js and refresh the service faster. You don't necessarily need to do this.
This process is now configured to restart whenever it crashes or stops. Finally we need to save the PM2 state so that the process resumes on restart of the raspberry pi.
pm2 save