import requests
import json
import time

ROBOT_IP = "192.168.68.64"
PORT = 1936

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

# 1) Enable AV streaming service
post("/api/services/avstreaming/enable", {})

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

print(f"\nJetzt in VLC öffnen: rtsp://{ROBOT_IP}:{PORT}\n")
time.sleep(999999)
