Cannot pair device
Closed this issue · 7 comments
Not a bug, but I cannot find any other information anywhere on pairing / bonding.
I have set the device as pairable but am unable to pair with anything. I understand this is very little to go off of, but I am more so wondering if there is a step I am missing, like some other method I need to call when bonding? Otherwise I can provide more code.
Could you be more precise? Setup? Configuration? ....
Could you share the code as text and tell me the hardware you used. If it is a WB, the firmware version.
Main Code:
#include <Arduino.h>
#include <SWOStream.h>
#include "debug_stream.h"
#include "BLE_Manager.h"
#include "initialization.h"
// Instantiate SWOStream for debugging
SWOStream SWO(2000000, SWO_Async, 0, true);
void setup() {
SystemClock_Config();
SWO.println("SWO Debugging Initialized!");
if (!bleManager.beginBLE()) {
while (1); // Halt
}
SWO.println("✅ BLE service created");
// Start advertising the service
bleManager.startAdvertising();
}
void loop() {
BLE.poll(); // Required for BLE event handling
if (BLE.connected()) {
if (BLE.pairable()) {
SWO.print("Device is pairable");
}
else {
SWO.print("Device is NOT pairable");
}
SWO.println("----------------------------------");
if(BLE.paired()) {
SWO.print("Device is paired");
}
else {
SWO.print("Device is NOT paired");
}
SWO.println("");
}
delay(3000);
}Manager class code:
#include "BLE_Manager.h"
BLEManager bleManager; // Global instance
BLEService txvrService("180C"); // 16-bit service UUID (standard "User Data")
bool BLEManager::beginBLE(const char* deviceName, const char* serviceUUID, uint16_t appearance) {
// Start the BLE module
if (!BLE.begin()) {
SWO.println("BLE initialization failed!");
return false;
}
SWO.println("BLE initialized");
BLE.setPairable(YES);
BLE.setConnectable(true);
// Basic configurations
BLE.setLocalName(deviceName);
BLE.setDeviceName(deviceName);
BLE.setAppearance(appearance);
SWO.print("Device name set: ");
SWO.println(deviceName);
// Create the service and add characteristics
addAllCharacteristicsToService(txvrService);
BLE.setAdvertisedService(txvrService); // ✅ This tells the scanner what to look for
// Now add the service to the BLE stack
BLE.addService(txvrService); // ✅ Add service only after characteristics are set
SWO.print("Service UUID registered: ");
SWO.println(serviceUUID);
return true;
}
void BLEManager::startAdvertising(const char* deviceName) {
BLEAdvertisingData advData;
advData.setFlags(BLEFlagsGeneralDiscoverable | BLEFlagsBREDRNotSupported); // ✅ Mandatory
advData.setLocalName(deviceName); // ✅ Include in primary advData
advData.setAdvertisedService(txvrService); // ✅ Include service UUID directly
BLE.setAdvertisingData(advData); // Set core advertising packet
BLEAdvertisingData scanData;
static const uint8_t manufactData[4] = {0x01, 0x02, 0x03, 0x04};
scanData.setManufacturerData(0xFFFF, manufactData, sizeof(manufactData)); // Optional
BLE.setScanResponseData(scanData);
BLE.setAdvertisingInterval(160);
BLE.advertise();
}
I used the stm32wb55rg, FUS v1.2.0 with stm32wb5x_BLE_HCILayer_fw.bin version 1.23.0
I have attached the entire program too if that helps.
The current version of the library is aligned with Cube Fw 1.22. 1.23 is not yet released.
Did you try with stm32wb5x_BLE_HCILayer_fw.bin version 1.22.0?
Ok looking at your request, it is not supported yet by the stm32duino Library.
We align the library with the Arduino Library and in this one the pair/bond is not well supported.
Sorry, but while the official library does not support it properly this one too.
Note: that's why the example EncryptedBatteryMonitor.ino is not provided

