Giter VIP home page Giter VIP logo

esp32-nimble's Introduction

NimBLE Rust wrapper for ESP32

crates.io build License Documentation

This is a Rust wrapper for the NimBLE Bluetooth stack for ESP32. Inspired by NimBLE-Arduino.

Usage

Add below settings to your project's sdkconfig.defaults.

CONFIG_BT_ENABLED=y
CONFIG_BT_BLE_ENABLED=y
CONFIG_BT_BLUEDROID_ENABLED=n
CONFIG_BT_NIMBLE_ENABLED=y
  • To enable Extended advertising, additionally append CONFIG_BT_NIMBLE_EXT_ADV=y.
    (For use with ESP32C3, ESP32S3, ESP32H2 ONLY)

Configuring for iOS Auto-Reconnection

To enable seamless auto-reconnection of iOS devices with your ESP32 BLE server, you need to adjust settings in both the sdkconfig file and your Rust code.

Update sdkconfig

Include this line in your sdkconfig:

CONFIG_BT_NIMBLE_NVS_PERSIST=y

Setting CONFIG_BT_NIMBLE_NVS_PERSIST to y ensures that bonding information is saved in the device's Non-Volatile Storage (NVS). This step is crucial for allowing iOS devices to automatically reconnect without the need for rebonding after the ESP32 has been reset or powered off and on again.

Configure Security Options in Rust Code

Properly setting the security options in your Rust implementation is key:

device
  .security()
  .set_auth(AuthReq::Bond) // Bonding enables key storage for reconnection
  .set_passkey(123456) // Optional, sets the passkey for pairing
  .set_io_cap(SecurityIOCap::NoInputNoOutput) // You can choose any IO capability
  .resolve_rpa(); // Crucial for managing iOS's dynamic Bluetooth addresses
  • .set_auth(AuthReq::Bond) sets up bonding, crucial for storing security keys that enable future automatic reconnections.
  • .resolve_rpa(): This function is essential for adapting to the changing Bluetooth addresses used by iOS devices, a feature known as Resolvable Private Address (RPA). It's vital for maintaining reliable and seamless connections with iOS devices, ensuring that your ESP32 device can recognize and reconnect to an iOS device even when its Bluetooth address changes.
  • BLE Passkeys are exactly 6 digits by spec, so if you set a passkey of '1234' it is actually '001234' so to properly display the code to a user you must pad the left i.e. format!("{:0>6}",pkey)

esp32-nimble's People

Contributors

taks avatar sampaioletti avatar oleander avatar chocolateloverraj avatar p3zhy avatar catunlock avatar jannesbrands avatar mnlphlp avatar tufteddeer avatar kpcyrd avatar cliffhan avatar pilotniq avatar jasta avatar mbv avatar codepainters avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.