Taking a picture using simulated drone Sphinx

Hi,

I am trying to take a picture using a simulated drone and save it but when I access the media link i get an empty json. What am i doing wrong?

output: Failed to fetch media. Status: 404, Response:
2025-01-19 17:53:33,401 [INFO] olympe.drone.ANAFI Ai 000000 - _disconnected_cb - Disconnected from device: ANAFI Ai 000000
2025-01-19 17:53:33,401 [INFO] olympe.drone.ANAFI Ai 000000 - _disconnection_impl - disconnected from device: b’10.202.0.1’
Drone disconnected.
2025-01-19 17:53:33,401 [INFO] olympe.drone.ANAFI Ai 000000 - disconnect - Disconnection with the device OK. IP: b’10.202.0.1’
2025-01-19 17:53:33,402 [INFO] olympe.pdraw.ANAFI Ai 000000 - _destroy_pomp_loop - Pomp loop has been destroyed: Thread-4
2025-01-19 17:53:33,403 [INFO] olympe.drone.ANAFI Ai 000000 - _on_device_removed -

code: from olympe.messages.camera import (
set_camera_mode,
set_photo_mode,
take_photo,
)
import olympe
import os
import requests
import time
import tempfile
import shutil

Drone IP and API URLs

ANAFI_IP = “10.202.0.1”
ANAFI_MEDIA_API_URL = f"http://{ANAFI_IP}/api/v1/media/medias/"

def setup_photo_mode(drone):
“”"
Configure the drone for single photo mode.
“”"
print(“Configuring photo mode…”)
drone(set_camera_mode(cam_id=0, value=“photo”)).wait()
drone(
set_photo_mode(
cam_id=0,
mode=“single”, # Single photo mode
format=“rectilinear”,
file_format=“jpeg”,
burst=“burst_14_over_1s”, # Set burst to match drone capabilities
bracketing=“preset_1ev”,
capture_interval=0.0,
)
).wait()
print(“Photo mode configured successfully.”)

def take_and_fetch_photo(drone):
“”"
Take a photo and fetch it via the media API.
“”"
print(“Taking a photo…”)
# Take a photo
drone(take_photo(cam_id=0)).wait()

# Wait for the media to be indexed
print("Waiting for media to be indexed...")
time.sleep(10)  # Increase this if media takes longer to index

# Fetch the media list
response = requests.get(ANAFI_MEDIA_API_URL)
if response.status_code == 200:
    media_list = response.json()
    if not media_list:
        print("No media found. Try increasing the indexing wait time.")
        return
    print(f"Media found: {len(media_list)} item(s).")
    download_and_save_media(media_list)
else:
    print(f"Failed to fetch media. Status: {response.status_code}, Response: {response.text}")

def download_and_save_media(media_list):
“”"
Download media from the drone and save it locally.
“”"
download_dir = tempfile.mkdtemp(prefix=“anafi_media_”)
print(f"Media will be saved to: {download_dir}")

for media in media_list:
    for resource in media["resources"]:
        resource_url = resource["url"]
        resource_id = resource["resource_id"]
        print(f"Downloading {resource_id}...")
        response = requests.get(f"http://{ANAFI_IP}{resource_url}", stream=True)
        if response.status_code == 200:
            file_path = os.path.join(download_dir, resource_id)
            with open(file_path, "wb") as file:
                shutil.copyfileobj(response.raw, file)
            print(f"Saved {resource_id} to {file_path}")
        else:
            print(f"Failed to download {resource_id}. Status: {response.status_code}")

def main():
“”"
Main function to handle drone connection, photo setup, and media capture.
“”"
drone = olympe.Drone(ANAFI_IP)
print(“Connecting to the drone…”)
drone.connect()

# Setup camera for single photo mode
setup_photo_mode(drone)

# Capture a photo and fetch media
take_and_fetch_photo(drone)

# Disconnect from the drone
drone.disconnect()
print("Drone disconnected.")

if name == “main”:
main()

Hello,

For ANAFI Ai, I recommend using Olympe’s Camera2 feature: Camera2 feature - 7.7

Here’s an example:

thank you. what should i use for DRONE_MEDIA_PORT = os.environ.get(“DRONE_MEDIA_PORT”, “80”) if I am using a simulated drone?