camara seguridad con telegram mejorar codigo
Publicado por roberto (1 intervención) el 07/05/2021 20:59:27
Me puede ayudar alguien,he encontrado este codigo en github y funciona, el problema es que los vídeos que grabo ademas de mandarlos a la aplicación se guardan en la memoria, y me ocupan espacio innecesario ya que los tengo en telegram.
Seria añadir una linea para que no se graben en la memoria estoy empezando y estoy muy verde gracias
Seria añadir una linea para que no se graben en la memoria estoy empezando y estoy muy verde gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import telepot
from picamera import PiCamera
import RPi.GPIO as GPIO
import time
from time import sleep
import datetime
from telepot.loop import MessageLoop
from subprocess import call
PIR = 4
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 25
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR, GPIO.IN)
motion = 0
motionNew = 0
def handle(msg):
global telegramText
global chat_id
chat_id = msg['chat']['id']
telegramText = msg['text']
print('Message received from ' + str(chat_id))
if telegramText == '/start':
bot.sendMessage(chat_id, 'Sistema activado.')#cambia el mensaje que desees
while True:
main()
bot = telepot.Bot('xxxxxxxxxxxxx')
bot.message_loop(handle)
def main():
global chat_id
global motion
global motionNew
if GPIO.input(PIR) == 1:
print("Objeto Detectado")
motion = 1
if motionNew != motion:
motionNew = motion
sendNotification(motion)
elif GPIO.input(PIR) == 0:
print("Sin Novedad")
motion = 0
if motionNew != motion:
motionNew = motion
def sendNotification(motion):
global chat_id
if motion == 1:
filename = "./video_" + (time.strftime("%y%b%d_%H%M%S"))
camera.start_recording(filename + ".h264")
sleep(5)
camera.stop_recording()
command = "MP4Box -add " + filename + '.h264' + " " + filename + '.mp4'
print(command)
call([command], shell=True)
bot.sendVideo(chat_id, video = open(filename + '.mp4', 'rb'))
bot.sendMessage(chat_id, 'The motion sensor is triggered!')
while 1:
time.sleep(10)
Valora esta pregunta


0