Skip to content
5aranxPublic

About

BLE HID emulation and keystroke framework for ESP32-S3 with an on-board Wi-Fi dashboard

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Mayavi

BLE HID emulation and keystroke framework for the ESP32-S3, with an on-board Wi-Fi dashboard and a serial console.

Mayavi turns the board into a configurable Bluetooth Low Energy HID device: it advertises as a keyboard, mouse, gamepad, media remote or TV box, pairs with a host, and types programmable keystroke payloads from a browser served by the device itself.

Use it only on hardware you own or have written permission to test.


Board

Module ESP32-S3-N16R8, 16 MB QIO flash, 8 MB octal PSRAM
Console port native USB (303a:1001, /dev/ttyACM0)
Status LED WS2812 on GPIO 48 (v1.1 boards use GPIO 38 — edit platformio.ini)
Framework Arduino, PlatformIO espressif32

Build and flash

pio run -e mayavi                     # firmware
pio run -e mayavi -t upload           # + flash it
pio run -e mayavi -t uploadfs         # web assets from data/ -> LittleFS

Flash both: the firmware without a filesystem serves a "LittleFS has no index.html" page. If the port is ambiguous, pin it: --upload-port /dev/ttyACM0.

Using it

  1. Power the board. It raises an access point: SSID Rishihood_Learner, open — no password by default.
  2. Open http://192.168.4.1.
  3. Firmware 1.2.0 opens discovery for 60 seconds after boot, using the saved Bluetooth name. To change the profile, use Disconnect / stop, choose a profile, then Start discovery again.
  4. On the target, pair the device. Windows 10/11 shows a Swift Pair toast; macOS/Linux list it by name.
  5. When the pill turns ready, go to Payloads and press Run payload.

Everything is also available over serial at 115200 baud.

The SSID names the ESP's own dashboard hotspot; it does not connect the ESP to an existing network with that name. Saved Wi-Fi settings survive firmware updates and override this default. On an already configured board, change Device settings → Network name to Rishihood_Learner, then select Save network & reboot to apply it.

Dashboard and payload studio

The dashboard has a responsive connection workspace, live device status, profile cards, a script editor with byte counts and unsaved-change tracking, and separate Bluetooth and Wi-Fi settings. Errors appear above every tab. Controls disable when the board is offline; scripts require an encrypted connection and a host subscribed to keyboard reports. The UI uses local assets only, without a CDN or internet connection.

Flash both firmware and LittleFS when upgrading. Version 1.1 fixes malformed JSON in the status and settings endpoints; replacing the dashboard alone does not fix older firmware. Version 1.2.0 fixes the advertising sequence and packet layout. Uploading only uploadfs does not install those BLE fixes.

If another computer cannot see Mayavi

  1. Upload both images, reload the dashboard, and check Device settings → Firmware shows 1.2.0:

    pio run -e mayavi -t upload --upload-port /dev/ttyACM0
    pio run -e mayavi -t uploadfs --upload-port /dev/ttyACM0
  2. The board supports one Bluetooth host at a time. If it is already Ready or Pairing, disconnect that host first. If the old host keeps taking the connection, temporarily turn off Bluetooth there while pairing the new one.

  3. Select Wireless Keyboard, choose the target OS, and start a 60-second discovery window. Search for the name shown under Advertised as; this Bluetooth name is separate from the dashboard's Wi-Fi SSID.

  4. The Discoverable badge now requires a successful controller callback. A rejected operation, failed callback or timeout appears as Discovery error, with details in the connection panel and serial status output. After a controller timeout, reboot before retrying.

  5. If discovery succeeds but your host still cannot see it, capture the serial boot log and status at 115200 baud while the discovery window is open. Include the target OS/version and whether another Bluetooth host is connected.

The primary advertisement now includes the HID service UUID in both standard and Swift Pair modes. Raw advertising data and scan-response configuration must complete before advertising starts; failures no longer produce a false Discoverable state. Standard BLE is the factory default, while saved mode preferences are preserved. Swift Pair uses the LE-only sub-scenario and reserved RSSI byte described in the Microsoft specification. Controller completion events follow the Espressif GAP API.

