Total Pageviews

Monday 11 July 2016

我用树莓派做的事情


翻译:
树莓派是一种便宜的卡片式Linux电脑,风靡全球。它是世界上众多廉价又成熟的电脑之一,只要35美元,而且十分容易上手。树莓派有成千上万种玩法,但我常常发现有些人心血来潮买了树莓派后,却突然不知道自己要用它来做什么了。现在我就记录下我现在和过去都用树莓派来做哪些事。


1.备份邮件

我使用树莓派的最重要的功能之一就是备份我的邮件。我使用一个叫做getmail的软件来检查每份使用POP或者IMAP协议的邮件,定时查看各个帐号的邮件。然后把邮件保存到一个mbox文件,这个文件可以在任何时候被复制到另一台电脑上做长期的邮件归档。

2.搭建个人RSS阅读器

我最近发现了miniflux,一个自托管的基于网络的RSS客户端,可以安装到树莓派上。和许多人一样,当谷歌宣布将在7月1号关闭Google Reader后我也开始将个人数据迁移出来。我使用了一阵子rss2email,让它把RSS每一条目都发送到我的邮箱中。但其实我不是很喜欢这个方法,于是我花了点时间寻找Google Reader替代品并试过了rss2email之后找到了miniflux。在树莓派上安装miniflux十分简单,你只需要提前安装PHP和一个web服务器软件就好了,比如nginx或者Apache。

3.搭建网站

树莓派一个很明显的用处就是作为网站的后台服务器。我曾这么用过一阵子,而且很快就要重新这么干。树莓派有足够的能力来处理静态网站,一些web框架也不成问题。我就在上面搭建过一个Flask框架,我甚至听说有的人直接在树莓派搭建了个Wordpress。

4.家用网络存储

只消耗很低的电量,树莓派就可以成为一个完美的NAS(网络连接式存储)。之前我把一个500GB的笔记本硬盘连接到树莓派上,还在上面安装了一个操作系统。我可以在上面存放许多需要在不同电脑间传输的文件。然后通过SFTP来连接,然后在家里的任何机器上都可以访问(即使不在家,只要路由设定对了也不成问题)。你也可以在派上安装Samba,这样Mac和PC都可以更容易地存取。

5.站点监控

树莓派的另一个用处就是用来检测对我来说很重要的网站。我写了个Python脚本并定时运行,确保这些网站回复一个200状态码(这意味着一切正常)。如果脚本判断出网站出了问题或者无法访问,会把这个事件的总体情况发邮件给我。我使用的Python模块是Requests,而发邮件的模块则是smtplib。

6.事件提醒

我让树莓派把我需要记住的重要事件发邮件给我。之前我用的是谷歌日历,但我只在简单事件才用它。所以我用树莓派代替了它,一段定时任务的Python脚本就够了。我设定了要记住的日期、时间和消息,这些参数会传给我的Python脚本,到了那一天它就会把消息发送到我的邮箱,提醒我当天的事件。

7.家庭相册

我的树莓派同时还支持着一个私人网站,网站放着我所有的家庭照片。我设立了验证信息所以只有我希望让他们看到的人才能进入网站。这比你的Facebook相册要靠谱多了,因为脸书上面你的账户有可能被删除,而且照片会被陌生人偶然看到。很简单,就是用PHP获取树莓派上一个文件夹里的照片而已。

8.点唱机

上面提到我把派当作一个网络存储器,所以我所有的音乐也都在上面。我的派上接了个立体扬声器,然后使用mpg123在树莓派的命令行里播放音乐。虽然有很多其他的mp3播放器,图形界面的也有,但我还是选择mpg123,因为它简单好用,安装也很方便。

9.安全摄像头

我曾经接了个摄像头,并使用一个叫motion的软件来捕获我屋子前的各种瞬间。motion很强大,你可以在它基础上个性化以及自由扩展,以满足各种图像和视频捕捉。我有个网站专门放着树莓派和motion拍下来的照片,点击每张照片都是相关的一段视频。

