Oct 28

将保存的连续图片拷贝到 Linux 上,通过 mencoder 就可以合并成视频文件:

$ sudo apt-get install mencoder
$ cd imagin //先进入图像所在目录
$ mencoder mf://*.jpg -mf w=320:h=240:fps=24:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

关于命令参数的说明:

mencoder一行表示将当前目录下的所有.jpg图片转换成一个.avi视频
w=320:h=240 – 图像的尺寸是320×240,根据实际情况可更改
fps=24:type=jpg – 每秒24帧,文件的类型是jpg,根据实际情况可更改
-ovc – 指定视频编码
-oac – 指定音频编码

Sep 27

获得domain_id:

curl -k https://dnsapi.cn/Domain.List -d "login_email=xxx&login_password=xxx"

获得record_id:

curl -k https://dnsapi.cn/Record.List -d "login_email=xxx&login_password=xxx&domain_id=xxx"

在下面的Python脚本中替换上你的Email,密码,域名ID,记录ID等参数,就可以了。

#!/usr/bin/env python
#-*- coding:utf-8 -*-
 
import httplib, urllib
import socket
import time
 
params = dict(
    login_email="email", # replace with your email
    login_password="password", # replace with your password
    format="json",
    domain_id=100, # replace with your domain_od, can get it by API Domain.List
    record_id=100, # replace with your record_id, can get it by API Record.List
    sub_domain="www", # replace with your sub_domain
    record_line="默认",
)
current_ip = None
 
def ddns(ip):
    params.update(dict(value=ip))
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
    conn = httplib.HTTPSConnection("dnsapi.cn")
    conn.request("POST", "/Record.Ddns", urllib.urlencode(params), headers)
     
    response = conn.getresponse()
    print response.status, response.reason
    data = response.read()
    print data
    conn.close()
    return response.status == 200
 
def getip():
    sock = socket.create_connection(('ns1.dnspod.net', 6666))
    ip = sock.recv(16)
    sock.close()
    return ip
 
if __name__ == '__main__':
    while True:
        try:
            ip = getip()
            print ip
            if current_ip != ip:
                if ddns(ip):
                    current_ip = ip
        except Exception, e:
            print e
            pass
        time.sleep(30)

我是将pypod.py文件放在/usr/local/bin/目录下的,注意修改自己的路径。

加入开机自动运行的方法:
编辑/etc/rc.local文件,在“exit 0”那一行前面加上一行:

su root -c "python /usr/local/bin/pypod.py >/tmp/dnspod.log 2>&1"

更好的方法就是添加cron任务,每两分钟检查一次:

sudo crontab -e
*/2 * * * * python /usr/local/bin/pypod.py >/tmp/dnspod.log 2>&1

转自:http://shumeipai.nxez.com/2013/09/17/dnspod-update-dynamic-ip-resolution.html

Sep 05

1.编译安装

svn co https://svn.ntop.org/svn/ntop/trunk/n2n
cd n2n/n2n_v2
make
sudo make install

2.Supernode 节点调试

supernode -l [listening port] [-v] [-h]
#测试的时候,建议开启调试日志,比如:
supernode -l 8080 -v

3.添加节点

sudo edge -d edge0 -a 10.0.0.3 -c chun -u 1000 -g 1000 -k chunchu -l 111.111.111.111:8080 -m e8:5e:02:2a:21:32

4.添加系统启动自动运行

sudo vim /etc/rc.local 
sudo edge -d edge0 -a 10.0.0.3 -c chun -u 1000 -g 1000 -k chunchu -l 111.111.111.111:8080 -m e8:5e:02:2a:21:32

Linux 下安装最为方便,按照上述的步骤的1、3、4即可。

OpenWrt 路由器的配置参照 连接

Windows 下需下载 N2N 的GUI客户端,地址为 http://sourceforge.net/projects/n2nedgegui/

Android 下 N2N 客户端下载地址为 https://play.google.com/store/apps/details?id=org.zhoubug.n2n_gui

Mac OS 下的安装稍稍麻烦一点,需要安装 tun/tap 补丁,然后下载 N2N 源代码后需要打一下 补丁,在tuntap_osx.o文件里, 删除void tunclose(tuntapdev *device)这行,并将tunclose(device)替换为tuntapclose(device),改动这二处就可以了,然后编译安装。Mac 下会自动生成 tun 设备 tap0, 所以运行时不用指定-d 参数:

sudo edge -a 10.0.0.5 -c chun -k chunchu -u 1000 -g 1000 -m 5c:96:5d:8c:2c:4f -l 111.111.111.111:8080

参考资料:
1.http://www.shuyz.com/n2n-vpn-network-introduction-and-config.html
2.http://www.vpnhosting.cz/wiki/index.php/N2n_Gui_En
3.http://luca.ntop.org/n2n.pdf
4.http://ahui.us/post/p2pvpn_zhi_n2n_an_zhuang_shi_yong.html
5.http://linux.die.net/man/8/edge

Sep 05

1.修改 Debian 中 crontab 默认编辑器 nano 为 vi

sudo update-alternatives --config editor

2.下载 WiFi_Check 脚本及修改权限

sudo wget https://raw.github.com/dweeber/WiFi_Check/master/WiFi_Check -O /usr/local/bin/WiFi_Check
sudo chmod 0755 /usr/local/bin/WiFi_Check

3.添加 Cron 任务每两分钟检查一次

sudo crontab -e
*/2 * * * * /usr/bin/sudo -H /usr/local/bin/WiFi_Check >> /dev/null 2>&1

