Import
Overview
BluFi is Espressif’s protocol for configuring WiFi on ESP32 devices over BLE. TheBlufiClient class provides a Python interface for:
- Connecting to ESP32 devices via BLE
- Negotiating secure communication
- Scanning for available WiFi networks
- Provisioning WiFi credentials
- Monitoring connection status
- Sending custom data
Methods
| Method | Description |
|---|---|
connectByName() | Connect to device by BLE name |
negotiateSecurity() | Establish encrypted communication |
requestVersion() | Get BluFi firmware version |
requestDeviceStatus() | Get WiFi connection status |
requestDeviceScan() | Scan for available WiFi networks |
postDeviceMode() | Set WiFi operation mode |
postStaWifiInfo() | Send WiFi credentials |
postCustomData() | Send custom data to device |
getVersion() | Get cached version string |
getWifiState() | Get cached WiFi state |
getSSIDList() | Get cached scan results |
Method Reference
BlufiClient()
Create a BluFi client instance.
| Parameter | Type | Description |
|---|---|---|
blufi_service_uuid | str | BluFi service UUID (optional) |
blufi_write_char_uuid | str | Write characteristic UUID (optional) |
blufi_notif_char_uuid | str | Notification characteristic UUID (optional) |
blufi_notif_desc_uuid | str | Notification descriptor UUID (optional) |
connectByName(name, timeout=None)
Connect to a BluFi device by its BLE advertised name.
| Parameter | Type | Description |
|---|---|---|
name | str | BLE device name to connect to |
timeout | float | Connection timeout in seconds (optional) |
bool - True if connected successfully
negotiateSecurity()
Establish secure encrypted communication with the device.
- All subsequent communication will be AES-encrypted
- Checksums will be enabled for data integrity
- Must be called before provisioning credentials
requestVersion()
Request the BluFi protocol version from the device.
getVersion()
Get the cached version string from the last requestVersion() call.
str or None - Version string
requestDeviceStatus()
Request current WiFi connection status from the device.
getWifiState()
Get the cached WiFi state from the last requestDeviceStatus() call.
dict with keys:
opMode- Operation mode (see Mode Constants)staConn- Station connection statussoftAPConn- SoftAP connection count
requestDeviceScan(timeout=10)
Request the device to scan for available WiFi networks.
| Parameter | Type | Description |
|---|---|---|
timeout | float | Scan timeout in seconds (default: 10) |
getSSIDList()
Get the cached WiFi scan results.
list[dict] - List of networks with SSID and RSSI
postDeviceMode(opMode)
Set the WiFi operation mode.
| Parameter | Type | Description |
|---|---|---|
opMode | int | Operation mode constant |
postStaWifiInfo(params)
Send WiFi credentials to the device.
| Parameter | Type | Description |
|---|---|---|
params | dict | Dictionary with ssid and pass keys |
postCustomData(data)
Send custom data to the device (application-specific).
| Parameter | Type | Description |
|---|---|---|
data | bytearray | Custom data bytes |
wait(timeout)
Wait for a specified duration (used between operations).
startNotify() / stopNotify()
Enable or disable BLE notifications.
Constants
Operation Modes
SoftAP Security Types
Connection Status
WiFi Failure Reasons
staConn field from getWifiState():
Examples
Basic WiFi Provisioning
WiFi Network Scanner
Production WiFi Provisioning Test
Custom Data Exchange
Error Handling
Exceptions
| Exception | Description |
|---|---|
BluetoothError | Base exception for Bluetooth related errors |
ConnectionError | Raised when a connection is unavailable |
RoleError | Raised when a resource is used with mismatched role |
SecurityError | Raised when a security related error occurs |
TimeoutError is Python’s built-in timeout exception, not a BluFi-specific exception.
Hardware Requirements
| Requirement | Description |
|---|---|
| Gateway | Must have Bluetooth adapter |
| ESP32 | Must be running BluFi-enabled firmware |
| Proximity | BLE range (typically < 10m) |
Protocol Details
The BluFi protocol uses:- BLE GATT: For data transport
- DH Key Exchange: For session key establishment
- AES-128: For data encryption
- CRC-16: For data integrity
- Service:
0000ffff-0000-1000-8000-00805f9b34fb - Write Characteristic:
0000ff01-0000-1000-8000-00805f9b34fb - Notification Characteristic:
0000ff02-0000-1000-8000-00805f9b34fb
Notes
- Always call
negotiateSecurity()before sending credentials - WiFi scan results are cached until the next scan
- The client uses a background thread for BLE operations
- Connection is automatically cleaned up on client destruction
- The protocol supports MTU sizes up to 512 bytes
- After provisioning, the device may restart to apply WiFi settings

