當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino ArduinoBLE - bleDevice.hasAdvertisedServiceUuid()用法及代碼示例

查詢發現的 Bluetooth® Low Energy 設備是否正在宣傳服務 UUID。

用法

bleDevice.hasAdvertisedServiceUuid()
bleDevice.hasAdvertisedServiceUuid(index)

參數

  • index: 可選,默認為 0,服務 UUID 的索引,如果設備正在廣播多個。

返回

  • true, 如果設備正在廣告服務 UUID,
  • false否則。

示例


  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");

    while (1);
  }

  Serial.println("BLE Central scan");

  // start scanning for peripheral
  BLE.scan();

  

  BLEDevice peripheral = BLE.available();

  if (peripheral) {
    // ...

    // print the advertised service UUIDs, if present
    if (peripheral.hasAdvertisedServiceUuid()) {
      Serial.print("Service UUIDs: ");
      for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
        Serial.print(peripheral.advertisedServiceUuid(i));
        Serial.print(" ");
      }
      Serial.println();
    }

    // ...
  }


相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 ArduinoBLE - bleDevice.hasAdvertisedServiceUuid()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。