我正在尝试用树莓派零创建门铃。 按下门铃pygame会播放门铃声音, Picamera将拍照并发送给电报。
乍一看好像可以使用,但几分钟后它崩溃/冻结。 我无法再通过SSH与其他计算机通信到pi,
有人知道我在做什么错吗? 谢谢!
我尝试了什么: 重新安装了rasbian lite(全新安装) 搜索谷歌。
import telepot
import pygame
from picamera import PiCamera
import RPi.GPIO as GPIO
camera = PiCamera()
bot = telepot.Bot('THIS IS MY TOKEN')
ring = 'tones/Apartment-ding-dong-sound.mp3'
_chatid = -00000000
pygame.mixer.init()
pygame.mixer.music.load(ring)
bot.sendMessage(_chatid,'Hello, i am online now.')
def sendpic():
try:
camera.resolution = (1024, 768)
camera.capture('snapshots/snapshot.jpg')
photo = open('snapshots/snapshot.jpg', 'rb')
bot.sendPhoto(_chatid, photo)
del photo
except:
print('Unknow error')
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def buttonPressed(value):
if GPIO.input(22) == GPIO.LOW:
pygame.mixer.music.play()
sendpic()
GPIO.add_event_detect(22, GPIO.FALLING, callback=lambda x: buttonPressed(150), bouncetime=1000)
while True:
pass