Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ The tested Saros 10R required two-key activation: set the remote-view PIN
the two-key request bits set and monitor bit off, then press Power on the robot
within about 60 seconds. Activation varies by model.

The QX Revo Ultra 2 (a298, firmware `02.15.44`) uses the same flow, and the
server can drive it:

```bash
uv run start_local_roborock_server.py camera-activate --config config.toml
```

Dock the robot first and clear any error (`error_code` must be 0). The command
reads `camera_status` and writes the two request values — bit 5, then bit 12 —
which for an out-of-box a298 (`385`) is `417` then `4513`. Press the robot's
Power button once while it is polling. The firmware clears bit 12 and sets the
read-only monitor bit 2 itself, and `camera_status` becomes `8613`. Writing the
monitor bit directly is rejected (`-10005`), and writing the result bit
(`8611`) is rejected (`-10007`).

Activation resets when the robot is re-onboarded or its camera PIN changes, so
rerun the command after either. With the monitor bit set, `start_camera_preview`
reaches the TURN bootstrap above; a viewer that offers an audio track gets no
SDP answer on this firmware, so the offer must be video-only.

A Qrevo Master report observed `set_camera_status` values `[417]` then `[4513]`
from an initial status of `385`, followed by a robot-reported status of `8613`,
without the Saros-style physical activation. An a226 report started at `257` and
Expand Down
4 changes: 2 additions & 2 deletions docs/tested_vacuums.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ Cloudflare can provide DNS validation for several certificate issuers. Its use a
| QRevo S Pro (a326) | `02.36.38` | ❓ | ❓ | ✅ | ❓ | [#132](https://github.com/Python-roborock/local_roborock_server/issues/132) |
| QRevo S Pro (a326) | `02.49.24` | ✅ | ❓ | ✅ | ❓ | [#156](https://github.com/Python-roborock/local_roborock_server/issues/156), [#186](https://github.com/Python-roborock/local_roborock_server/issues/186) |
| QRevo Slim | `02.43.38` | ✅ | ❓ | ❓ | ❓ | [#175](https://github.com/Python-roborock/local_roborock_server/issues/175) |
| QX Revo Ultra 2 (a298) | `02.15.44` | ✅ | ✅ | ✅ | ❓ | [#193](https://github.com/Python-roborock/local_roborock_server/issues/193) |
| QX Revo Plus (Costco version) | Not reported | ❓ | ❓ | ✅ | ❓ | [#89](https://github.com/Python-roborock/local_roborock_server/pull/89) |
| QX Revo Plus (Costco version) | `02.49.24` | ✅ | ❓ | ❓ | ❓ | [#147](https://github.com/Python-roborock/local_roborock_server/issues/147) |
| QX Revo Plus (a168 as reported) | `02.27.40` | ✅ | ❓ | ❓ | ❓ | [#248](https://github.com/Python-roborock/local_roborock_server/issues/248) |
| QX Revo Ultra 2 (a298) | `02.15.44` | ❓ | ✅ | ❓ | ❓ | [#193](https://github.com/Python-roborock/local_roborock_server/issues/193) |

Setup notes:

Expand Down Expand Up @@ -181,7 +181,7 @@ Setup notes:
- QRevo S5V `02.33.88`: maps were not saved because `lab_status` was off and the LocalRock toggle was greyed out. Sending `set_lab_status` with `[{"lab_status": 1}]` from Home Assistant's `vacuum.send_command` enabled it.
- QRevo Slim: the certificate was issued through Pangolin (Traefik) and reported as ZeroSSL.
- QRevo Master: the SSL.com result used a Sectigo Public Server Authentication CA DV R36 chain and a workaround for the proxy MQTT onboarding issue in [#83](https://github.com/Python-roborock/local_roborock_server/issues/83).
- QX Revo Ultra 2: shares its model code and firmware with the QRevo Edge 2 Set. Public key recovery used header samples while query samples stayed at 0, which is expected.
- QX Revo Ultra 2 (a298): shares its model code and firmware (`02.15.44`) with the QRevo Edge 2 Set row. Onboarded with the project CLI after LocalRock's v5 auth flow returned `401 missing_authorization`. Public key recovery used `header_samples` rather than `query_samples`. Cloud-free operation was verified under a full router outbound block, and the `/f/c` rrcheck was accepted on 6 daily requests over 5 days. Live video works with the provided TURN relay and a video-only WebRTC offer; remote viewing needs the local two-key activation in [camera.md](camera.md), which `camera-activate` performs.

The [report details](compatibility_reports.md) retain the newer setup profiles,
camera qualifications, and unresolved requests behind these results.
Expand Down
14 changes: 13 additions & 1 deletion src/roborock_local_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

from .configure import run_configure
from .security import hash_password
from .server import build_arg_parser, repair_runtime_identities, run_server
from .server import (
activate_camera_command,
build_arg_parser,
repair_runtime_identities,
run_server,
)


def main() -> int:
Expand Down Expand Up @@ -58,6 +63,13 @@ def main() -> int:
if args.command == "repair-identities":
return repair_runtime_identities(config_file=Path(args.config), links=list(args.link))

if args.command == "camera-activate":
return activate_camera_command(
config_file=Path(args.config),
duid=str(args.duid),
timeout=float(args.timeout),
)

parser.error(f"Unhandled command: {args.command}")
return 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def sync_timer(
context: Any, duid: str, name: str, enabled: bool, *, check_current: Callable[[], None],
) -> str:
"""Update only the named timer; a fresh read is the success criterion, and a lost ack is read back, not resent."""
from shared.routine_runner import _RoutineMqttClient
from shared.routine_runner import RoutineMqttClient

device = context.runtime_credentials.resolve_device(duid=duid)
if device is None or not device.get("localkey"):
Expand All @@ -56,7 +56,7 @@ async def sync_timer(
write_attempted = False
try:
async with asyncio.timeout(45):
client = _RoutineMqttClient(context, device, logging.getLogger(__name__))
client = RoutineMqttClient(context, device, logging.getLogger(__name__))
await client.connect()
timer = _timer_entry(await client.send_command(TimerCommand.GET, []), name)
current = "on" if timer.enabled else "off"
Expand Down Expand Up @@ -184,14 +184,14 @@ def observe_request(self, duid: str, payload: bytes) -> None:
return

async def _client(self, duid: str, device: dict[str, Any]) -> Any:
from .routine_runner import _RoutineMqttClient
from .routine_runner import RoutineMqttClient

localkey = str(device.get("localkey") or "")
cached = self._clients.get(duid)
if cached is not None and cached[0] == localkey:
return cached[1]
await self._drop_client(duid)
client = _RoutineMqttClient(self.context, device, _LOGGER)
client = RoutineMqttClient(self.context, device, _LOGGER)
await client.connect()
self._clients[duid] = (localkey, client)
return client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _ensure_local_python_roborock_on_path() -> None:
__all__ = [
"RoutineCommand",
"RoutineExecutionError",
"RoutineMqttClient",
"RoutineRunner",
"RoutineStep",
"commands_for_step",
Expand Down Expand Up @@ -497,7 +498,7 @@ def _enum_or_int_value(value: Any) -> int:
return int(getattr(value, "value", value))


class _RoutineMqttClient:
class RoutineMqttClient:
def __init__(
self,
context: ServerContext,
Expand Down Expand Up @@ -983,7 +984,7 @@ def add_scene(candidate: dict[str, Any]) -> None:
async def _sync_scene_tids(
self,
*,
client: _RoutineMqttClient,
client: RoutineMqttClient,
scene: dict[str, Any],
device_id: str,
logger: logging.LoggerAdapter,
Expand All @@ -1008,7 +1009,7 @@ async def _stop_scene(self, *, device_id: str, scene_id: int, scene_name: str) -
},
)
logger.info("Stopping routine scene=%s device=%s", scene_name, device_id)
client = _RoutineMqttClient(self._context, device, logger)
client = RoutineMqttClient(self._context, device, logger)
await client.connect()
try:
await client.send_command(RoborockCommand.APP_STOP, [])
Expand All @@ -1018,7 +1019,7 @@ async def _stop_scene(self, *, device_id: str, scene_id: int, scene_name: str) -
async def _send_step_command(
self,
*,
client: _RoutineMqttClient,
client: RoutineMqttClient,
logger: logging.LoggerAdapter,
step: RoutineStep,
routine_command: RoutineCommand,
Expand Down Expand Up @@ -1066,7 +1067,7 @@ async def _send_step_command(
async def _send_step_commands(
self,
*,
client: _RoutineMqttClient,
client: RoutineMqttClient,
logger: logging.LoggerAdapter,
step: RoutineStep,
commands: list[RoutineCommand],
Expand Down Expand Up @@ -1116,7 +1117,7 @@ async def _run_steps(
device_id,
)

client = _RoutineMqttClient(self._context, device, logger)
client = RoutineMqttClient(self._context, device, logger)
await client.connect()
try:
if sync_scene_tids:
Expand Down
89 changes: 89 additions & 0 deletions src/roborock_local_server/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""Local two-key camera activation.

Some models (Saros 10R, QX Revo Ultra 2) do not enable live view from
``set_homesec_password`` alone. The firmware expects the remote-view app to write
``set_camera_status`` twice — first with the request bit 5, then with bit 12 — and
then a physical Power press on the robot within about a minute. The firmware
clears bit 12 and sets the read-only monitor bit 2, which authorizes
``start_camera_preview``.

Only bits 5 and 12 are added; the firmware truncates/validates anything else, and
writing bit 2 or bit 13 directly is rejected.
"""

from __future__ import annotations

import asyncio
from dataclasses import dataclass
import time
from typing import Any

from roborock.roborock_typing import RoborockCommand

#: Read-only "view authorized" bit the firmware sets after a successful press.
MONITOR_BIT = 0x4
#: First and second request bits, in the order the app writes them.
REQUEST_BITS = (0x20, 0x1000)


@dataclass(frozen=True)
class ActivationResult:
initial_status: int
final_status: int
activated: bool


def activation_writes(current_status: int) -> list[int]:
"""Return the ``set_camera_status`` values that arm the two-key request.

Each write carries the previous one forward: the firmware sees bit 5 on the
first write and bit 5 plus bit 12 on the second.
"""

status = current_status
writes: list[int] = []
for bit in REQUEST_BITS:
status |= bit
writes.append(status)
return writes


def monitor_enabled(status: int) -> bool:
"""True once the firmware has granted view authorization."""

return bool(status & MONITOR_BIT)


async def _read_camera_status(client: Any) -> int:
result = await client.send_command(RoborockCommand.GET_CAMERA_STATUS)
value = result[0] if isinstance(result, list) and result else result
return int(value)


async def activate_camera(
client: Any,
*,
timeout_seconds: float = 90.0,
poll_interval_seconds: float = 1.0,
) -> ActivationResult:
"""Arm the two-key request and wait for the monitor bit.

The caller must press Power on the robot while this is polling. Returns once
the robot reports the monitor bit or the timeout expires.
"""

initial = await _read_camera_status(client)
if monitor_enabled(initial):
return ActivationResult(initial_status=initial, final_status=initial, activated=True)

for value in activation_writes(initial):
await client.send_command(RoborockCommand.SET_CAMERA_STATUS, [value])

deadline = time.monotonic() + timeout_seconds
while True:
status = await _read_camera_status(client)
if monitor_enabled(status):
return ActivationResult(initial_status=initial, final_status=status, activated=True)
if time.monotonic() >= deadline:
return ActivationResult(initial_status=initial, final_status=status, activated=False)
await asyncio.sleep(poll_interval_seconds)
Loading