Packet layout and controller success/failure paths are tested on the host; physical discovery on Linux/macOS still requires a test with the flashed board.

OS-specific payloads

The payload studio separates Windows, Linux and macOS into their own libraries. Choose a host and a template, customize its fields, review the generated script, then select Load into editor. Loading and previewing never execute a script. Run payload starts only after the selected 3-, 5- or 10-second countdown.

Template Windows Linux macOS
Typing test Focused text editor Focused text editor Focused text editor
Notepad greeting Run dialog → new Notepad document — —
Terminal greeting PowerShell Write-Output Shell printf Terminal printf
System information Windows OS name/version uname -sr sw_vers
Open a web page Ctrl+L in a focused browser Ctrl+L in a focused browser Command+L in a focused browser
Custom command Editable PowerShell command Editable shell command Editable shell command

Messages, URLs and commands are configurable; terminal templates also offer an app startup wait. Linux exposes the terminal shortcut selector. Each OS retains its custom-command field while switching libraries. Switching OS preserves the editor; a template loaded for a different OS must be replaced or its original OS reselected before running. Host OS selection is manual, not autodetected. Previously saved or hand-written scripts must be reviewed for the chosen host.

macOS terminal templates use Command+Space, search for Terminal, then use Command+N to create a new window. Complete macOS keyboard setup before running, and adjust shortcuts in the editor if yours differ. Refer to Apple's Spotlight shortcuts, Terminal shortcuts, and Windows keyboard shortcuts.

The template library lives in data/presets.js and supports firmware 1.1.0 or later. Install firmware 1.2.0 as well to get the Bluetooth discovery fixes above. Future dashboard-only edits can be uploaded with uploadfs after that upgrade.

Linux hosts

  1. Select Wireless Keyboard, choose Linux / BlueZ, and start discovery. This selects standard BLE advertising. The scan response includes the HID service UUID so hosts can identify the device as an input peripheral.

  2. Pair from your Linux Bluetooth settings. Alternatively, run bluetoothctl and enter the following, replacing DEVICE_MAC with the scanned address:

    power on
    agent on
    default-agent
    scan on
    pair DEVICE_MAC
    trust DEVICE_MAC
    connect DEVICE_MAC
    scan off
    
  3. Wait for Ready, then open Payload studio → Linux. Start with Typing test and focus an empty text editor on the paired Linux host.

  4. For Terminal greeting, select the shortcut configured in your desktop: Ctrl+Alt+T, Super+Enter, or Super+Q. These are selectable examples, not universal Linux defaults. You can also choose Already open and focus an empty terminal prompt yourself. Then load the preset; it runs printf '%s\n' 'Hello from Mayavi' in that terminal. Edit the script directly for other shortcuts or slower terminal startup.

Linux support uses ordinary BLE HID reports, so no X11-only input utility is required. The host needs working Bluetooth/BlueZ and HID support. Text uses the US keyboard layout and ASCII; non-US layouts and Unicode text are not translated. Windows Notepad and PowerShell presets remain available separately.

If discovery expires, start it again. If an old pairing fails after an update, forget the bond in Mayavi and remove the device from the host, then re-pair. The in-dashboard Linux guide includes the same pairing commands. See the BlueZ bluetoothctl reference and Bluetooth assigned service numbers.

The Linux workflow and readiness logic have automated coverage. Physical Linux pairing and typing still need verification on a flashed board; host tests are not a substitute for that check.

Profiles

id appearance advertised as
keyboard 0x03C1 Wireless Keyboard
mouse 0x03C2 Wireless Mouse
gamepad 0x03C4 Wireless Gamepad
joystick 0x03C3 Wireless Joystick
pen 0x03C7 Digital Pen
android-tv 0x0280 Android TV
apple-tv 0x0280 Apple TV
airtag 0x0200 AirTag
jiotag 0x0200 JioTag
hrm 0x0341 HR Sensor
custom user set user set name

Switching a profile changes the advertised name and appearance only. The GATT table is one composite HID device — keyboard (report 1), mouse (2), gamepad (3), consumer control (4) — so no re-pairing is needed when the profile changes.

Serial console