参考资料:
1.http://blog.csdn.net/god_7z1/article/details/8822130
2.http://weworkweplay.com/play/rebooting-the-raspberry-pi-when-it-loses-wireless-connection-wifi/

Jul 19

1.安装CUPS软件,”CUPS“是linux下可以用通用打印系统

 sudo apt-get install cups

2.允许pi用户配置CUPS,

 sudo usermod -a -G lpadmin pi

3.备份替换CUPS配置:
关闭服务

 sudo service cups stop

备份配置文件

 sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.bak

修改配置文件

 sudo vim /etc/cups/cupsd.conf

全部配置文件如下:

 
#
# "$Id: cupsd.conf.in 9407 2010-12-09 21:24:51Z mike $"
#
# Sample configuration file for the CUPS scheduler.  See "man cupsd.conf" for a
# complete description of this file.
#

# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn

# Deactivate CUPS' internal logrotating, as we provide a better one, especially
# LogLevel debug2 gets usable now
MaxLogSize 10m

# Only listen for connections from the local machine.
#Listen localhost:631
Port 631
Listen /var/run/cups/cups.sock

# Show shared printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseRemoteProtocols cups
BrowseAddress @LOCAL
BrowseLocalProtocols CUPS dnssd

# Default authentication type, when authentication is required...
DefaultAuthType Basic

# Web interface setting...
WebInterface Yes

# Restrict access to the server...

  Order allow,deny
  Allow @Local


# Restrict access to the admin pages...

  Order allow,deny
  Allow @Local


# Restrict access to configuration files...

  AuthType Default
  Require user @SYSTEM
  Order allow,deny


# Set the default printer/job policies...

  # Job/subscription privacy...
  
    Order deny,allow
  

  
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  # All administration operations require an administrator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # All printer operations require a printer operator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # Only the owner or an administrator can cancel or authenticate a job...
  
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  
    Order deny,allow
  


# Set the authenticated printer/job policies...

  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default

  # Job-related operations must be done by the owner or an administrator...
  
    AuthType Default
    Order deny,allow
  

  
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  # All administration operations require an administrator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # All printer operations require a printer operator to authenticate...
  
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  

  # Only the owner or an administrator can cancel or authenticate a job...
  
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  

  
    Order deny,allow
  


BrowseWebIF Yes

#
# End of "$Id: cupsd.conf.in 9407 2010-12-09 21:24:51Z mike $".
#

参考的配置文件
(1)http://jxeeno.tk/local–files/blog:raspberry-pi:print-server/cupsd.conf
(2)https://github.com/bostoneboy/raspberry_pi_stuff/blob/master/cups/cupsd.conf

将Listen localhost:631行注释掉,并在其下方增加一行Port 631以监听来自网络的位置。
在Location /上方增加一行ServerAlias *以接受来自网络的请求。
在Location /与Location /admin区块内增加Allow @Local字段,以实现通过网络访问控制面板。

启动cups服务

 sudo service cups restart

4.编译开源foo2zjs驱动
foo2zjs是一款开源的打印驱动,支持部分打印机,安装该驱动需要下载其官方网站上的源码包进行编译安装。先查询一下自己的打印机是否在支持之列。

如果以前安装过foo2zjs驱动需要先卸载

 sudo apt-get remove --purge foo2zjs

安装基本的编译环境

 sudo apt-get install build-essential

wget -O foo2zjs.tar.gz http://foo2zjs.rkkda.com/foo2zjs.tar.gz
tar -xzvf foo2zjs.tar.gz
cd foo2zjs
make

编辑完成后需要下载相应的打印机的固件

 ./getweb P1505

安装编译好的驱动

 sudo make install
sudo make install-hotplug
sudo make cups

5.向CUPS添加共享打印机
PC端用浏览器打开网站”https://树莓派ip:631/”,点击”Administrator”界面添加对应的打印机,登录帐号和密码是树莓派的pi用户的密码;在local printers中找到usb连接的打印机,(寻找到你自己的打印机),修改打印机名,勾选”共享该打印机”的复选框,进入驱动选择界面。在列表中选择对应的驱动,所有foo2zjs驱动会注明footmatic/foo2zjs字样。再点击”添加打印机”按钮即完成打印机的添加。

6.安装samba服务
要使Windows系统能在局域网内发现树莓派共享的打印机,最好安装samba服务。

 sudo apt-get install samba

7.网络打印机的地址”http://树莓派ip:631/printers/HPPrinter”,PC端按照此地址添加网络打印机和驱动,或者搜索”HPPrinter on RASPBERRYPI”。

8.添加允许打印的用户

 sudo service cups stop
sudo vim /etc/cups/printers.conf
sudo vim /etc/cups/printers.conf.0
添加AllowUser Administrator用户
sudo service cups restart

9.实现iOS6兼容的AirPrint打印共享
这个是没有成功过,不知道是什么原因。
已添加的打印机会自动加入Avahi广播列表,使用苹果Bonjour协议向网络进行广播。所有苹果设备,包括手机、平板电脑和笔记本电脑均可直接发现打印机设备,并实现远程打印。然而为了使其支持iOS6系统,还需增加两个文件。

 # /usr/share/cups/mime/airprint.types image/urf      
urf string(0,UNIRAST)

# /usr/share/cups/mime/airprint.convs image/urf      
application/pdf         100     pdftoraster

参考文献:
1.http://bbs.feng.com/read-htm-tid-7523777.html
2.http://www.maojunliang.com/?p=394
3.http://blog.chinaunix.net/uid-13327770-id-2902327.html
4.https://linuxtechie.wordpress.com/2009/08/11/hp-laserjet-p1505-on-ubuntu/
5.http://foo2zjs.rkkda.com/