默认密码是:“arduino”。复制代码
- $ sshroot@arduino.local
那么,为什么要安装“openssh-sftp-server”呢?因为这个软件包可以让你从Arduino上面轻松上传或下载文件。现在,你可以使用一个通用的SFTP客户端,比如filezilla,transmit,或是cyberduck等等,这样就不用输入麻烦的SCP命令来进行文件传输了。复制代码
- $opkg update
- $opkg install openssh-sftp-server
笔者墙裂推荐你可以在Arduino Yún上插一个SD卡(如果你有一个的话),Arduino Yún设备会自动分配文件路径,地址是mnt/sda1。复制代码
- $opkg update
- $opkg install python-openssl
就可以了。复制代码
- $ opkg update
- $ opkg install kmod-video-uvc
第三步 拍摄你的第一张照片复制代码
- $ opkg install fswebcam
如果一切正常的话,你现在就能拍摄自己的第一张照片啦!注意看看你的SD卡里的内容哦,:)复制代码
- $ cd /mnt/sda1
- $ fswebcam test.png
第四步 安装声卡复制代码
- Process.runShellCommand("fswebcam /mnt/sda1/test.png");
完成安装之后,现在Arduino Yún设备就有了声卡支持了。笔者只尝试了下MP3格式的音乐播放,还没有自己录制一些音频,但是很快就会去尝试下!复制代码
- $opkg install kmod-usb-audio
- $opkg install madplay
这意味着现在我们可以通过Yún’s Bridge库,在Arduino设备里面播放声音了,按照下面这种操作方式就能实现:复制代码
- $cd /mnt/sda1
- $madplay yoursound.mp3
第五步 电子邮件脚本复制代码
- Process.runShellCommand("madplay /mnt/sda1/test.mp3");
现在,你需要把相关电子邮件设置做下改动,如下复制代码
- # coding=utf-8
- # Copyright (C) 2014 Stefano Guglielmetti
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- import smtplib, os, sys
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEBase import MIMEBase
- from email.MIMEText import MIMEText
- from email.Utils import COMMASPACE, formatdate
- from email import Encoders
- #From address, to address, subject and message body
- from_address = 'FROM_ADDRESS@EMAIL.COM'
- to_address = ['YOUR_ADDRESS@EMAIL.COM']
- email_subject = 'Alert!!! Zombies!!! Ahead!!!'
- email_body = 'A non dead intruder has been detected and needs to be eliminated!'
- # Credentials (if needed)
- username = 'EMAIL_LOGIN'
- password = 'EMAIL_PASSWORD'
- # The actual mail send
- server = 'smtp.gmail.com:587'
- def send_mail(send_from, send_to, subject, text, files=[], server="localhost"):
- assert type(send_to)==list
- assert type(files)==list
- msg = MIMEMultipart()
- msg['From'] = send_from
- msg['To'] = COMMASPACE.join(send_to)
- msg['Date'] = formatdate(localtime=True)
- msg['Subject'] = subject
- msg.attach( MIMEText(text) )
- for f in files:
- part = MIMEBase('application', "octet-stream")
- part.set_payload( open(f,"rb").read() )
- Encoders.encode_base64(part)
- part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
- msg.attach(part)
- smtp = smtplib.SMTP(server)
- smtp.starttls()
- smtp.login(username,password)
- smtp.sendmail(send_from, send_to, msg.as_string())
- smtp.close()
- send_mail(from_address, to_address, email_subject, email_body, [sys.argv[1]], server) #the first command line argument will be used as the image file name
接下来,你可以通过SFTP(或是SCP,如果你喜欢的话)把这段脚本文件上传到Arduino Yún的SD卡里,然后再次打开SSH会话,输入下面这段命令:复制代码
- #From address, to address, subject and message body
- from_address = 'FROM_ADDRESS@EMAIL.COM'
- to_address = ['YOUR_ADDRESS@EMAIL.COM']
- email_subject = 'Alert!!! Zombies!!! Ahead!!!'
- email_body = 'An undead intruder has been detected and needs to be eliminated!'
- # Credentials (if needed)
- username = 'EMAIL_LOGIN'
- password = 'EMAIL_PASSWORD'
- # The actual mail send
- server = 'smtp.gmail.com:587'
几秒钟之后,你就会收到一封电子邮件,附件就是Arduino Yún拍摄的照片,是不是很神奇!复制代码
- $cd /mnt/sda1
- $python sendemail.py test.png
十秒钟之后(校准时间),就将开始工作,并拍摄照片了!!!复制代码
- *
- * Switches a LED, takes a picture and sends it via email
- * according to the state of the sensors output pin.
- * Determines the beginning and end of continuous motion sequences.
- *
- * @author: Stefano Guglielmetti / stefano (at) mikamai (dot) com / http://jeko.net
- * @date: feb 5, 2014
- *
- * based on the example by Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at
- * http://playground.arduino.cc/Code/PIRsense
- *
- * stefano guglielmetti (cleft) 2014
- *
- * released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license
- * http://creativecommons.org/licenses/by-nc-sa/2.0/de/
- *
- *
- * The Parallax PIR Sensor is an easy to use digital infrared motion sensor module.
- * (http://www.parallax.com/detail.asp?product_id=555-28027)
- *
- * The sensor's output pin goes to HIGH if motion is present.
- * However, even if motion is present it goes to LOW from time to time,
- * which might give the impression no motion is present.
- * This program deals with this issue by ignoring LOW-phases shorter than a given time,
- * assuming continuous motion is present during these phases.
- *
- */
- #include <Bridge.h>
- /////////////////////////////
- //VARS
- //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
- int calibrationTime = 10;
- //the time when the sensor outputs a low impulse
- long unsigned int lowIn;
- //the amount of milliseconds the sensor has to be low
- //before we assume all motion has stopped
- long unsigned int pause = 5000;
- boolean lockLow = true;
- boolean takeLowTime;
- int pirPin = 6; //the digital pin connected to the PIR sensor's output
- int ledPin = 13;
- Process p;
- String imageName;
- /////////////////////////////
- //SETUP
- void setup(){
- Bridge.begin();
- Serial.begin(9600);
- pinMode(pirPin, INPUT);
- pinMode(ledPin, OUTPUT);
- digitalWrite(pirPin, LOW);
- //give the sensor some time to calibrate
- Serial.print("calibrating sensor ");
- for(int i = 0; i < calibrationTime; i++){
- Serial.print(".");
- delay(1000);
- }
- Serial.println(" done");
- Serial.println("SENSOR ACTIVE");
- delay(50);
- }
- ////////////////////////////
- //LOOP
- void loop(){
- if(digitalRead(pirPin) == HIGH){
- digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
- if(lockLow){
- //makes sure we wait for a transition to LOW before any further output is made:
- lockLow = false;
- Serial.println("---");
- Serial.print("motion detected at ");
- Serial.print(millis()/1000);
- Serial.println(" sec");
- imageName = uniqueFileName("png"); //generate a new, uniqe file name
- p.runShellCommand("fswebcam /mnt/sda1/" + imageName); //takes the picture
- while(p.running()); //wait till the process ends
- p.runShellCommand("madplay /mnt/sda1/sounds/sirena.mp3"); //play the siren sound
- while(p.running()); //wait till the process ends
- p.runShellCommand("python /mnt/sda1/sendemail.py /mnt/sda1/" + imageName); //sends the picture via email
- while(p.running()); //wait till the process ends
- delay(50);
- }
- takeLowTime = true;
- }
- if(digitalRead(pirPin) == LOW){
- digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
- if(takeLowTime){
- lowIn = millis(); //save the time of the transition from high to LOW
- takeLowTime = false; //make sure this is only done at the start of a LOW phase
- }
- //if the sensor is low for more than the given pause,
- //we assume that no more motion is going to happen
- if(!lockLow && millis() - lowIn > pause){
- //makes sure this block of code is only executed again after
- //a new motion sequence has been detected
- lockLow = true;
- Serial.print("motion ended at "); //output
- Serial.print((millis() - pause)/1000);
- Serial.println(" sec");
- delay(50);
- }
- }
- }
- /* A simple function to generate unique timestamp based filenames */
- String uniqueFileName(String ext){
- String filename = "";
- p.runShellCommand("date +%s");
- while(p.running());
- while (p.available()>0) {
- char c = p.read();
- filename += c;
- }
- filename.trim();
- filename += "." + ext;
- return filename;
- }
欢迎光临 机器人与人工智能爱好者论坛 (http://www.robot-ai.org/) | Powered by Discuz! X3.2 |