1 / start [sec]     start BLE discovery advertising
0 / stop            stop advertising / disconnect the host
2 / status          connection, security, payload state
3 / profiles        list emulated profiles
profile <id>        switch profile
name <text>         change the advertised name
appearance <hex>    raw appearance code, selects the custom profile
duration <sec>      discovery timeout, 5..60
mode swift|beacon   Swift Pair or plain advertisement
forget              clear stored Bluetooth bonds
4 / hid             payload menu
5 / hello           Notepad + Hello test payload
hello linux         Linux terminal + Hello (requires Ctrl+Alt+T)
hello text          type Hello in the focused editor (any OS)
payload begin       enter a script, finish with END
payload show        print the stored script
payload run         execute it
abort               stop and release all keys
wifi                show the dashboard access point
wifi open           drop the password and reboot into an open AP
wifi set <s> <p>    change it, then reboot (empty password = open)
reboot

Payload syntax

REM comment                     # comment
STRING Hello from Mayavi
DELAY 500
ENTER / TAB / ESC / BACKSPACE / DELETE / SPACE
UP / DOWN / LEFT / RIGHT / HOME / END / F1..F12
GUI r                           CTRL SHIFT ESC
DEFAULTDELAY 30                 # per-character gap, ms

The runner is a non-blocking state machine, so the dashboard stays responsive and Stop releases keys immediately.

Layout

src/main.cpp      boot, access point, status LED, loop
src/settings.*    NVS-backed identity + AP credentials
src/emul.*        BLE stack, HID device, advertising payloads, bonds
src/hid.*         report descriptor, key tables, report senders
src/payload.*     parser + cooperative runner + presets
src/web.*         LittleFS assets + JSON API
src/console.*     serial CLI
data/             dashboard (index.html, app.js, style.css)
data/presets.js   Windows, Linux and macOS template catalog and script builder

Notes and limits

  • Advertising budget is 31 bytes. Flags, appearance and the HID service UUID occupy 11 bytes. Standard BLE includes up to 18 name bytes (marked as a shortened name when necessary); Swift Pair has room for 13 display-name bytes. The full name (25 bytes max) is in the scan response.
  • The access point and BLE share the 2.4 GHz radio. Coexistence works; heavy dashboard polling during a payload can add a little jitter.
  • Tracker profiles (airtag, jiotag) emulate the advertised appearance and name only — they cannot register with a real Find My network.
  • Pairing is Just Works with bonding (ESP_LE_AUTH_REQ_SC_BOND), which is what a keyboard-shaped HID device normally does. forget clears the bonds so the host pairs again.
  • The AP ships open so the dashboard can be reached without setup. Anyone in radio range can therefore drive the HID side — set a password from the Settings tab (or wifi set) for anything but a bench test.
  • Two USB ports: the serial console is on the native USB port (CDC). The CH343 bridge port works for flashing but only carries the ROM bootloader output, not the CLI.

Development checks

The dashboard ships as plain HTML/CSS/JavaScript. Node dependencies are used only for development tests and are not copied to the board.

npm ci
npm test
node --check data/app.js
pio run -e mayavi
pio run -e mayavi -t buildfs

npm test requires a current Node.js version supported by jsdom, Python 3 and g++. It exercises the dashboard against a simulated device, including Linux shortcuts, pairing readiness, run/stop, offline recovery, input validation and draft preservation. The Python checks compile the actual C++ API serializer functions with host stubs and parse their responses, covering open/protected networks, escaped text, presets and HID readiness combinations. The advertising tests compile the actual packet builder and GAP-operation helpers against a simulated controller. They check byte budgets, service UUIDs, Swift Pair fields, operation ordering, immediate errors, asynchronous failures, bounded timeouts, stop/start transitions and connected-host rejection.

Before releasing to hardware, check desktop and phone layouts, flash both images, pair a Linux host, run the focused-editor and terminal greetings, and confirm Stop releases the keys. Automated DOM tests do not check rendered layout or Bluetooth radio behavior.


Engineered with precision for secure, scalable systems.
Made by Saransh Singh

About

BLE HID emulation and keystroke framework for ESP32-S3 with an on-board Wi-Fi dashboard

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages