首先是简单的拍照功能,通过下面的php可以实现远程查看照片
| 12
 3
 4
 5
 6
 
 | <?php
 echo shell_exec("raspistill -t 1 -o /home/pi/www/a.jpg -w 2592 -h 1944");
 echo '<img style="width: 80%" src=a.jpg>';
 ?>
 
 
 | 
如果出错需要执行下面的代码: 
来自:http://www.raspbian.org/RaspbianQuake3
然后,是C语言写的定时拍照器,一分钟一张照片
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 
 | #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 int main()
 {
 while(1)
 {
 char cmd[100];
 sprintf(cmd, "raspistill -t 1 -o /home/pi/www/img/%d.jpg -w 1920 -h 1080", $
 system(cmd);
 printf(cmd);
 printf("\n");
 sleep(60);
 }
 }
 
 
 
 | 
然后我们可以通过gcc编译并执行:
但是呢,我们如果关闭putty,拍照就会停止,所以我们需要一个叫screen的东西
| 12
 3
 4
 
 | screen -S "ypw"
 ./a.out
 
 
 | 
执行上面的代码之后,关闭putty也会自动拍照了.
然后有了那么多照片之后,怎么样去查看呢?
那么我们就需要一个php遍历文件了
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
 | <!DOCTYPE html>
 <html lang="zh-CN">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>拍的照片们</title>
 <?php
 $dir=dirname(__FILE__);
 $files = scandir($dir);
 foreach($files as $file)
 {
 if(strpos($file,".jpg"))
 {
 echo '<img style="width:80%" src='.$file.'><br>';
 $time=filemtime($file);
 echo "文件名:$file    拍摄时间:".date("Y-m-d H:i:s",$time)."<br>\n";
 }
 }
 ?>
 
 
 | 
然后保存到/home/pi/www/img文件夹下,这样访问http://192.168.191.3/img/的时候就会返回所有的照片.
拍了一天之后,照片有一千多张,访问刚才那个页面之后内存会崩溃,这样我们就没办法去查看图片了,这时候就需要python来帮忙下载了.
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 
 | __author__ = 'lucky dog'
 
 from bs4 import BeautifulSoup
 from urllib import *
 import os
 
 url = "http://192.168.191.3/img/"
 
 html = urlopen(url).read()
 soup = BeautifulSoup(html)
 imgs = soup.findAll("img")
 for img in imgs:
 print img['src']
 url2 = "http://192.168.191.3/img/"+img['src']
 filepath = "img/"+img['src']
 if not os.path.exists(filepath):
 urlretrieve(url2.encode('utf-8'), filepath)
 
 
 | 
这样图片就都下载下来了.
下面这几张图片就是树莓派和我的植物




之后我觉得晚上都是黑色的图片多无聊,我就加了个灯


