Untitled

 avatar
unknown
plain_text
a month ago
1.4 kB
5
Indexable
#!/usr/bin/env python3
import asyncio
import RPi.GPIO as GPIO
import os
import time
from open_gopro import WirelessGoPro, Params

# --- Konfiguration ---
BUTTON_PIN = 21
SAVE_PATH  = '/home/pi/Video'
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

async def record_and_transfer():
    async with WirelessGoPro() as gopro:
        # 1. Aufnahme starten
        await gopro.http_command.set_shutter(shutter=Params.Toggle.ENABLE)
        await asyncio.sleep(30)
        # 2. Aufnahme stoppen
        await gopro.http_command.set_shutter(shutter=Params.Toggle.DISABLE)
        # 3. Warten bis Datei finalisiert ist
        await asyncio.sleep(5)
        # 4. Letztes Medium ermitteln
        media = await gopro.http_command.get_last_captured_media()
        filename = media['media'][0]['fs'][-1]['n']
        # 5. Herunterladen
        filepath = os.path.join(SAVE_PATH, filename)
        await gopro.http_command.download_file(file=filename, path=SAVE_PATH)
        # 6. Löschen auf der Kamera
        await gopro.http_command.delete_file(file=filename)
        print(f"{time.strftime('%F %T')} → {filepath}")

def main():
    try:
        while True:
            if GPIO.input(BUTTON_PIN) == GPIO.LOW:
                asyncio.run(record_and_transfer())
                time.sleep(0.5)  # Entprellen
            time.sleep(0.1)
    finally:
        GPIO.cleanup()

if __name__ == '__main__':
    main()
Editor is loading...
Leave a Comment