Skip to content

Chamath-Adithya/WiBLE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

84 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

WiBLE - Your Gateway Between BLE and Wi-Fi

WiBLE Logo

A production-grade, secure, and scalable BLE provisioning library for ESP32/ESP32-C6

GitHub Stars Downloads License Build Status

Features β€’ Quick Start β€’ Documentation β€’ Examples β€’ Contributing


🎯 Overview

WiBLE is a next-generation provisioning framework that seamlessly combines Bluetooth Low Energy (BLE) and Wi-Fi connectivity into a unified, developer-friendly library. It enables IoT devices to be configured securely and reliably through mobile apps, eliminating the complexity of manual network setup.

Why WiBLE?

Feature Traditional Approach WiBLE
Security Basic or None ECDH + AES-256 by default
Error Handling Manual retries Automatic with exponential backoff
State Management Boolean flags Finite State Machine (FSM)
Connection Time 30-60s < 18s
Testing Manual only Unit + Integration tests
Documentation Basic README Comprehensive API docs

✨ Features

πŸ”’ Security First

  • ECDH Key Exchange - Perfect Forward Secrecy
  • AES-256 Encryption - Military-grade credential protection
  • Multiple Security Levels - From hobbyist to enterprise
  • Secure Storage - Encrypted credentials in NVS

πŸš€ Performance Optimized

  • < 18s Total Provisioning - 50% faster than alternatives
  • MTU Negotiation - Up to 512 bytes per packet
  • Chunked Transfer - Handle large data seamlessly
  • Connection Pooling - Multi-device support

πŸ›‘οΈ Production Ready

  • Finite State Machine - Predictable state transitions
  • Circuit Breaker - Prevent cascading failures
  • Auto-Reconnect - WiFi resilience with exponential backoff
  • Comprehensive Logging - Structured, filterable logs

πŸ‘¨β€πŸ’» Developer Friendly

  • Simple API - 5 lines to get started
  • Event-Driven - Reactive callbacks
  • 80+ Unit Tests - High code quality
  • Rich Examples - Learn by doing

πŸ“¦ Partition Scheme (Critical!)

WiBLE requires a larger app partition than the default. The combined size of the WiFi stack, BLE stack (Bluedroid), and security libraries exceeds the standard 1.3MB app partition.

Arduino IDE

  1. Go to Tools > Partition Scheme.
  2. Select "Huge APP (3MB No OTA/1MB SPIFFS)" or "Minimal SPIFFS (1.9MB APP with OTA)".

PlatformIO

Add this to your platformio.ini:

board_build.partitions = huge_app.csv
; OR for OTA support:
; board_build.partitions = min_spiffs.csv

πŸš€ Quick Start

1. Installation

PlatformIO (Recommended)

