EspHub provisions ESP32 devices over USB and manages them through the web and MCP. This repository owns the Hub services. Board firmware lives in esphub-firmware.
| Host | Component |
|---|---|
| esphub.ai and www.esphub.ai | Website Worker, landing and setup |
| app.esphub.ai | Same website Worker, authenticated device console |
| api.esphub.ai | Hono Worker, MQTT uplink processing and authenticated API |
| cdn.esphub.ai | Board photos from R2, resized and cached at the Cloudflare edge |
| api.esphub.ai/mcp | Streamable HTTP JSON-RPC using Clerk OAuth |
Use boards_search to find a board and its examples. Each entry includes a capability description, the upstream reference, a revision-pinned source URL, an entrypoint and a build command.
A first install writes three parts:
- Bootloader set. Boards with the same bootloader ID (for example
esp32s3-16mb) share one set: the ESP-IDF second-stagebootloader.bin,partition-table.binand the EspHub Launcher. The publisher records each version inesphub.bootloaders, andGET /bootloaders/<id>/<version>/<bootloader|partition-table|launcher>serves the files with immutable caching. - App. The board's default example, built as one
app.binand served fromGET /releases/<board>/app. - Private NVS image. The Hub generates it per device with the Hub hostname, the device token, the BLE key and the Wi-Fi network. It is downloadable for 15 minutes with its bearer header.
Ask the user for the Wi-Fi SSID and password, connect the board over USB and call devices_create with wifi. The response's flash object lists every file with its offset, URL and sha256 (the NVS entry also carries its headers and expires_at), and the matching esptool command. Install esptool with pip install esptool, download and verify the files, then run the command, for example:
esptool.py --chip esp32s3 --port PORT write_flash --erase-all --flash_mode dio --flash_size 16MB --flash_freq 80m 0x0 bootloader.bin 0x8000 partition-table.bin 0x9000 nvs.bin 0x20000 launcher.bin 0x2a0000 app.binThe board starts in the EspHub Bootloader and connects. Call bootloader_exit, type app on USB, or power-cycle the board to start the application. Confirm that devices_get reports an online app and flash.app_version, and check the behavior described in setup_example.description. POST /setup does the same for the web console, and POST /setup/<device>/reissue rotates the device credentials and returns a fresh plan.
From the signed-in EspHub workspace, select Bind my ESP32 and paste the prompt into your coding agent. The agent can guide board registration, USB setup and Wi-Fi, then confirm the device is online. Use Manage devices to open the management prompt.
The bootloader also accepts these newline-terminated JSON commands over USB at 115200 baud. Each response begins with EH-WIFI followed by JSON.
EH-WIFI {"op":"wifi.scan"}
EH-WIFI {"op":"wifi.join","ssid":"My network","password":"<password>","hidden":false}
EH-WIFI {"op":"wifi.status"}
For an open network, use an empty password. A join is saved after the device gets an IP address. For direct USB console access, wifi add <ssid> [password] [hidden] saves a network immediately. Use the JSON commands for credentials containing spaces. BLE also supports offline setup. On an online device, use wifi_add with an SSID and optional password to save a network remotely. Read commands_get for the result.
The first-install NVS image and an explicit bootloader entry set a one-shot hold flag. The bootloader consumes it and stays available for that boot. On the next power cycle it starts a valid app, or stays available if the app is missing or invalid. A Hub hello only reports the session.
On ordinary boots, applications use the saved Wi-Fi networks and can initialize their own Bluetooth stack immediately. The bootloader advertises the EspHub provisioning service whenever it is running with a BLE bootstrap key, including when Wi-Fi is already configured. For offline recovery, expose an application menu item or startup key that calls eh_enter_bootloader() from the SDK.
Applications with their own Wi-Fi settings screen can call eh_wifi_join() and poll eh_wifi_join_state(). The station saves credentials after obtaining an IP address.
Call devices_create_virtual from an authorized MCP client. Each account can create one private esphub/virtual-esp32 board. Creating it again returns the same device ID.
- Call
devices_listand select the device withkind: "virtual". Use its ID withfirmware_getto inspect the simulated firmware and currentprocess_id. - Call
devices_rebootwith that device ID. The response contains the new boot’sprocess_id. Supply a UUID asrequest_idon the first call and reuse it for retries. - Use
devices_getto confirm the new boot ID.
- Use
bootloader_enterand wait fordevices_getto show an online device in the bootloader role. - Call
ota_installwith kindapporbootloader. Omiturlto install the board’s published image. For custom firmware, pass an HTTPS URL or upload the image as described below. - Follow the receipt with
commands_get. Confirm the new process ID and the application version indevices_getafter reboot.
The EspHub Bootloader checks TLS, the image header and chip, and checks its own variant when updating a bootloader. A bootloader update writes the inactive bootloader slot. An application update writes the single application slot. An interrupted application write can be retried in Bootloader mode. Firmware that crashes after a valid boot can require USB recovery.
Use setup_example for the sources of a newly installed app. For another example use boards_search or devices_get, pick an entry by description, check out the revision in its source_url and edit its entrypoint. Run its build_command from the firmware repository root. The build guide describes the toolchain. Use kind app for the resulting image.
A local build, a downloaded release or a file supplied by the user can all be installed. The build machine needs no GitHub account. If you already have a direct HTTPS download URL accessible to the device, skip the upload step.
-
Call
ota_prepare_uploadwithdevice_id,kindand the file's exactsizein bytes. The device can be offline. This requiresdevices:write. -
PUT the raw file to
upload_urlusing the returnedheaders.Authorization. For example, with the response saved privately asgrant.jsonand the file path inFILE:curl --fail-with-body --request PUT --upload-file "$FILE" \ --header "Authorization: $(jq -r '.headers.Authorization' grant.json)" \ "$(jq -r '.upload_url' grant.json)"
HTTP 201 confirms the bytes are in private R2 storage. The write credential is valid for 15 minutes and can create one object. The device's download URL is valid for 24 hours. App uploads accept up to 32 MiB and bootloader uploads up to 4 MiB. The binary must also fit the board's target partition.
-
Call
bootloader_enterand wait for Bootloader mode. Pass the upload response'surl(or an existing direct download URL),kindanddevice_idtoota_install. Follow the transfer receipt and next boot to verify installation.
Enter Launcher mode and read info.layout from the device’s current boot. Call ota_resize_app with the device ID, app_size_bytes (a multiple of 65536) and erase_littlefs: true to move the boundary in either direction. This erases all LittleFS files, retains the installed app and provisioning, and reboots into the Launcher. Repeating the current size preserves files. If the current image is too large to shrink, install a smaller app first. Follow the command receipt until the next boot confirms the requested capacities, then install the image. If power is interrupted while rewriting the primary table, recovery may require USB. EspHub supplies the image size for private uploads and official releases. For other HTTPS sources, pass image_size_bytes at installation when known. If the source has an unknown length and the stream exceeds the slot, the receipt gives the minimum image size, the current slot, and the maximum supported slot.
Browser sign-in and sign-up use the Clerk production Account Portal at accounts.esphub.ai. Clerk manages sessions across the esphub.ai root domain. The API checks the token signature against clerk.esphub.ai, issuer, expiry and an exact allowed browser origin before mapping a Clerk user ID to a Neon account. The website forwards same-origin requests through its API Worker binding. Connect a remote MCP client from the Devices page and sign in through Clerk. MCP accepts audience-bound OAuth access tokens for https://api.esphub.ai/mcp. Clients request both devices:read and devices:write by default. Read access covers device and firmware information, saved Wi-Fi networks and boot metadata. Active Wi-Fi scans, device or network changes, firmware installation also require devices:write. Existing read-only grants must obtain user consent before a write. Clerk handles consent, token issuance and renewal. A device token cannot access operator tools.
In the EspHub production Clerk instance, register https://api.esphub.ai/mcp under Agents → MCP servers and allow public clients to connect with CIMD. In OAuth applications → Settings, enable Publish CIMD support and leave Publish DCR support off. Use a client version that supports Client ID Metadata Documents (CIMD). Under OAuth applications, create and advertise devices:read and devices:write. Select both devices:read and devices:write in the default and allowed scopes for dynamic clients. Clerk uses offline_access for token refresh. Use the instance's secret key for the API Worker.
Neon stores registrations, device-token hashes, boot metadata and the command queue. Each device’s Durable Object serializes incoming MQTT reports and records structured events in R2.
Install dependencies with npm ci. After npm run migrate, seed a fresh local database and local R2 with the test board catalog and photos using node scripts/seed-catalog.mjs. npm run build bundles the browser code. npm test runs unit tests, and TEST_DATABASE_URL enables the PostgreSQL tests. npm run migrate takes MIGRATION_DATABASE_URL and serializes checksum-verified migrations under an advisory lock.
Pushes to main run verification on an ephemeral PostgreSQL instance, migrate production Neon, deploy the Hono API then the website, and check public domains and authentication boundaries. Required repository secrets are CLERK_SECRET_KEY (EspHub production instance), MIGRATION_DATABASE_URL, RUNTIME_DB_PASSWORD (64 lowercase hex characters), CLOUDFLARE_API_TOKEN, IOT_RELAY_SECRET (at least 32 characters), IOT_ACCESS_KEY_ID and IOT_SECRET_ACCESS_KEY. CLOUDFLARE_ACCOUNT_ID, IOT_ACCOUNT_ID and IOT_DATA_ENDPOINT are repository variables. The API Worker stores uploads and logs in the esphub-production R2 bucket and reads releases and board photos from the esphub-firmware bucket. Both buckets must exist before the first deploy. The migration role creates a restricted runtime role; the API Worker receives the runtime database URL and the Clerk credential. Configure the production environment to suit the organization's deployment policy.
Firmware builds, SDK version automation and release publication live in esphub-firmware. The firmware repository publishes board profiles, example and source links, and an index of every published release file to Neon. The Hub serves the directory and downloads from these records and R2, without contacting GitHub or deriving release names. GET /boards and the read-only MCP tool boards_search use the same directory. A query such as {"query":"paper"} matches the literal substring in board IDs. Each result includes its R2 photo and the latest published version and pinned download URL for each available firmware kind. Board photos are committed to esphub-firmware, which publishes them to boards/<group>/<project>.webp in the esphub-firmware bucket. The website loads GET /boards/gallery, which joins current boards and their manufacturer product links with the available R2 photos. Set a manufacturer link in esphub.board_product_pages. The gallery and device cards request bounded WebP thumbnails from cdn.esphub.ai using ?width=. Cloudflare Images resizes them from R2 on a CDN cache miss. Opening a board shows its original photo. A missing photo returns 404 and is omitted from the wall.