To run the Security Camera scripts you will need to install additional packages on the Raspbian operating system.
You will perform the following tasks in this section:
- Configure your USB cellular module
- Install necessary Linux packages to run the Security Camera scripts
- Add your Security Camera to the front-end created in the Deploy scripts to Functions step
- Configure Security Camera scripts with URLs created in the Deploy scripts to Functions step
- Make the Node.js application run at boot up time on the Raspbian operating system
Configure the USB cellular modem
The Raspberry Pi Zero W was chosen for this Blueprint because it is Wifi enabled - a huge advantage during the configuration process. In the link below, you will download and install the necessary packages to enable the USB cellular modem for remote access with Twilio Programmable Wireless.
Visit our detailed guide, “Connect using Raspberry Pi and a Cellular USB modem”, to learn the various ways to enable cellular connectivity on your device. This is a necessary step if you wish to create a portable camera that transmits images over the cellular network.
Start at the My Raspberry Pi is connected to the Internet by wifi or ethernet step.
Add your Security Camera to the front-end
- Visit the front-end site created in the Deploy scripts to Functions step
- Click the Add Camera button at the top right corner of the website
- Click the Add New Camera button
- Enter the Twilio phone number provisioned in the Deploy scripts to Functions step
- Click the Submit button
- Make a note of the ID generated you will add this to the Raspbian Security Camera script
- Make a note of the Token generated you will add this to the Raspbian Security Camera script
Install required Linux packages
Open a terminal and type the following commands:
sudo apt-get update sudo apt-get install nodejs libopencv-dev
This section requires an Internet connection. You can use either Cellular or Wifi connectivity during this step. It’s recommended you use Wifi if it’s available as this is only a configuration step and will save you on data usage. You can monitor your SIM usage in the Data Usage section of the Console.
Enable the camera
Type the following in the command line:
Scroll down to Enable Camera in the menu system
- Press Enter to enable the camera
We recommend rebooting the Raspberry Pi at this point.
Install Raspbian Security Camera scripts
Make the camera directory in /home/pi
mkdir /home/pi/camera mkdir /home/pi/camera/images
Download the Node.js script and dependency file from the Security Camera repository into /home/pi/camera
wget https://raw.githubusercontent.com/twilio/wireless-security-camera/master/pi/security-camera.js wget https://raw.githubusercontent.com/twilio/wireless-security-camera/master/pi/package.json
Install Node.js modules from package.json
Open security-camera.js to configure front-end credentials
sudo leafpad /home/pi/camera/security-camera.js
Change the clientBootstrapUrl variable on line 13 of security-camera.js to the URL where your CameraAuthenticator Function is deployed from the Deploy scripts to Functions step
- Change the cameraId variable on line 11 to the ID you used when adding the camera from the Add your camera to the front-end section above
- Change the cameraSecret variable on line 12 of security-camera.js to the token generated from the Add your camera to the front-end section above
Run the script by typing the following in a terminal
cd /home/pi/camera npm start
Configure security-camera.js to run at startup
You can manually run the script every time you want to use the camera or have it run when the Raspberry Pi boots up.
To have security-camera.js run at startup:
Type the following commands in a terminal
su pi -c 'node /home/pi/camera/security-camera.js < /dev/null &'
Enter the password for the pi user
- Default password is raspberry
The script is set to run everytime the Raspberry Pi boots up.
Want more control of Node.js scripts on boot? Read this tutorial on using PM2, a Node.js process manager.
You completed the following task in this section:
- Installed the Linux dependencies to run the Node.js application
- Added your Security Camera to the front-end created in the Deploy scripts to Functions step
- Configured the security-camera.js script with URLs created in the Deploy scripts to Functions step
- Made security-camera.js run at boot up time on Raspbian operating system
Continue on to the next section to finalize and test your new Security Camera!