RTL8720 (bw16) BLE UUID 128bit 簡化導致通訊失敗

問題

我目前使用Ublox w306 RTL8720嘗試與三種不同廠牌的藍芽裝置進行連線,以下以ABC代稱,目前B與C可以連線,而A廠牌使用ESP32C3可以正常取得資料,而使用RTL8720時會失敗,使用A廠牌時RTL8720可以正常搜尋服務,但是後續無法與裝置成功溝通,只能用16bit UUID取得服務。

目前發現可能的原因是A廠牌的UUID結尾-0000-1000-8000-00805F9B34FB 與藍牙標準 UUID 相同,導致 BLE 底層誤將其識別或簡化為 16-bit UUID,想請問有沒有辦法強制BLE以128bit UUID搜尋服務,已使用過profile_client.h檔案裡的apiclient_by_uuid128_srv_discoveryclient_by_uuid128_char_discovery,結果均失敗。

A、B、C三家的UUID

static  BLEUUID AServiceUUID("0000fff0-0000-1000-8000-00805f9b34fb");
static  BLEUUID ACharReadUUID ("0000fff1-0000-1000-8000-00805f9b34fb");
static  BLEUUID ACharWriteUUID("0000fff2-0000-1000-8000-00805f9b34fb");

static  BLEUUID AServiceUUID16bit  (BLEUUID("FFF0")); // 16bit
static  BLEUUID ACharReadUUID16bit (BLEUUID("FFF1"));
static  BLEUUID ACharWriteUUID16bit(BLEUUID("FFF2"));


static  BLEUUID BServiceUUID("00001523-1212-efde-1523-785feabcd123");
static  BLEUUID BCharUUID   ("00001524-1212-efde-1523-785feabcd123");

static  BLEUUID CServiceUUID ("233BF000-5A34-1B6D-975C-000D5690ABE4");
static  BLEUUID CCharUUID    ("233BF001-5A34-1B6D-975C-000D5690ABE4");

部分程式

藍芽連線


bool returnStatus = true;

uint8_t connCount = 0;

do
{
  
    if (BLE.configConnection()->connect(targetDevice, 2000))  
    {
    
      delay(2000);   

      break;

    }
    else
    {

      delay(500);

      Serial.println("failed, try to connect again...");

      connCount ++;

    }
    
} while (connCount < connTimeout);

  

