Komut
hasCharacteristic()
Açıklama
BLE hizmetinin belirli bir özelliği varsa sorgulayın.
Sözdizimi
bleService.hasCharacteristic (Uuid)
bleService.has Karakteristik (uuid, dizin)
Parametreler
uuid - kontrol etmek için uuid (dize olarak)
endeks - isteğe bağlı, cihazın açıktan fazla olup olmadığını kontrol etmek için karakteristik endeksi. Sağlanmazsa varsayılan olarak 0 olur.
İadeler
true , hizmet karakteristik sağlarsa, aksi takdirde false .
Misal
…
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
Serial.println("BLE Central scan");
// start scanning for peripheral
BLE.scan();
// …
BLEDevice peripheral = BLE.available();
if (peripheral) {
// ...
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}
// discover peripheral attributes
Serial.println("Discovering attributes ...");
if (peripheral.discoverAttributes()) {
Serial.println("Attributes discovered");
} else {
Serial.println("Attribute discovery failed!");
peripheral.disconnect();
return;
}
BLEService batteryService = peripheral.service("180f");
if (batteryService) {
// use the service
if (batteryService.hasCharacteristic("2a19")) {
Serial.println("Battery service has battery level characteristic");
}
} else {
Serial.println("Peripheral does NOT have battery service");
}
// ...
}
…
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
Serial.println("BLE Central scan");
// start scanning for peripheral
BLE.scan();
// …
BLEDevice peripheral = BLE.available();
if (peripheral) {
// ...
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}
// discover peripheral attributes
Serial.println("Discovering attributes ...");
if (peripheral.discoverAttributes()) {
Serial.println("Attributes discovered");
} else {
Serial.println("Attribute discovery failed!");
peripheral.disconnect();
return;
}
BLEService batteryService = peripheral.service("180f");
if (batteryService) {
// use the service
if (batteryService.hasCharacteristic("2a19")) {
Serial.println("Battery service has battery level characteristic");
}
} else {
Serial.println("Peripheral does NOT have battery service");
}
// ...
}
…
See Also