import requests, json, time

from config import MISTY_IP
ROBOT_IP = MISTY_IP
PORT = 1936

def post(path, payload=None):
    url = f"http://{ROBOT_IP}{path}"
    r = requests.post(url, data=json.dumps(payload or {}),
                      headers={"Content-Type": "application/json"},
                      timeout=10)
    print(f"{path} -> {r.status_code}")
    try:
        print(r.json())
    except Exception:
        print(r.text)
    return r

print("🔌 Enable AV streaming service...")
post("/api/services/avstreaming/enable", {})

print("📡 Start AV streaming (Misty as RTSP server)...")
post("/api/avstreaming/start", {
    "url": f"rtspd:{PORT}",
    "width": 640,
    "height": 480,
    "frameRate": 30,
    "videoBitRate": 5000000,
    "audioBitRate": 128000,
    "audioSampleRateHz": 44100,
    "userName": None,
    "password": None
})

print("⏳ Warte 2 Sekunden bis der RTSP-Server steht...")
time.sleep(2)

print(f"✅ Jetzt sollte gehen: rtsp://{ROBOT_IP}:{PORT}")
