From c49df2b81f160cae17e68d8e1a40346f0098c7f7 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Wed, 25 Mar 2026 14:59:03 +0100 Subject: [PATCH 1/2] scripts/serve: Optionally serve over https. Allows local testing on mobile devices with Bluetooth, USB, and camera suppport. --- scripts/serve.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/serve.py b/scripts/serve.py index 79f49f725..3839710f5 100755 --- a/scripts/serve.py +++ b/scripts/serve.py @@ -6,9 +6,11 @@ import http.server import pathlib -import socketserver +import ssl BUILD_DIR = (pathlib.Path(__file__).parent.parent / "build").resolve() +CERT_FILE = BUILD_DIR / "cert.pem" +KEY_FILE = BUILD_DIR / "key.pem" PORT = 8000 @@ -17,10 +19,10 @@ def __init__( self, request: bytes, client_address: tuple[str, int], - server: socketserver.BaseServer, + server: http.server.HTTPServer, directory: str | None = ... ) -> None: - super().__init__(request, client_address, server, directory=BUILD_DIR) + super().__init__(request, client_address, server, directory=str(BUILD_DIR)) def end_headers(self) -> None: # custom headers needed for some web API features @@ -29,6 +31,14 @@ def end_headers(self) -> None: return super().end_headers() -with socketserver.TCPServer(("", PORT), Handler) as httpd: - print(f"serving at http://0.0.0.0:{PORT}") - httpd.serve_forever() +httpd = http.server.HTTPServer(("", PORT), Handler) + +if CERT_FILE.exists() and KEY_FILE.exists(): + ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + ctx.load_cert_chain(certfile=CERT_FILE, keyfile=KEY_FILE) + httpd.socket = ctx.wrap_socket(httpd.socket, server_side=True) + print(f"serving at https://0.0.0.0:{PORT}") +else: + print(f"cert/key not found, serving without TLS at http://0.0.0.0:{PORT}") + +httpd.serve_forever() From ea9af98d1fd0a842ed76d3a7f83767f363bc1b17 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Fri, 27 Mar 2026 10:27:23 +0100 Subject: [PATCH 2/2] usb/sagas: Drop debug prints. We don't have these for BLE either, and it makes other debugging harder. --- src/usb/sagas.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/usb/sagas.ts b/src/usb/sagas.ts index d10d51337..6855f3e06 100644 --- a/src/usb/sagas.ts +++ b/src/usb/sagas.ts @@ -461,8 +461,6 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator { continue; } - console.debug('Received USB message:', result.data); - switch (result.data.getInt8(0)) { case PybricksUsbInEndpointMessageType.Response: yield* put( @@ -509,8 +507,6 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator { for (;;) { const action = yield* take(chan); - console.debug('Processing USB action:', action); - if (usbPybricksSubscribe.matches(action)) { const message = new DataView(new ArrayBuffer(2)); message.setUint8(0, PybricksUsbOutEndpointMessageType.Subscribe);