Picam + Pir --->电子邮件图片

时间:2019-03-26 19:46:26

标签: python raspberry-pi3

我是python的新手,我正在制作要在车道上使用的Motion触发Picam。应该发送给我一封包含拍摄照片的电子邮件。

我已启动并运行代码,我只是想不出如何放置此代码,(这只是我测试过的一个示例)

mpack -s“测试” / home / pi / Desktop / motions \ cam / 2019-03-24_20.07.40_picture.jpg someone1234@gmail.com

首先,我尝试使用MMS-在丹麦使用twilio非常昂贵 因此,电子邮件

代码如下:

from picamera import PiCamera
from time import sleep
from gpiozero import MotionSensor
from datetime import datetime


camera = PiCamera()
pir = MotionSensor(4)
#camera.rotation = 180
camera.resolution = (640,480)
camera.start_preview()


print("Online!")


while True:

    pir.wait_for_motion()    
    print("Motion detected!")

    sleep(0)
    # create time stamp
    now = (datetime.now())
    tstamp = "{0:%Y}-{0:%m}-{0:%d}_{0:%H}.{0:%M}.{0:%S}".format(now)

    #create file name with tstamp
    #filename = tstamp + "_Picam.h264" #video
    filename = tstamp + "_picture.jpg"


    print (filename)
    #camera.start_recording(filename) #video
    #camera.wait_recording(15)
    camera.capture(filename)
    sleep(5)
    pir.wait_for_no_motion()
    print("Motion ended!")
    #camera.stop_recording()
    camera.stop_preview()

0 个答案:

没有答案