备注:
我知道肯定不少人要说这些树莓派的用处都可以在任何一台Linux电脑上完成。这话没错,并且我支持你使用一台旧笔记本来实现这些东西。但树莓派比较环保而且不会耗你那么多电费,所以我觉得上面大多数用处还是在树莓派上实现比较好。

英文原文:

Check out more posts about the Raspberry Pi here: Raspberry Pi Posts
The Raspberry Pi, an inexpensive and tiny Linux machine, has garnered much popularity. At $35, it's one of the cheapest full-blown computers that you can buy and easily use out of the box. There a a ton of uses for a Raspberry Pi, but I often see people buy one on impulse and then find themselves at a loss for what they should do with it - the Pi just ends up sitting on a shelf. Here I will keep track of how I am using my Raspberry Pi and what I have used it for in the past.
1. Backing up my email 
One of the most important uses I have for my Raspberry Pi is backing up my email. I use a program called getmail that can be used to check an email account using POP or IMAP. I have it checking my gmail and other email accounts at regular intervals with cron job. The email is saved to a mbox file that can be copied to another computer at any time for long-term email archiving. I wrote a small guide about how I do this here: How to Back Up Email with Getmail.
2. Security camera 
For a while I had a webcam connected to my Raspberry Pi and was using a program called motion to detect and capture images of movement in front of my house. motion is a powerful program that can be heavily customized/extended to do all kinds of image and video capture. I had a site set up to view the images taken by the Raspberry Pi and motion, and each image was a link to a video of the event.
3. Host my personal RSS reader 
I recently discovered a self-hosted, web-based RSS client called miniflux that can be installed on a Raspberry Pi. I, as many have, migrated off of Google Reader when it was announced that it would be shut down on July 1, 2013. I was using a program called rss2email for a while to send RSS feed items to my email inbox. However, I wasn't as happy with that method and I found miniflux after looking around for an alternative to Google Reader and rss2email. miniflux is very simple to set up on a Raspberry Pi. All you need is PHP and a web server program like nginx or Apache.
4. Host websites 
One of the most obvious uses for my Raspberry Pi was to host a website or three. For a while, this site was hosted on my Pi (and might be again, soon). The Pi has plenty of horsepower to handle static sites and also some using web frameworks. I've hosted Flask sites on mine and I have read about some people even installing a Wordpress instance on a Raspberry Pi. Here are a couple of tutorials to get you started:
5. Household NAS 
With the very low power usage of a Raspberry Pi, it's a perfect candidate for being a NAS, or network attached storage device. I previously had a 500 GB laptop hard drive connected to the Pi (and was even running the Pi's OS on it). I would store many of the files on it that I needed to transfer between my computers. I would then connect to it via SFTP and have access to all of my media from any machine in my house (or outside of it, with the right routing). You can also set up Samba on a Raspberry Pi to make it easy for Macs and PCs to access the storage. Update: I've started using BitTorrent Sync on my Pi to replace Dropbox. It's working great and I have much more space than what I had onDropbox (2 + 19 GB bonus). You can read about setting it up here: Installing BitTorrent Sync on a Raspberry Pi.
6. Pingdom replacement 
Another use I have put my Raspberry Pi to is checking web sites that are important to me. I have written a Python script and run it at regular times to make sure these sites return a 200 status (meaning they are up). The script will email me a summary of the incident if the site is deemed to be down or inaccessible. I use a Python module calledRequests to check the site, and another called smtplib to email me.
7. Event Reminder 
I use my Raspberry Pi to email me about important events that I need to remember. I previously used Google Calendar, but I only needed it for simple reminders. So I substitute the functionality with my Raspberry Pi, a Python script and cron jobs. I set a cron job for the date and time I need to remember, which executes the python script and passes in a message argument. This message is sent to my email and reminds me of the event on the date that I choose.
8. Host a family photo album 
My Raspberry Pi also hosts a private website that displays all of my family photos. I have set up authentication for the site so that only people I wish to see it can access it. This is a good replacement for placing all of your photos on Facebook, where you account can be deleted or photos viewed by strangers on accident. It's a simple PHP site that loads images from a directory on the Pi that I choose.
9. Jukebox 
Since my Pi acts as a NAS, I have all of my music stored on it. I also have a set of stereo speakers connected to the audio jack on the Pi and I use mpg123 to play music from the Raspberry Pi's command line. Although there are other mp3 players out there, including graphical ones, I went with mpg123 for it's simplicity and ease of set up.
10. Calendar and Contact Syncing 
Since I don't really trust Google to sync my contacts and calendar to my phone anymore, I set up a CalDav and CardDav server on my Raspberry Pi. I use Radicale as the server (http://radicale.org/) and DavDroid on my phone as the client. Radicale is easy to set up, and you can get DavDroid for free if you use F-Droid, the alternative Android market. Now that all my contacts and events are synced to my Pi, I'm the only one that sees them, I can back them up at the filesystem, and I don't have to worry about a company deciding they would rather my use a new Calendar or Contact storage paradigm on a whim.
11. Git Repo Server 
If you're a developer or like versioned files, you can set up your Pi to serve your git repos. All you have to do is do a git clone --bare from your repo's current location. Then you can access the repo at ssh://yourpi.com/absolute/path/to/repo, replacing each part of the url with your info.
Side note:
I know a lot of people complain that any of these uses for the Raspberry Pi can also be applied to any other Linux machine. This is true, and I encourage you to use an old laptop to experiment with these activities. But the Pi is silent and won't show up on your electricity bill as heavily, so I think it is better suited for many of these projects.

