import random import time, datetime import os import json from open_gopro import GoPro, params # This seems to handle cases where the GoPro's failed to disconnect on previous runs. os.system("bluetoothctl power off") os.system("bluetoothctl power on") config = open('config.json') config = json.load(config) # The config file looks like this: [ {"id": "1000", "ble_mac": "FF:3E:A4:XX:XX:XX", "name": "GoPro 1"}, {"id": "1001", "ble_mac": "F2:B5:DF:XX:XX:XX", "name": "GoPro 2"}, {"id": "1002", "ble_mac": "FD:09:71:XX:XX:XX", "name": "GoPro 3"}, ] gopros = [] def connect(): for obj in config: try: tmp = GoPro(obj["id"]) tmp.establish_ble(obj["ble_mac"]) tmp.discover_chars() tmp.initialize() tmp.camera_id = obj["id"] tmp.camera_name = obj["name"] gopros.append(tmp) print("Connected to camera name", obj["name"]) except: print("Problems connecting to camera", obj['name']) def start_recording(): for gopro in gopros: assert gopro.ble_command.set_shutter(params.Shutter.OFF).is_ok assert gopro.ble_command.set_turbo_mode(False).is_ok assert gopro.ble_command.load_preset(params.Preset.CINEMATIC).is_ok assert gopro.ble_command.set_shutter(params.Shutter.ON).is_ok print(datetime.datetime.now(), ", Started recording on camera id", gopro.camera_id) def stop_recording(): for gopro in gopros: assert gopro.ble_command.set_shutter(params.Shutter.OFF).is_ok print(datetime.datetime.now(), ", Stopped recording on camera id", gopro.camera_id) connect() while True: start_recording() time.sleep(5) stop_recording() time.sleep(60*10) for gopro in gopros: gopro.terminate_ble()