[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = 
    Chamath-Adithya/WiBLE@^2.0.0

Arduino IDE

  1. Download latest release from GitHub Releases
  2. Extract to Arduino/libraries/WiBLE/
  3. Restart Arduino IDE

2. Basic Example

#include <WiBLE.h>

using namespace WiBLE;
WiBLE provisioner;

void setup() {
    Serial.begin(115200);
    
    // Configure library
    ProvisioningConfig config;
    config.deviceName = "MyIoTDevice";
    config.securityLevel = SecurityLevel::SECURE;
    
    // Initialize
    provisioner.begin(config);
    
    // Register callbacks
    provisioner.onWiFiConnected([](String ssid, String ip) {
        Serial.printf("Connected to %s with IP %s\n", ssid.c_str(), ip.c_str());
    });
    
    provisioner.onError([](ErrorCode code, String msg, bool canRetry) {
        Serial.printf("Error: %s\n", msg.c_str());
    });
    
    // Start provisioning
    provisioner.startProvisioning();
}

void loop() {
    provisioner.loop();  // CRITICAL: Call every iteration
}

3. Mobile App Setup

  1. Download WiBLE Companion App:

  2. Open app and scan for devices

  3. Select your device

  4. Enter WiFi credentials

  5. Wait for provisioning to complete


πŸ“– Documentation

Architecture

WiBLE uses a five-layer architecture for maximum flexibility:

graph TD
    App["Application Layer (Your Code)"] --> Core["Core Services Layer"]
    
    subgraph Core ["Core Services Layer"]
        State["State Machine"]
        Sec["Security Manager"]
        Orch["Provisioning Orchestrator"]
    end
    
    Core --> Proto["Protocol Layer"]
    
    subgraph Proto ["Protocol Layer"]
        BLE["BLE Manager"]
        WiFi["WiFi Manager"]
    end
    
    Proto --> HAL["Platform Abstraction Layer (ESP32 APIs)"]
    
    Cross["Cross-Cutting Concerns"] -.-> Core
    Cross -.-> Proto
Loading

Key Components

1. State Machine

Manages provisioning lifecycle with predictable transitions:

IDLE β†’ BLE_ADVERTISING β†’ BLE_CONNECTED β†’ AUTHENTICATING
  β†’ RECEIVING_CREDENTIALS β†’ CONNECTING_WIFI β†’ PROVISIONED

2. Security Manager

Handles all cryptographic operations:

  • ECDH-P256 key exchange
  • AES-256-CBC/GCM encryption
  • HMAC-SHA256 message authentication
  • Secure random number generation

3. BLE Manager

Manages Bluetooth operations:

  • GATT service/characteristic handling
  • MTU negotiation (up to 512 bytes)
  • Operation queue (serialized GATT ops)
  • RSSI monitoring

4. WiFi Manager

Handles network connectivity:

  • Network scanning
  • Connection with retry logic
  • Auto-reconnect with circuit breaker
  • Multi-network support

πŸŽ“ Examples

Basic Provisioning

Simple example showing minimal setup:

examples/BasicProvisioning/BasicProvisioning.ino

More Examples (Coming Soon)

  • Secure Provisioning: Advanced security with PIN authentication
  • Multi-Device: Provision multiple devices simultaneously
  • Custom Protocol: Extend provisioning with custom data
  • Background Operation: Long-running provisioning with power management

πŸ”§ Configuration

Security Levels

// No encryption (dev only)
config.securityLevel = SecurityLevel::NONE;

// Basic pairing
config.securityLevel = SecurityLevel::BASIC;

// ECDH + AES-256 (recommended)
config.securityLevel = SecurityLevel::SECURE;

// Certificate pinning + AES-256-GCM
config.securityLevel = SecurityLevel::ENTERPRISE;

Connection Parameters

// Fast provisioning (high power)
config.connectionInterval = 24;      // 30ms
config.mtuSize = 512;
config.enablePowerSaving = false;

// Power-efficient (slower)
config.connectionInterval = 80;      // 100ms
config.mtuSize = 185;
config.enablePowerSaving = true;

WiFi Settings

config.wifiConnectTimeoutMs = 20000;  // 20s
config.wifiMaxRetries = 3;
config.autoReconnect = true;
config.persistCredentials = true;     // Save to NVS

πŸ§ͺ Testing

Run Unit Tests

# PlatformIO
pio test -e native

# Arduino
# Use Arduino IDE's built-in test runner

Run Integration Tests

pio test -e esp32

Test Coverage

# Generate coverage report
pio test -e native --coverage
lcov --capture --directory .pio/build/native --output-file coverage.info
genhtml coverage.info --output-directory coverage_html

Current coverage: 85% (target: 80%)


πŸ“Š Performance Metrics

Provisioning Time

Phase Time Optimizations
BLE Scan 2-3s Pre-scanning
BLE Connection 1-2s Fast intervals
Authentication 1-2s ECDH caching
Credential Transfer 0.5-1s MTU 512
WiFi Connection 5-10s Retry backoff
Total 10-18s 50% improvement

Memory Usage

Component RAM Flash
WiBLE Core 45KB 180KB
BLE Stack 50KB 200KB
WiFi Stack 40KB 150KB
Total 135KB 530KB

Power Consumption

State Current Duration
BLE Advertising 25mA Variable
BLE Connected 20mA 5-10s
WiFi Connecting 100mA 5-10s
WiFi Connected 80mA Continuous
Deep Sleep 10ΞΌA When idle

πŸ” Debugging

Enable Verbose Logging

config.logLevel = LogLevel::VERBOSE;
config.enableSerialLog = true;

Dump State Information

provisioner.dumpState();

Output:

Current State: BLE_CONNECTED
Previous State: BLE_ADVERTISING
Time in State: 5234ms
BLE Connected: true
WiFi Connected: false
Secure Session: true
MTU: 512 bytes

Monitor Metrics

auto metrics = provisioner.getMetrics();
Serial.printf("Success Rate: %.1f%%\n", 
    (float)metrics.successfulProvisionings / 
    metrics.totalProvisioningAttempts * 100);

🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Development Setup

# Clone repository
git clone https://github.com/Chamath-Adithya/WiBLE.git
cd wible

# Install dependencies
pio lib install

# Build
pio run -e esp32

# Run tests
pio test -e native

# Format code
pio run -t format

# Note: If running locally, ensure you have PlatformIO installed.
# You may need to use a virtual environment if your system manages python packages externally:
# python3 -m venv venv
# source venv/bin/activate
# pip install platformio
# pio run -e esp32

Code Style

  • Follow Google C++ Style Guide
  • Use clang-format for formatting
  • Write tests for new features
  • Update documentation

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright (c) 2025 Chamath Adithya (SOLVEO)

πŸ‘₯ Author

Chamath Adithya - SOLVEO


πŸ™ Acknowledgments

Built on insights from:



❓ Frequently Asked Questions (FAQ)

How do I provision an ESP32 using Bluetooth?

WiBLE makes it easy. Simply include the library, set the security level, and call provisioner.startProvisioning(). The device will advertise via BLE, allowing your mobile app to connect and send WiFi credentials securely.

Is WiBLE secure?

Yes! WiBLE uses ECDH (Elliptic Curve Diffie-Hellman) for key exchange and AES-256 for encryption. This ensures that your WiFi credentials are never exposed in plain text over the air.

Does it support ESP32-C3 and ESP32-S3?

Yes, WiBLE supports all ESP32 variants including ESP32-C3, ESP32-S3, and ESP32-C6, as long as they support Bluetooth Low Energy.

Can I use this with Arduino IDE?

Absolutely. WiBLE is fully compatible with the Arduino framework and can be installed via the Library Manager or by downloading the release from GitHub.


πŸ“ž Support


πŸ—ΊοΈ Roadmap

v2.1 (Q2 2025)

  • Bluetooth Mesh support
  • Matter/Thread integration
  • Flutter SDK
  • React Native SDK

v2.2 (Q3 2025)

  • OTA firmware updates
  • Cloud integration (AWS IoT, Azure)
  • Analytics dashboard
  • Multi-language support

v3.0 (Q4 2025)

  • BLE 5.3 features
  • Kubernetes deployment
  • Edge computing support
  • AI-powered diagnostics

πŸ“ˆ Statistics


Built with ❀️ by SOLVEO