器材:USB 攝像頭
300萬像素 USB 攝像頭 樹莓派親測可用 免驅動(168塊錢 http://item.taobao.com/item.htm?spm=a1z02.1.5864393.d4908585.MOVO92&id=20650207132)
1:剛裝好的系統,首先更新系統
sudo apt-get update
2: 安裝vim編輯器(nano,vi 都用不習慣)
sudo apt-get install vim
3:配置hosts 文件,更快更新
vim /ect/hosts
添加以下內容
#######################收集的地址
93.93.130.39 www.raspberrypi.org
93.93.130.214 archive.raspberrypi.org
93.93.128.230 www.raspberrypi.org
212.187.212.72 downloads.raspberrypi.org
5.153.225.207 mirrordirector.raspbian.org
61.110.197.50 0.debian.pool.ntp.org
27.54.95.11 1.debian.pool.ntp.org
62.201.215.14 2.debian.pool.ntp.org
86.59.113.114 3.debian.pool.ntp.org
4: 安裝 tightvncserver 配置遠程連接
sudo apt-get install tightvncserver
在Raspberry Pi中輸入以下命令運行VNC服務端,然后設置密碼,在這里我們可以設置一個只用於觀看而不操作Raspberry Pi的密碼:
tightvncserver
然后我們便可以使用VNC,如果你希望以1024 x 728的視窗顯示於你的電腦,就要在Raspberry Pi輸入以下命令:
vncserver :1 -geometry 1024x728 -depth 24
使用TightVNC Viewer 連接
5:使用圖形化配置raspi-config, 這里之所以使用圖形化,是因為 客戶端putty在使用raspi-config出現亂碼
1:Expand filesystem 選擇將根分區擴展到整張SD卡 2:change locale 默認的是 en_GB.UTF-8 UTF-8 按空格是添加/刪除 刪除 en_GB.UTF-8,選擇 zn_GB.UTF-8
5: change Timezone 選擇 Asia Shanghai
6: Change Keyboard Layout 選擇 US
3:Enable Camera 選擇 Enbale
4: SSH 選擇 Enbale
配置完 選擇 Finish 和 reboot
6:生產圖像
查看攝像頭
pi@raspberrypi:~$ ls -l /dev/video0
crw-rw---T 1 root video 81, 0 1ÔÂ 1 1970 /dev/video0
安裝抓圖軟件fswebcam
pi@raspberrypi:~# sudo apt-get install fswebcam
###測試生產圖像
pi@raspberrypi:~$ mkdir yeelink #創建文件夾 存放圖片
sudo fswebcam -d /dev/video0 -r 320x240 --bottom-banner --title "RaspberryPi@Yeelink" --save /home/pi/yeelink/yeelink.jpg #生成圖片
7: 登錄Yeelink(http://www.yeelink.net/), 在用戶中心增加一個設備, 再為之增加一個圖像傳感器。(此塊介紹來之:http://bbs.xiaomi.cn/thread-7363284-1-1.html 特別感謝)
<ignore_js_op>

<ignore_js_op>

<ignore_js_op>

4. 在/home/pi下准備腳本yeelink.sh(vi /home/pi/yeelink.sh), 內容為以下兩行命令, 其中的ApiKey和URL請改為自己設備對應的信息。
sudo fswebcam -d /dev/video0 -r 800x600 --bottom-banner --title "RaspberryPi@Yeelink" --save /home/pi/yeelink/yeelink.jpg curl --request POST --data-binary @"/home/pi/yeelink/yeelink.jpg" --header "U-ApiKey:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" http://api.yeelink.net/v1.0/device/xxxx/sensor/xxxx/photos
為腳本增加可執行權限
pi@raspberrypi ~ $ chmod +x yeelink.sh
5. 將腳本加入cronjob定時任務
pi@raspberrypi ~ $ crontab -e
加入下面一行, 讓腳本每分鍾運行一次, 保存退出。
*/1 * * * * /home/pi/yeelink.sh
至此樹莓派端的搭建已經完成,然后插上網線,連接電源,就可以自動進行傳輸了,到Yeelink個人中心看看你的成功吧,如下圖所示。為了保證圖片傳輸速率,我在樹莓派端搭建的時候將圖片設置成了320×240像素,一般使用已經足夠了,間隔拍攝時間是1分鍾,從Yeelink時間線中可以看到,基本每分鍾都會傳輸一張圖片。