This project mixs these two features, and aim to build a wireless time-lapse camera using Raspberry Pi, which is much eaiser than a wireless time-lapse camera in Arduino.
- Raspiberry Pi 2
- Raspiberry camera
- USB Wifi dongle
- Any mobile battery bank or a power supply for Raspberry Pi.
- Raspian (OS for Raspberry Pi)
3. Setup remote server
I use a regular LAMP on my server.
Here is the PHP file that I ues to receive photos from Raspberry Pi:
Upload this HTML file, browse it in your browser to make sure your upload feature work properly.
Make sure your camera work properly before you proceed:
raspistill -o cam.jpg
You should see a photo captured in your home dir.
Implement python script
Instal python setup tool:
sudo apt-get install python-pip
Install required python packages:
pip install picamera pip install PIL pip install requests pip install urllib2
Camera.py simply takes one photo every 20s.
Here is what upload.py about to execute:
Indicate the remote server:
url = 'http://SERVER/camera.php'
internet_on() to test the Ineretnet connection first. If the Internet connection is avaiable, weather or not it is WLAN or LAN, it uploads photos in the
pic dir, and moves uploaded photos to
It assumes that all photos are JPEG files:
And removes all file with 0 size in case photo files created mistakenly:
filesize = os.stat(path).st_size if filesize > 0: pics.append(file) else: os.remove(path)
Comment out these lines if you don't have a rotation problem as I encountered, c
im = Image.open(current_name) out = im.rotate(180) out.save(current_name)
Then upload.py post it to the remote server:
r = requests.post(url, files=current_file)
Comment out these line if you don't need any thumbnail images:
#save a thumbnail out = im.resize((128, 77)) out.save('/home/pi/thumbnail/' +filename)
5. Test wifi upload
Make sure your wifi network work properly.
Execute each python scripts:
You should see the latest photo appears on your sever side. Or error info to debug.
6. Setup crontab script
Create a startcamera.sh file:
nohup python /home/pi/camera/camera.py > log &
Make it executeable:
chmod +x startcamera.sh
Lanuch camera on start:
sudo vim /etc/rc.local
Add line at its beginning (do not add it in any IF-ELSE block):
/usr/bin/python /home/pi/camera/camera.py >/tmp/camlog 2>/tmp/camerr &
Create a upload.sh file:
Make it executeable:
chmod +x upload.sh
Run upload script on start:
sudo crontab -e
*/1 * * * * /home/pi/upload.sh >/tmp/upload 2>/tmp/upload.err
Setup autostart when device boot
Restart the device to test: