RaspberryPi/Timelapse2
From charlesreid1
Outline: Raspbian
The issue with using Kali was, the use of the camera required onboard video libraries that did not come bundled with Kali. These were also not in the aptitude repositories, and I had no luck installing them. So for the camera project I decided to go with Raspbian and not sink any more time into getting Kali to work with camera hardware.
pi/raspberry
Hardware
- Raspberry Pi
- Pi camera
- Camera case
- Network cable
- Power cable
Setting up the Pi
To begin with, I installed a fresh Kali Linux arm image. I wanted to make sure I had installed the operating system correctly and that I could reach the Pi just fine. I connected the Pi directly to my laptop using a crossover cable. After connecting the two, I restarted both machines. They automatically picked link-local addresses at 169.254.X.Y, which I was able to use to SSH directly into the Pi.
This confirmed that I had everything working ok on the Pi.
Connecting to the Pi
I connected the Pi to a router, set a fixed IP address on the boot line of cmdline.txt on the memory card's boot sector, and plugged it into my home router. I then fired up the Pi.
SSH to 192.168.0.111 confirmed I was able to remotely reach the Pi. The Pi was also able to successfully reach the gateway and the outside internet.
Installing stuff
Get busy installing stuff:
apt-get install -y screen screen
In the new screen window:
apt-get install -y vim aptitude apt-get install -y python build-essential apt-get install -y python-pip
This doesn't do much - most everything here is already installed.
Now install the pi camera library (should also be already installed):
pip install picamera
Now one last thing to do before testing the camera is to enable the boot flag that lets you use the camera (disabled by default).
Run raspi-config and pick the camera menu item (number 6). Choose to enable the camera. Save changes, and you'll be asked to reboot the Pi. Reboot the Pi. Now you can try out the camera.
Testing Picamera
Open python and try to import the picamera library:
import picamera
Now try capturing your first photo:
import picamera
camera = picamera.PiCamera()
camera.capture('helloworld.jpg')
Woo hoo! Works perfect!
Problems out of nowhere
Suddenly, out of nowhere, just when I had finished rigging the wireless and the zip ties and the camera box, everything failed. The camera would no longer respond. Hardware connection problem. Tear it all apart.
Resolution
The problems that came out of nowhere turned out to be connection problems with the flat yellow plate on the front of the camera face. I had to re-seat that plate snugly. After that, the camera worked fine.
Next Steps
Next steps consisted of testing, one step at a time, each aspect of the configuration. The steps were as follows:
With crossover cable:
- Crossover cable, 169.254.111.111, test local ssh to Pi - PASSED
- Crossover cable, 169.254.111.111, test whether we can capture a photo from the camera - PASSED
With wireless: RaspberryPi/Wireless
- Wireless, 192.168.0.X, test whether we can connect to the wireless - PASSED
- Wireless, 192.168.0.X, test whether we can auto-MAGIC-ally connect to the wireless on boot - PASSED
- Wireless, 192.168.0.X, test whether we can plug in on other side of house, ssh in, start/finish photo capture, run http server - PASSED
- Wireless, 192.168.0.X, test whether we can capture photos, with everything taped into position -
- Wireless, 192.168.0.X, test whether we can run a time lapse test
Last Steps
DO IT!!! Take a timelapse for 2 seconds at a time.
Scripting
To script taking a picture, use the following code, which loops forever, taking photos and marking them with timestamps:
# pic.py
import picamera
from datetime import datetime
import time
camera = picamera.PiCamera()
while True:
prefix = datetime.strftime(datetime.now(),"photo_%Y%m%d-%H%M%S")
filename = prefix+".jpg"
camera.capture(filename)
print "Saving photo to %s"%(filename)
time.sleep(2)
Flags