This is a Rust wrapper for the Bluedroid Bluetooth stack for ESP32. It allows you to build a GATT server with a declarative API and supports multithreading.
Declare a characteristic:
rust
let manufacturer_name_characteristic = Characteristic::new(BleUuid::Uuid16(0x2A29))
.name("Manufacturer Name String")
.permissions(AttributePermissions::new().read().write())
.properties(CharacteristicProperties::new().read().write().notify())
.max_value_length(20)
.on_write(|data, param| {
info!("Received write request: {:?} {:?}", data, param);
})
.show_name()
.set_value("Hello, world!".as_bytes().to_vec())
.build();
Declare a service:
rust
let device_information_service = Service::new(BleUuid::Uuid16(0x180A))
.name("Device Information")
.primary()
.characteristic(&manufacturer_name_characteristic)
.build();
Declare a profile and start the server:
```rust let profile = Profile::new(0x0001) .name("Device Information") .service(&deviceinformationservice) .build();
GLOBALGATTSERVER .lock() .unwrap() .profile(profile) .devicename("ESP32-GATT-Server") .appearance(Appearance::WristWornPulseOximeter) .advertiseservice(&deviceinformationservice) .start(); ```