0

i am trying to create a doorbell with raspberry pi zero. When you press the doorbell pygame will play the doorbell sound, And picamera will take a picture and will send it to telegram.

At the first place it looks like it's working but after a few minutes it crash/freeze. i cannot communicate with my other computer to the pi anymore with SSH,

does anyone have idea what i am doing wrong? thanks!

what i have try: Reinstalled rasbian lite (fresh install) searching google.

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
  • `del photo` raises some eyebrows. Perhaps `photo.close()` instead? – TrebledJ Jun 14 '19 at 16:06
  • not for a duplicate, but I think you should read https://stackoverflow.com/questions/529034/python-pass-or-sleep-for-long-running-processes – B. Go Jun 14 '19 at 16:11
  • i have changed : while True: pass to this : while True: time.sleep(0.5) and now i am getting this error: python3: malloc.c:2942: __libc_malloc: Assertion `!victim || chunk_is_mmapped (mem2chunk (victim)) || ar_ptr == arena_for_chunk (mem2chunk (victim))' failed. – Jordy van den Berg Jun 14 '19 at 18:01

0 Answers0