from  http://magnatecha.com/things-i-do-with-my-raspberry-pi/
------------------

Installing BitTorrent Sync on a Raspberry Pi

I've been looking for a replacement for Dropbox for a while now. I've tried OwnCloud, but it seemed awefully slow on a normal machine, and especially slow on a Raspberry Pi. It seemed to heavy for the simple task of file syncing, anyway, with all of its features. I knew about BitTorrent Sync, but didn't know that there was an ARM version of the client for it. When I saw that there was, I decided to try it out on the Raspberry Pi. It works great and with the Pi always on it replaces Dropbox perfectly for my needs.

To install BitTorrent Sync on your Raspberry Pi download the ARM version  and transfer it to your Pi. Next, extract it and in the folder you will find the BitTorrent Sync binary called btsync. Following BitTorrent's instructions, simply run that binary by entering `./bstync` in your Raspberry Pi's terminal.

Next, you can visit /gui on port 8888 of your Pi. So if your Pi's IP address is 192.168.1.4, visit http://192.168.1.4:8888/gui to set up the folders you want to share.

Once you select a folder to sync on the Pi, you can generate a secret string for that folder. When you enter that string in the web interface for BitTorrent Sync running on another computer, it will start syncing files from that folder on your Pi. To get BitTorrent Sync for your other computer (Windows, Linux, or Mac) go to that same download page and download the client for your machine.

BitTorrent Sync is a great replacement for Dropbox or other similar file syncing software. You also get to control the computers that your files are on with BitTorrent Sync, and aren't vulnerable to anyone deleting an account and endangering your data.

If you have any questions just ask them in the comments below and I'll help you out.

from http://pitown.blogspot.com/2014/03/installing-bittorrent-sync-on-raspberry.html
(此网页的下面有树莓派可买)
----------------

此网站http://pitown.blogspot.com
Guides and News about the Raspberry Pi。
----------------------------

http://www.geekfan.net/category/hardware/raspberry-pi-hardware/ 
有关树莓派的文章。
----------

http://www.wolfram.com/raspberry-pi/