(一)树莓派使用USB摄像头
说明最好是linux下能支持的uvc摄像头,我用的uvc301的摄像头,linux下一般免驱。
1.首先更新firmware:
rpi-update是老外开发的一个更新树莓派firmware的工具,很方便也很好用,推荐给大家!
红色部分是需要输入的:
$ sudo apt-get update
$ sudo apt-get install ca-certificates
$ sudo apt-get install git-core
$ sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
$ sudo chmod +x /usr/bin/rpi-update
$ sudo rpi-update
Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS
Performing self-update
Autodetecting memory split
Using ARM/GPU memory split of 192MB/64MB
We're running for the first time
Setting up firmware (this will take a few minutes)
Using SoftFP libraries
/opt/vc/sbin/vcfiled: error while loading shared libraries:libvchiq_arm.so: cannot open shared object file: No such file or directory
If no errors appeared, your firmware was successfully setup
A reboot is needed to activate the new firmware
$ sudo ldconfig
$ sudo rpi-update
Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS
Performing self-update
Autodetecting memory split
Using ARM/GPU memory split of 192MB/64MB
Updating firmware (this will take a few minutes)
Your firmware is already up to date
$ sudo reboot
备注:
09-18版本以后的官方镜像都集成了rpi-update工具,直接执行“sudo rpi-update”就行了,不需要再安装了
2.插上usb摄像头,输入
ls /dev,
查看dev中是否存在一个video0这个设备,如果有了说明系统识别了,如果不认,重复第一步确保firmware最新,还不行就换摄像头吧
3.安装mplayer,输入
sudo apt-get install mplayer
4.输入命令播放摄像头视频(可能是我摄像头没调好,显示出来很花。。。。。。)
sudo mplayer tv://
5.安装强大的网络监控软件motion,输入
sudo apt-get install motion (如果安装不了的,可以先sudo apt-get update 一下)
6.配置motion,编辑motion.conf文件
sudo vi /etc/motion/motion.conf (或者运行sudo xedit /etc/motion/motion.conf)
7.找到”control_localhost on “和”webcam_localhost on“这两行,改为以下两行后,保存退出
control_localhost off
webcam_localhost off8.运行motion软件,输入
motion -n
9.在pc上用IE浏览器打开,
192.168.99.53
是我的树莓派ip,
换成你们自己的
配置网页:http://
192.168.99.53
:8080
监控网页:http://
192.168.99.53
:8081
(二)树莓派玩家5分钟内将树莓派-USB摄像头与Yeelink连接–最好玩的网页监控器
5分钟一点也不夸张, 在你熟悉Yeelink使用的情况下, 你真的只需几分钟就可以搭建一套在线图像监控, 神马入室小偷啥的, 还能逃过你的千里眼
当然, 要是使用motion来获取图像, 还能做到画面动作检测, 有兴趣的同学可以继续发挥哦. 废话少说, 来看看几分钟怎么做到的吧.
1. 将USB摄像头接到Pi上, 安装驱动, 我所使用的版本(2012-10-28-wheezy-raspbian.img)已经包含了V4L2驱动, 略去xxx字. 有问题的话Google一下
pi@raspberrypi ~ $ ls -l /dev/video0 crw-rw---T 1 root video 81, 0 Jan 1 1970 /dev/video0
2. 安装抓图软件fswebcam
pi@raspberrypi ~ $ sudo apt-get install fswebcam
3. 登录Yeelink, 在用户中心增加一个设备, 再为之增加一个图像传感器.
4. 在/home/pi下准备脚本yeelink.sh, 内容为以下两行命令, 其中的ApiKey和URL请改为自己设备对应的信息.
sudo fswebcam -d /dev/video0 -r 320x240 --bottom-banner --title "RaspberryPi @ Yeelink" --no-timestamp /home/pi/yeelink.jpg
curl --request POST --data-binary @"/home/pi/yeelink.jpg" --header "U-ApiKey: xxxxxxxxxxxxxxxxxxxx"http://api.yeelink.net/v1.0/device/1022/sensor/1294/photos
为脚本增加可执行权限
pi@raspberrypi ~ $ chmod +x yeelink.sh
5. 将脚本加入cronjob
pi@raspberrypi ~ $ crontab -e
加入下面一行, 让脚本每分钟运行一次, 保存退出.
*/1 * * * * /home/pi/yeelink.sh
搞定, 至此我们的监控就开始运行了, 上网页上看看效果吧
http://www.yeelink.net/devices/1022
(三) 利用bypy实现树莓派NAS同步百度云
详见。
Bypy是一个百度云/百度网盘的Python客户端,主要的目的就是在Linux环境下(命令行)同步百度云盘空间。Bypy要求python2.7以上版本,最新版下载地址为https://github.com/houtianze/bypy
一、bypy安装
1、所需环境
python 2.7x
python requests库(安装该库需要setuptools 和pip)
2、安装
(1)python 2.7 不在详述
(2)requests库安装
首先安装setuptools
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
如果安装过程中出现问题,可能是没有安装zip解压的原因,zip如何安装请百度。
然后安装pip
https://pypi.python.org/pypi/pip 从这里下载pip-1.5.6.tar.gz
tar -zxvf pip-1.5.6.tar.gz
python setup.py install
安装完成后,pip install requests。实现requests的安装。
(3)安装bypy
直接从https://github.com/houtianze/bypy下载解压就可以了。
3、使用
(1)第一次使用
要把系统的区域编码设置为UTF-8
vi /etc/sysconfig/i18n
将原内容改为:
LANG="zh_CN.UTF-8"
SYSFONT=latarcyrheb-sun16
设置token:
./bypy.py info
or
./bypy.py --disable-ssl-check info
程序会要求你访问一个网址,获取你授权码,授权后复制code给程序,程序会利用不同的服务器进行认证,认证成功会显示百度网盘的容量,如果一次没成功,可以多试几次,容易被墙。
名称: 个人百度云盘CMD
ID: 5086425
API Key:TG3X5KahFVkmik87Rf46gLMU
Secret Key:F9WIzAVVvEjVP9nuQV1AaoO8NpgIi5UA
<span style="color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">http://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&redirect_uri=oob&response_type=code&client_id=TG3X5KahFVkmik87Rf46gLMU</span>
login_code: <span style="font-family: verdana, Arial, Helvetica, sans-serif;">b448929eb5ff07ded5a4420bfa216150</span>
https://openapi.baidu.com/oauth/2.0/token?
grant_type=authorization_code&
code=b448929eb5ff07ded5a4420bfa216150&
client_id=<span style="font-family: verdana, Arial, Helvetica, sans-serif;">TG3X5KahFVkmik87Rf46gLMU</span><span style="font-family: verdana, Arial, Helvetica, sans-serif;">&</span>
client_secret=<span style="font-family: verdana, Arial, Helvetica, sans-serif;">F9WIzAVVvEjVP9nuQV1AaoO8NpgIi5UA</span><span style="font-family: verdana, Arial, Helvetica, sans-serif;">&</span>
redirect_uri=<span style="font-family: verdana, Arial, Helvetica, sans-serif;">oob</span>
<pre style="word-wrap: break-word; white-space: pre-wrap;">{"expires_in":2592000,
"refresh_token":"22.66b955170a96ddb2137dd73facd5d903.315360000.1734598642.31043809985086425",
"access_token":"21.83601609dc191cf7843efe5f2193efaa.2592000.1421830642.31043809985086425",
"session_secret":"38a93f152524f90d04b763804a696800",
"session_key":"9mnRfCGbRcZZdf\/3fpgvDv58Qm9Oth14TOl6plEfBiKubkZwF3pDlQ16czfsQbGjVUUrIcF2nWATlJypTSIdiuqlBINDgz5wcw==",
"scope":"basic netdisk"}
{
"access_token": "1.a6b7dbd428f731035f771b8d15063f61.86400.1292922000-2346678-124328",
"expires_in": 86400,
"refresh_token": "2.385d55f8615fdfd9edb7c4b5ebdc3e39.604800.1293440400-2346678-124328",
"scope": "basic email",
"session_key": "ANXxSNjwQDugf8615OnqeikRMu2bKaXCdlLxn",
"session_secret": "248APxvxjCZ0VEC43EYrvxqaK4oZExMB",
}
这时百度网盘的“我的应用管理”下会形成bypy文件+。
安装完全后,可以使用./bypy.py list 来看一下列表。
(2)主要命令参数
optional arguments:
-h, --help show this help message and exit
--TESTRUN Perform python doctest [default: False]
--PROFILE Profile the code [default: False]
-V, --version show program's version number and exit
-d, --debug enable debugging & logging [default: 0]
-v, --verbose set verbosity level [default: 0]
-r RETRY, --retry RETRY
number of retry attempts on network error [default: 5
times]
-q QUIT, --quit-when-fail QUIT
quit when maximum number of retry failed [default:
False]
-t TIMEOUT, --timeout TIMEOUT
network timeout in seconds [default: 60]
-s SLICE, --slice SLICE
size of file upload slice (can use '1024', '2k',
'3MB', etc) [default: 20 MB]
--chunk CHUNK size of file download chunk (can use '1024', '2k',
'3MB', etc) [default: 20 MB]
-e, --verify Verify upload / download [default : False]
-f, --force-hash force file MD5 / CRC32 calculation instead of using
cached values [default: False]
-l LISTFILE, --list-file LISTFILE
input list file (used by some of the commands only
[default: None]
--resume-download RESUMEDL
resume instead of restarting when downloading if local
file already exists [default: True]
--include-regex INCREGEX
regular expression of files to include. if not
specified (default), everything is included. for
download, the regex applies to the remote files; for
upload, the regex applies to the local files. to
exclude files, think about your regex, some tips here:
https://stackoverflow.com/questions/406230/regular- expression-to-match-string-not-containing-a-word
[default: ]
--on-dup ONDUP what to do when the same file / folder exists in the
destination: 'overwrite', 'skip', 'prompt' [default:
overwrite]
--no-symlink DON'T follow symbol links when uploading / syncing up
[default: True]
--disable-ssl-check DON'T verify host SSL cerificate [default: True]
-c, --clean 1: clean settings (remove the token file) 2: clean
settings and hash cache [default: 0]
Commands:
help command - provide some information for the command
cleancache - remove invalid entries from hash cache file
combine <remotefile> [md5s] [localfile] - try to create a file at PCS by combining slices, having MD5s specified
compare [remotedir] [localdir] - compare the remote direcotry with the local directory
copy/cp <from> <to> - copy a file / dir remotely at Baidu Yun
delete/remove/rm <remotepath> - delete a file / dir remotely at Baidu Yun
downdir <remotedir> [localdir] - download a remote directory (recursively)
downfile <remotefile> [localpath] - download a remote file.
dumpcache - display file hash cache
list/ls [remotepath] [format] [sort] [order] - list the 'remotepath' directory at Baidu PCS
listrecycle [start] [limit] - list the recycle contents
meta <remotepath> [format] - get information of the given path (dir / file) at Baidu Yun.
mkdir <remotedir> - create a directory at Baidu Yun
move/mv/rename/ren <from> <to> - move a file / dir remotely at Baidu Yun
quota/info - displays the quota information
refreshtoken - refresh the access token
restore <remotepath> - restore a file from the recycle bin
search <keyword> [remotepath] [recursive] - search for a file using keyword at Baidu Yun
stream <remotefile> <localpipe> [format] [chunk] - stream a video / audio file converted to M3U format at cloud side, to a pipe.
syncdown [remotedir] [localdir] [deletelocal] - sync down from the remote direcotry to the local directory
syncup [localdir] [remotedir] [deleteremote] - sync up from the local direcotry to the remote directory
upload [localpath] [remotepath] [ondup] - upload a file or directory (recursively)
eg. => /apps/bypy/20141222test/shan.jpg (/我的应用数据/bypy/20141222test/shan.jpg)
./bypy.py -v upload "/users/hardwu/Desktop/shan.jpg" "/20141222test/shan.jpg"