if (!BLE.connected(connID))
{

    Serial.println("BLE not charConnected");

    returnStatus = false;

    if (BLE.configConnection()->disconnect(connID))
    {

      Serial.println("BLE disconnect success");

    }
    
    return returnStatus;

}
else
{

    BLE.configClient();

    pClient = BLE.addClient(connID);

    if (pClient == nullptr)
    {

      Serial.println("failed to add client");

      returnStatus = false;

    }
    else
    {

      uint8_t discTimeout = 10;

      pClient->setDisconnectCallback(MyClientDisconnectCallback);

      pClient->discoverServices()

      uint8_t discCount = 0;

      do
      {

        Serial.print(".");

        delay(1000);

        discCount++;

        if (discCount > discTimeout)
          break;

      } while (!(pClient->discoveryDone()));

      Serial.println();

      pClient->printServices();

      if (discCount > discTimeout)
      {

        Serial.println("time out");
      }
      else
      {
      
		checkProtocol();
		
      }
      
  returnStatus = deviceTasks(pClient); // 處理藍芽裝置連線指令
  
  BLE.configConnection()->disconnect();

  return returnStatus;
}

確認Characteristic

bool ValidateCharacteristic(BLERemoteCharacteristic *pRemoteCharacteristiccheck, BLEUUID CharUUID)

{

    if (pRemoteCharacteristiccheck == nullptr)

    {

      Serial.print("Failed to find our characteristic UUID: ");

      Serial.println(getString(CharUUID));

      return false;

    }

    else

    {

      Serial.print("search Characteristic:");

      Serial.print(getString(pRemoteCharacteristiccheck->getUUID()));

      Serial.println("...Good");

    }

    Serial.print(" - Found out characteristic: ");

    Serial.println(getString(pRemoteCharacteristiccheck->getUUID()));

  

    return true;

}

ESP32C3 A廠牌(成功)

ESP32C3使用16bit UUID找到UUID為128bit的Characteristic並成功連線與溝通

check A service
- Found out service:0000fff0-0000-1000-8000-00805f9b34fb
search Characteristic:0000fff1-0000-1000-8000-00805f9b34fb…Good
- Found out characteristic: 0000fff1-0000-1000-8000-00805f9b34fb
search Characteristic:0000fff2-0000-1000-8000-00805f9b34fb…Good
- Found out characteristic: 0000fff2-0000-1000-8000-00805f9b34fb
NOTIFY
- Registered Callback
- Enable Notify
========================================================
SPP CMD Index=7
A command length=6
A command:XX,XX,XX,XX,XX,XX,
Send SPP command via ESP32C3
Notify callback for characteristic
data length=6, Data:YY,YY,YY,YY,YY,YY,
… Received
Elapse time:100
Process Response 7:
insufficient length, abort
BT Process time:2.53
stop scan
E (37570) BT_BTM: BTM_BleScan scan not active


RTL8720

A廠牌 16bit UUID (有找到服務失敗)

A廠牌

static  BLEUUID AServiceUUID(BLEUUID("FFF0"));

static  BLEUUID ACharReadUUID(BLEUUID("FFF1"));

static  BLEUUID ACharWriteUUID(BLEUUID("FFF2"));


Device at conn ID 0 has services:
Service UUID: 1800
Start handle: 0x1, End handle: 0x7
Characteristic UUID: 2A00, Properties: 0xa
Declaration handle: 0x2, Value handle: 0x3
Characteristic UUID: 2A01, Properties: 0x2
Declaration handle: 0x4, Value handle: 0x5
Characteristic UUID: 2A04, Properties: 0x2
Declaration handle: 0x6, Value handle: 0x7
Service UUID: 1801
Start handle: 0x8, End handle: 0x8
Service UUID: FFF0
Start handle: 0x9, End handle: 0xe
Characteristic UUID: FFF1, Properties: 0x10
Declaration handle: 0xa, Value handle: 0xb
Descriptor UUID: 2902
Declaration handle: 0xc
Characteristic UUID: FFF2, Properties: 0xc
Declaration handle: 0xd, Value handle: 0xe
Service UUID: 8E400001-F315-4F60-9FB8-838830DAEA50
Start handle: 0xf, End handle: 0x12
Characteristic UUID: 8E400001-F315-4F60-9FB8-838830DAEA50, Properties: 0x18
Declaration handle: 0x10, Value handle: 0x11
Descriptor UUID: 2902
Declaration handle: 0x12
Service UUID: 180A
Start handle: 0x13, End handle: 0xffff
Characteristic UUID: 2A29, Properties: 0x2
Declaration handle: 0x14, Value handle: 0x15
Characteristic UUID: 2A24, Properties: 0x2
Declaration handle: 0x16, Value handle: 0x17
Characteristic UUID: 2A25, Properties: 0x2
Declaration handle: 0x18, Value handle: 0x19
Characteristic UUID: 2A27, Properties: 0x2
Declaration handle: 0x1a, Value handle: 0x1b
Characteristic UUID: 2A26, Properties: 0x2
Declaration handle: 0x1c, Value handle: 0x1d
Characteristic UUID: 2A28, Properties: 0x2
Declaration handle: 0x1e, Value handle: 0x1f
device 3, expected protocol:0

discover battery service
Failed to find out service UUID: 180F
check A service
- Found out service:FFF0
search Characteristic:FFF1…Good
- Found out characteristic: FFF1
search Characteristic:FFF2…Good
- Found out characteristic: FFF2
NOTIFY
- Registered Callback
- Enable Notify
========================================================
SPP CMD Index=7
command length=6
command:XX,XX,XX,XX,XX,XX,
Send SPP command via RTL8720
Properties: 0xC
wait for data
wait for data
wait for data
wait for data // 傳輸超時


A廠牌 128bit UUID (失敗)

static  BLEUUID AServiceUUID  ("0000fff0-0000-1000-8000-00805f9b34fb");

static  BLEUUID ACharReadUUID ("0000fff1-0000-1000-8000-00805f9b34fb");

static  BLEUUID ACharWriteUUID("0000fff2-0000-1000-8000-00805f9b34fb");

Device at conn ID 0 has services:
Service UUID: 1800
Start handle: 0x1, End handle: 0x7
Characteristic UUID: 2A00, Properties: 0xa
Declaration handle: 0x2, Value handle: 0x3
Characteristic UUID: 2A01, Properties: 0x2
Declaration handle: 0x4, Value handle: 0x5
Characteristic UUID: 2A04, Properties: 0x2
Declaration handle: 0x6, Value handle: 0x7
Service UUID: 1801
Start handle: 0x8, End handle: 0x8
Service UUID: FFF0
Start handle: 0x9, End handle: 0xe
Characteristic UUID: FFF1, Properties: 0x10
Declaration handle: 0xa, Value handle: 0xb
Descriptor UUID: 2902
Declaration handle: 0xc
Characteristic UUID: FFF2, Properties: 0xc
Declaration handle: 0xd, Value handle: 0xe
Service UUID: 8E400001-F315-4F60-9FB8-838830DAEA50
Start handle: 0xf, End handle: 0x12
Characteristic UUID: 8E400001-F315-4F60-9FB8-838830DAEA50, Properties: 0x18
Declaration handle: 0x10, Value handle: 0x11
Descriptor UUID: 2902
Declaration handle: 0x12
Service UUID: 180A
Start handle: 0x13, End handle: 0xffff
Characteristic UUID: 2A29, Properties: 0x2
Declaration handle: 0x14, Value handle: 0x15
Characteristic UUID: 2A24, Properties: 0x2
Declaration handle: 0x16, Value handle: 0x17
Characteristic UUID: 2A25, Properties: 0x2
Declaration handle: 0x18, Value handle: 0x19
Characteristic UUID: 2A27, Properties: 0x2
Declaration handle: 0x1a, Value handle: 0x1b
Characteristic UUID: 2A26, Properties: 0x2
Declaration handle: 0x1c, Value handle: 0x1d
Characteristic UUID: 2A28, Properties: 0x2
Declaration handle: 0x1e, Value handle: 0x1f
device 3, expected protocol:0
A 128bit read characteristic discovery failed
A 128bit write characteristic discovery failed
check A service
getService
getService done
Failed to find our service UUID: 0000FFF0-0000-1000-8000-00805F9B34FB // 搜尋不到服務
discoonect connection

B廠牌 (成功)

Device at conn ID 0 has services:
Service UUID: 1800
Start handle: 0x1, End handle: 0x7
Characteristic UUID: 2A00, Properties: 0x2
Declaration handle: 0x2, Value handle: 0x3
Characteristic UUID: 2A01, Properties: 0x2
Declaration handle: 0x4, Value handle: 0x5
Characteristic UUID: 2A04, Properties: 0x2
Declaration handle: 0x6, Value handle: 0x7
Service UUID: 1801
Start handle: 0x8, End handle: 0x8
Service UUID: 180A
Start handle: 0x9, End handle: 0x1b
Characteristic UUID: 2A23, Properties: 0x2
Declaration handle: 0xa, Value handle: 0xb
Characteristic UUID: 2A24, Properties: 0x2
Declaration handle: 0xc, Value handle: 0xd
Characteristic UUID: 2A25, Properties: 0x2
Declaration handle: 0xe, Value handle: 0xf
Characteristic UUID: 2A26, Properties: 0x2
Declaration handle: 0x10, Value handle: 0x11
Characteristic UUID: 2A27, Properties: 0x2
Declaration handle: 0x12, Value handle: 0x13
Characteristic UUID: 2A28, Properties: 0x2
Declaration handle: 0x14, Value handle: 0x15
Characteristic UUID: 2A29, Properties: 0x2
Declaration handle: 0x16, Value handle: 0x17
Characteristic UUID: 2A2A, Properties: 0x2
Declaration handle: 0x18, Value handle: 0x19
Characteristic UUID: 2A50, Properties: 0x2
Declaration handle: 0x1a, Value handle: 0x1b
Service UUID: 1810
Start handle: 0x1c, End handle: 0x21
Characteristic UUID: 2A35, Properties: 0x20
Declaration handle: 0x1d, Value handle: 0x1e
Descriptor UUID: 2902
Declaration handle: 0x1f
Characteristic UUID: 2A49, Properties: 0x2
Declaration handle: 0x20, Value handle: 0x21
Service UUID: 00001523-1212-EFDE-1523-785FEABCD123
Start handle: 0x22, End handle: 0xffff
Characteristic UUID: 00001524-1212-EFDE-1523-785FEABCD123, Properties: 0x18
Declaration handle: 0x23, Value handle: 0x24
Descriptor UUID: 2902
Declaration handle: 0x25
device 2, expected protocol:0
B Device
check B service
- Found out service:00001523-1212-EFDE-1523-785FEABCD123
search Characteristic:00001524-1212-EFDE-1523-785FEABCD123…Good
- Found out characteristic: 00001524-1212-EFDE-1523-785FEABCD123
NOTIFY
- Registered Callback
- Enable Notify
read data
========================================================
SPP CMD Index=0
SPP command:XX,XX,XX,XX,XX,XX,XX,XX,
Send SPP command via RTL8720
Notify callback for characteristic
data length=8 Data:ZZ,ZZ,ZZ,ZZ,ZZ,ZZ,ZZ,ZZ,
store data at index:0
… Received