Hallo zusammen,
ich habe mich lange nicht mehr hier gemeldet, weil es auch gut lief.
Durch den Wechsel von "ich schalte den Stream erst an" zu ich Streame immer und überwache das mit dem Watchdog, konnte ich das Programm etwas vereinfachen und es hat wirklich gut funktioniert. Leider hat mein alter RPi, den ich benutzte dafür, den Geist aufgegeben.
Hab jetzt einen RPi 3+ und leider funktioniert das Programm nicht mehr.
Ich bekomme einen Fehler
Code: Alles auswählen
Aufnahme start
/home/pi/cam/20190714_204746.mkv
['ffmpeg', '-i', 'http://192.168.100.130:9000/?action=stream', '-f', 'image2', '-r', '1/5', '-frame_pts', '1', '/home/pi/cam/%d.jpg', '-vcodec', 'copy', '-an', '-bufsize', '2048k', '-t', '00:00:30', '-y', '/home/pi/cam/20190714_204746.mkv']
Traceback (most recent call last):
File "ring.py", line 90, in <module>
main()
File "ring.py", line 85, in main
record(ring_count)
File "ring.py", line 66, in record
record = subprocess.Popen(VIDEO_RECORD_COMMAND + [videoname] )
File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Das Verzeichnis cam existiert mit 775 Rechten ...
Danke schon mal für die Hilfe, warum die Fehlermeldung plötzlich beim neuen RPi kommt ..
Hier noch der Programm code:
Code: Alles auswählen
#!/usr/bin/env python
#coding: utf8
import time
import os
import subprocess
import datetime
from itertools import count
import requests
import RPi.GPIO as gpio
import glob
#import psutil
DEVELOPERMODE = True
# PIN festlegen an dem das Signal kommt
OPTOKOPPLER = 18
RELAIS = 11
gpio.setwarnings(False)
#Telegram konfiguration
TELEGRAM_URL ="https://api.telegram.org/bot"
BOT_TOKEN = "7ichbindertokencode"
B_ID = "123456789"
A_ID = "123456788"
CHAT_IDS = [A_ID, B_ID]
BASE_PATH = '/home/pi/cam/'
VIDEO_RECORD_COMMAND = ['ffmpeg',
'-i', "http://192.168.100.130:9000/?action=stream",
'-f', 'image2', '-r', '1/5', '-frame_pts', '1', '/home/pi/cam/%d.jpg',
'-vcodec', 'copy', '-an', '-bufsize', '2048k', '-t', '00:00:30', '-y']
def send_message(chatroomids, message=None, photo=None):
files = {}
for id in chatroomids:
params = {"chat_id": id}
if message:
params["text"] = message
cmd = "sendMessage"
if photo:
files = {"photo": photo}
cmd = "sendPhoto"
url = "{}{}/{}".format(TELEGRAM_URL, BOT_TOKEN, cmd)
r = requests.get(url, params=params, files=files)
result = r.json()
print(result)
def setup():
# Pin optokopller als Eingang, relais als Ausgang festlegen
gpio.setwarnings(False)
gpio.setmode(gpio.BOARD)
gpio.setup(OPTOKOPPLER, gpio.IN, pull_up_down = gpio.PUD_UP)
gpio.setup(RELAIS, gpio.OUT)
# Klingelrelais generell anschalten
gpio.output(RELAIS, gpio.HIGH)
def record(ring_count):
videoname = os.path.join(BASE_PATH, "{:%Y%m%d_%H%M%S}.mkv".format(datetime.datetime.now()))
print("Aufnahme start")
print(videoname)
print(VIDEO_RECORD_COMMAND + [videoname])
record = subprocess.Popen(VIDEO_RECORD_COMMAND + [videoname] )
time.sleep(31)
record.terminate()
record.wait()
print("Aufzeichnung beendet")
message = "Es hat gerade das {}. mal geklingelt.".format(ring_count)
send_message(CHAT_IDS, message=message)
for filename in sorted(glob.glob(os.path.join(BASE_PATH, '*.jpg'))):
with open(filename, 'rb') as data:
photo = data.read()
send_message(CHAT_IDS, photo=photo)
time.sleep(1)
os.unlink(filename)
def main():
try:
setup()
for ring_count in count(start=1):
if DEVELOPERMODE or gpio.wait_for_edge((OPTOKOPPLER), gpio.FALLING):
record(ring_count)
finally:
gpio.cleanup()
if __name__ == '__main__':
main()