From 916df7918439994e5d549bafc01cbffe9d64ad08 Mon Sep 17 00:00:00 2001 From: Maarten Veenstra Date: Mon, 19 Oct 2026 16:40:09 +0200 Subject: [PATCH] Add S7 MaxV camera preflight with normal region settings --- docs/camera.md | 38 ++++++++++++++++++- docs/tested_vacuums.md | 1 + onboarding_shared.py | 8 ++-- .../https_server/routes/fw/createca.py | 2 +- start_onboarding.py | 10 ++++- tests/test_onboarding_cli.py | 33 ++++++++++++++++ tests/test_onboarding_preflight.py | 24 +++++++++++- 7 files changed, 107 insertions(+), 9 deletions(-) diff --git a/docs/camera.md b/docs/camera.md index 737ff75d..fac496ad 100644 --- a/docs/camera.md +++ b/docs/camera.md @@ -9,7 +9,9 @@ Camera bootstrap, authentication and TURN all need to work. Bootstrap depends on firmware. The tested Saros 10R (`roborock.vacuum.a144`, FCC/US firmware) uses the onboarding region (`country_domain`). Qrevo MaxV (`roborock.vacuum.a87`) was observed using `token.r`, including its explicit -port, even when a separate camera domain was supplied. +port, even when a separate camera domain was supplied. S7 MaxV +(`roborock.vacuum.a27`, firmware `02.59.36`) streamed with a short `token.r` +on port 443 while retaining the normal `eu` country domain. Firmware truncates the input to 15 characters and appends `iot.roborock.com`. The input used by that firmware needs a trailing `/` and must fit in **15 characters total**, @@ -21,7 +23,7 @@ For example, onboarding server `api-vac.cc:555` produces `token.r = vac.cc:555/` Camera domain `api-vac.cc` produces `country_domain = api-vac.cc/`. Qrevo requires DNS, trusted TLS and routing for `vac.cc:555`; Saros requires `api-vac.cc:443`. Explicit ports are retained; inputs without a port use 443. -After device selection, onboarding checks the observed input for a87 and a144. +After device selection, onboarding checks the observed input for a27, a87 and a144. For an unknown model or a new vacuum whose model is not known yet, it checks both inputs conservatively; configure both endpoints or first identify the model. The initial configuration check only tests the API and MQTT listeners. Camera @@ -30,6 +32,23 @@ for the admin connection. A Saros can use a short camera domain with a longer API/token hostname; a Qrevo with an explicit token port does not require a separate camera-domain listener on 443. +For a model using `token.r`, pass `--camera` to enable camera preflight without +changing its normal country domain. For example, the tested S7 MaxV used the +equivalent of: + +```sh +uv run start_onboarding.py --server https://api-vac.cc:443 --camera --country-domain eu +``` + +This sends `token.r = vac.cc/` and keeps `country_domain = eu`. Both +`api-vac.cc:443` and `vac.cc:443` need trusted TLS and routing to the server. +Use the appropriate normal region for your robot; `eu` is the tested region, +not a requirement for all S7 MaxV units. Changing the server address requires +another Wi-Fi pairing cycle. A recovered public key can be reused. +The `--camera-domain` option still sets `country_domain` for firmware that +uses that field for bootstrap, and continues to enable preflight automatically. +Ordinary pairing without either camera option does not require TURN. + Preflight also POSTs to the bootstrap route and checks that its advertised TURN endpoint matches server status. An older server without TURN status is rejected with update guidance. A trusted certificate for the wrong proxy service is not @@ -130,6 +149,12 @@ within about 60 seconds. Activation varies by model. - No bootstrap request: check DNS, trusted TLS, the trailing slash, length limits and routing from the robot's network for both inputs. - Preview rejected: check the existing PIN and the model's activation flow. +- S7 MaxV (`roborock.vacuum.a27`, firmware `02.59.36`): preview while charging + returned `-10011` (`robot in charge, denied preview`), even after + `check_homesec_password` accepted the existing PIN. Move the robot off the + dock before testing preview. A subsequent `-10014` (`request turnserver failed`) + was resolved by running a camera-capable server with provided TURN and + re-pairing with a short `token.r` on port 443, leaving `country_domain = eu`. - Bootstrap succeeds without frames: check authenticated TURN allocation, UDP mappings, firewall rules and the advertised address. @@ -137,3 +162,12 @@ Saros 10R completed a WebRTC handshake with coturn and go2rtc received frames. Qrevo MaxV completed a forced-relay preview with frames after configuring the `token.r` hostname and its explicit port. These observations do not establish identical bootstrap or activation behavior on other firmware. + +S7 MaxV (`a27`, `02.59.36`) delivered H.264 video at 640×480 using go2rtc +1.9.14 after the setup above, with the robot's Internet access blocked at the +router. The existing remote-view PIN was accepted; no new activation sequence +was needed. The server used a provided RSA-2048 Let's Encrypt certificate +covering both the API and bootstrap hostnames. Audio and remote driving were +not tested. A second go2rtc build with Pion's `ICETransportPolicyRelay` forced +for the Roborock connection decoded 240 frames over 20 seconds through the +local coturn relay, with no decoder errors reported during that sample. diff --git a/docs/tested_vacuums.md b/docs/tested_vacuums.md index ea01e3eb..72090f29 100644 --- a/docs/tested_vacuums.md +++ b/docs/tested_vacuums.md @@ -94,6 +94,7 @@ Cloudflare can provide DNS validation for several certificate issuers. Its use a Setup notes: - S6 MaxV: initial LocalRock and Home Assistant controls worked, but the reporter noted intermittent connectivity shortly after onboarding and had not tested it long term. +- S7 MaxV `02.59.36`: local video and a forced-relay stream worked with the robot's Internet access blocked, a provided RSA-2048 Let's Encrypt certificate, a short `token.r` on HTTPS port 443 and the normal `eu` region. Preview was rejected while charging. See [Camera](camera.md) for the tested setup and limitations. - S7 Pro Ultra: the Actalis success used an RSA-2048 certificate. The Let's Encrypt failure was reported with an R3/E1 chain. - Saros 10: the reporter blocked the vacuum's Internet access to complete onboarding and kept it blocked afterward. Camera preview did not work. - Saros 10R `02.50.56`: the reported pfSense/HAProxy setup used provided certificates and the MITM redirect fix in [PR #77](https://github.com/Python-roborock/local_roborock_server/pull/77). diff --git a/onboarding_shared.py b/onboarding_shared.py index d96616ac..af3fbddf 100644 --- a/onboarding_shared.py +++ b/onboarding_shared.py @@ -81,10 +81,10 @@ def perform_onboarding_preflight( def perform_camera_preflight(*, api: Any, stack_server: str, country_domain: str, - model: str, output: TextIO) -> None: + model: str, output: TextIO, camera_enabled: bool = False) -> None: # Defer firmware-specific checks until a device is selected. Ordinary pairing # may coexist with TURN configured for another robot. - if "/" not in country_domain: + if not camera_enabled and "/" not in country_domain: return status = api.get_status() services = _service_map_from_status(status) @@ -93,7 +93,7 @@ def perform_camera_preflight(*, api: Any, stack_server: str, country_domain: str turn = status["turn"] if turn.get("mode") == "disabled": raise RuntimeError("Camera preflight failed: TURN is disabled. Configure provided or external mode first.") - # Firmware varies: Saros uses country_domain, Qrevo a87 uses token.r. + # Firmware varies: Saros uses country_domain; S7 MaxV and Qrevo a87 use token.r. endpoints = camera_bootstrap_endpoints(stack_server=stack_server, country_domain=country_domain, model=model) for host, port in endpoints: label = f"https://{host}:{port}/iot.roborock.com/fwapi/createca" @@ -121,7 +121,7 @@ def camera_bootstrap_endpoints(*, stack_server: str, country_domain: str, model: """Check the observed firmware input; unknown models conservatively need both.""" endpoints: list[tuple[str, int]] = [] inputs = [("token.r", stack_server), ("country_domain", country_domain)] - if model == "roborock.vacuum.a87": + if model in {"roborock.vacuum.a27", "roborock.vacuum.a87"}: inputs = inputs[:1] elif model == "roborock.vacuum.a144": inputs = inputs[1:] diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/fw/createca.py b/src/roborock_local_server/bundled_backend/https_server/routes/fw/createca.py index 12a120f8..90574bf0 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/fw/createca.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/fw/createca.py @@ -8,7 +8,7 @@ including its explicit port. A short input with a trailing ``/`` resolves it to this server (see docs/camera.md). Until this route existed the request fell through to the catchall, the robot got no TURN config, and -``start_camera_preview`` returned ``-10012 / request turnserver failed`` with the +``start_camera_preview`` returned ``-10014 / request turnserver failed`` with the app showing an instant timeout. This route answers with a TURN/STUN server operated alongside the stack (for diff --git a/start_onboarding.py b/start_onboarding.py index 80fb4f14..03a21408 100644 --- a/start_onboarding.py +++ b/start_onboarding.py @@ -299,6 +299,7 @@ class GuidedOnboardingConfig: cst: str country_domain: str allow_insecure_tls: bool = False + camera_enabled: bool = False class ApiReachabilityError(RuntimeError): @@ -437,6 +438,11 @@ def build_parser() -> argparse.ArgumentParser: parser.add_argument("--timezone", default="") parser.add_argument("--cst", default="") parser.add_argument("--country-domain", default="") + parser.add_argument( + "--camera", + action="store_true", + help="Check camera bootstrap and TURN before pairing, without changing the country domain.", + ) parser.add_argument( "--camera-domain", default="", @@ -494,6 +500,7 @@ def prompt_for_config(args: argparse.Namespace, output: TextIO = sys.stdout) -> cst=cst, country_domain=country_domain, allow_insecure_tls=bool(args.allow_insecure_tls), + camera_enabled=bool(getattr(args, "camera", False)), ) @@ -695,7 +702,8 @@ def run_guided_onboarding( try: perform_camera_preflight(api=api, stack_server=config.stack_server, country_domain=config.country_domain, - model=str(selected.get("model") or ""), output=output) + model=str(selected.get("model") or ""), output=output, + camera_enabled=config.camera_enabled) except (RuntimeError, ValueError) as exc: output.write(f"Camera preflight failed: {exc}\nChoose another vacuum or quit to edit the settings.\n") continue diff --git a/tests/test_onboarding_cli.py b/tests/test_onboarding_cli.py index 05e43723..1e930be1 100644 --- a/tests/test_onboarding_cli.py +++ b/tests/test_onboarding_cli.py @@ -1,6 +1,7 @@ from __future__ import annotations import argparse +from dataclasses import replace from io import StringIO import pytest @@ -10,6 +11,7 @@ ApiReachabilityError, GuidedOnboardingConfig, RemoteOnboardingApi, + build_parser, choose_device, country_from_iana, normalize_api_base_url, @@ -21,6 +23,37 @@ ) +def test_camera_flag_preserves_normal_country_domain() -> None: + args = build_parser().parse_args([ + "--server", "https://api-vac.cc:443", "--admin-password", "admin", + "--ssid", "test", "--password", "wifi", "--timezone", "Europe/Amsterdam", + "--camera", "--country-domain", "eu", + ]) + config = prompt_for_config(args) + assert config.camera_enabled is True + assert config.country_domain == "eu" + assert config.stack_server == "vac.cc/" + + +def test_camera_flag_blocks_pairing_when_turn_is_disabled(monkeypatch, config): + config = replace(config, camera_enabled=True, country_domain="eu", stack_server="vac.cc/") + api = FakeApi(devices=[{ + "duid": "s7", "name": "S7 MaxV", "model": "roborock.vacuum.a27", + }], baseline_statuses=[]) + api.get_status = lambda: {"turn": {"mode": "disabled"}, "health": {"services": []}} + answers = iter(["1", "quit"]) + monkeypatch.setattr("builtins.input", lambda prompt="": next(answers)) + output = StringIO() + sent = [] + assert run_guided_onboarding( + config=config, api=api, output=output, + send_onboarding=lambda *args: sent.append(args), + ) == 0 + assert "TURN is disabled" in output.getvalue() + assert api.started_duids == [] + assert sent == [] + + class FakeApi: def __init__(self, *, devices: list[dict], baseline_statuses: list[dict]) -> None: diff --git a/tests/test_onboarding_preflight.py b/tests/test_onboarding_preflight.py index 1ff17dbc..5ef8f56c 100644 --- a/tests/test_onboarding_preflight.py +++ b/tests/test_onboarding_preflight.py @@ -81,18 +81,40 @@ def test_initial_configuration_defers_camera_checks_until_device_selection(monke @pytest.mark.parametrize(("model", "token", "country", "endpoint"), [ ("roborock.vacuum.a144", "roborock.example.com:555/", "api-vac.cc/", ("api-vac.cc", 443)), ("roborock.vacuum.a87", "vac.cc:556/", "api-vac.cc/", ("vac.cc", 556)), + ("roborock.vacuum.a27", "vac.cc/", "eu", ("vac.cc", 443)), ]) def test_selected_model_only_requires_observed_camera_endpoint(monkeypatch, model, token, country, endpoint): calls = [] monkeypatch.setattr(onboarding_shared, "_probe_tls_endpoint", lambda **kw: calls.append(kw)) onboarding_shared.perform_camera_preflight( api=_FakeApi(_camera_status()), stack_server=token, country_domain=country, - model=model, output=StringIO(), + model=model, output=StringIO(), camera_enabled=True, ) assert [(c["host"], c["port"]) for c in calls] == [endpoint] assert calls[0]["allow_insecure_tls"] is False +def test_s7_camera_preflight_rejects_long_token_with_normal_region(monkeypatch): + calls = [] + monkeypatch.setattr(onboarding_shared, "_probe_tls_endpoint", lambda **kw: calls.append(kw)) + with pytest.raises(ValueError, match="Camera token.r.*15 characters"): + onboarding_shared.perform_camera_preflight( + api=_FakeApi(_camera_status()), stack_server="vacuum.example.com:555/", + country_domain="eu", model="roborock.vacuum.a27", output=StringIO(), + camera_enabled=True, + ) + assert calls == [] + + +def test_s7_ordinary_pairing_does_not_require_camera_support(): + api = _FakeApi({}) + onboarding_shared.perform_camera_preflight( + api=api, stack_server="vacuum.example.com:555/", country_domain="eu", + model="roborock.vacuum.a27", output=StringIO(), + ) + assert api.status_calls == 0 + + @pytest.mark.parametrize("value", ["vac.cc:555", "too-long.example:555/", "123456789012345"]) def test_camera_token_requires_slash_and_15_character_limit(value) -> None: with pytest.raises(ValueError, match="Camera token.r.*15 characters"):