esp-idf-provisioning-web
v0.0.7
Published
ESP-IDF WiFi Provisioning SDK for web browsers
Maintainers
Readme
ESP-IDF Provisioning Web SDK
A TypeScript SDK for provisioning ESP32 devices from web browsers using the ESP-IDF provisioning protocol. Supports both BLE (Web Bluetooth) and SoftAP (HTTP) transport modes.
Features
- [x] Security 0 and Security 1
- [x] Security1: X25519 + PoP + AES-256-CTR
- [ ] Security2 (not implemented)
- [x] BLE Transport: Uses Web Bluetooth API for wireless provisioning
- [x] SoftAP Transport: HTTP-based provisioning for devices in AP mode
- [x] Provisioning Protocol: Supports ESP-IDF provisioning protocol for WiFi credentials
- [x] Scan APs
- [x] Provision device status monitoring
- [ ] Reset and re-provisioning
- [x] Custom endpoints
Browser Compatibility
- BLE Mode: Requires browsers with Web Bluetooth API support (Chrome, Edge, Opera)
- SoftAP Mode: Works in all modern browsers (user must manually connect to WiFi)
Installation
npm install esp-idf-provisioning-webUsage
BLE with Security 0
Security 0 sends provisioning data without application-layer encryption. Use it only when the device is configured for Security 0.
import { ESPProvisionManager } from 'esp-idf-provisioning-web';
const device = await ESPProvisionManager.searchBLEDevice();
await device.connect();
const networks = await device.scanWifiList();
await device.provision('MyWiFiSSID', 'MyWiFiPassword');
// Poll fetchWifiStatus() until connected or failed, then disconnect.Runnable example: BLE Security 0.
BLE with Security 1
Security 1 uses X25519, proof of possession (PoP), and AES-256-CTR. Supply the PoP expected by the device:
import { ESPProvisionManager } from 'esp-idf-provisioning-web';
const device = await ESPProvisionManager.searchBLEDevice();
await device.connect({
type: 'Security1',
proofOfPossession: 'device-proof-of-possession',
});
const networks = await device.scanWifiList();
await device.provision('MyWiFiSSID', 'MyWiFiPassword');
// Poll fetchWifiStatus() until connected or failed, then disconnect.Runnable example: BLE Security 1.
Resolve Security 1 credentials asynchronously
connect() reads the public proto-ver endpoint before starting the handshake.
Pass a resolver to obtain credentials using the returned protocol and application
metadata. requestProofOfPossession below is supplied by the consuming application:
await device.connect(async (info) => {
if (info.prov.sec_ver !== 1) throw new Error('Expected Security 1');
const proofOfPossession = await requestProofOfPossession(info);
return { type: 'Security1', proofOfPossession };
});The SDK passes through custom metadata without interpreting it. Credential retrieval and authorization belong to the consuming application.
A new connect() call reads fresh metadata and runs the resolver again. Failed
authentication, resolver failure, or transport failure clears the session; retry
with connect(). There is no automatic downgrade to Security 0. Security 2 is
unsupported.
Custom endpoints and connection status
After connecting with either security mode, use the same APIs for application endpoints and Wi-Fi status. Custom endpoints use the established security mode:
const response = await device.sendData(
'custom-data', new TextEncoder().encode('{"command":"get"}')
);Requests are serialized because Security 1 shares one continuous AES-CTR stream
across both directions. sendData('proto-ver', ...) remains plaintext;
prov-session is managed internally. Other endpoints require a completed handshake.
import { ESPWifiStaState } from 'esp-idf-provisioning-web';
let status;
do {
status = await device.fetchWifiStatus();
if (status.staState === ESPWifiStaState.connecting) {
await new Promise((resolve) => setTimeout(resolve, 2000));
}
} while (status.staState === ESPWifiStaState.connecting);
device.disconnect();Security 1 requires a secure browser context and native Web Crypto X25519 support. Unsupported browsers fail the handshake instead of falling back to plaintext. See the Web Crypto specification and ESP-IDF protocol documentation.
SoftAP Provisioning
Important: The browser cannot automatically connect to WiFi networks. Users must manually connect to the ESP device's access point before running this code.
import { ESPProvisionManager } from 'esp-idf-provisioning-web';
// Create device instance for SoftAP
// User should already be connected to the device's WiFi network
const device = ESPProvisionManager.createSoftAPDevice(new URL('http://192.168.4.1'));
// Connect and provision
await device.connect();
await device.provision('MyWiFiSSID', 'MyWiFiPassword');Check Bluetooth Support
// Check if Web Bluetooth is available
if (ESPProvisionManager.isBluetoothSupported()) {
const isAvailable = await ESPProvisionManager.getBluetoothAvailability();
console.log('Bluetooth available:', isAvailable);
}Browser Limitations
BLE Mode
- Requires user interaction (button click) to initiate device scanning
- User must manually select device from browser's device picker
- HTTPS or localhost required for Web Bluetooth API
- The provisioning service UUID must be included in
filters[].servicesoroptionalServices
SoftAP Mode
- Browser cannot connect to WiFi networks programmatically
- User must manually connect to ESP device's access point
- CORS may need to be configured on the ESP device
- May not work on all networks due to browser security restrictions
FAQ
Which BLE service UUID should I use?
FALLBACK_SERVICE_UUID comes from ESP-IDF's default provisioning service,
not a Bluetooth SIG standard. If your firmware calls
wifi_prov_scheme_ble_set_service_uuid(), pass the same UUID in
filters[].services or optionalServices to searchBLEDevice().
The SDK tries the default service first. If it is absent or unauthorized, it
searches authorized services for prov-session and proto-ver. Endpoint names
are read from the 0x2901 descriptors; no fixed endpoint UUID mapping is used.
Development
Use Node.js 24 LTS to build and lint the SDK.
npm pack and npm publish rebuild the generated protocol code, bundles and
type declarations before packaging.
# Install dependencies
npm install
# Build
npm run build
# Lint
npm run lint
# Build and run provisioning transport tests with simulated GATT services
npm test
# Format
npm run formatLicense
MIT
