1/* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import type { AsyncCallback, Callback } from './@ohos.base'; 17import type constant from './@ohos.bluetooth.constant'; 18 19/** 20 * Provides methods to operate or manage Bluetooth. 21 * 22 * @namespace ble 23 * @syscap SystemCapability.Communication.Bluetooth.Core 24 * @since 10 25 */ 26declare namespace ble { 27 /** 28 * Indicate the profile connection state. 29 * 30 * @syscap SystemCapability.Communication.Bluetooth.Core 31 * @since 10 32 */ 33 type ProfileConnectionState = constant.ProfileConnectionState; 34 35 /** 36 * create a Gatt server instance. 37 * 38 * @returns { GattServer } Returns a Gatt server instance {@code GattServer}. 39 * @syscap SystemCapability.Communication.Bluetooth.Core 40 * @since 10 41 */ 42 function createGattServer(): GattServer; 43 44 /** 45 * create a Gatt client device instance. 46 * 47 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 48 * @returns { GattClientDevice } Returns a Gatt client device instance {@code GattClientDevice}. 49 * @throws { BusinessError } 401 - Invalid parameter. 50 * @throws { BusinessError } 801 - Capability not supported. 51 * @syscap SystemCapability.Communication.Bluetooth.Core 52 * @since 10 53 */ 54 function createGattClientDevice(deviceId: string): GattClientDevice; 55 56 /** 57 * Obtains the list of devices in the connected status. 58 * 59 * @permission ohos.permission.ACCESS_BLUETOOTH 60 * @returns { Array<string> } Returns the list of device address. 61 * @throws { BusinessError } 201 - Permission denied. 62 * @throws { BusinessError } 801 - Capability not supported. 63 * @throws { BusinessError } 2900001 - Service stopped. 64 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 65 * @throws { BusinessError } 2900099 - Operation failed. 66 * @syscap SystemCapability.Communication.Bluetooth.Core 67 * @since 10 68 */ 69 function getConnectedBLEDevices(): Array<string>; 70 71 /** 72 * Starts scanning for specified BLE devices with filters. 73 * 74 * @permission ohos.permission.ACCESS_BLUETOOTH 75 * @param { Array<ScanFilter> } filters - Indicates the list of filters used to filter out specified devices. 76 * If you do not want to use filter, set this parameter to {@code null}. 77 * @param { ScanOptions } options - Indicates the parameters for scanning and if the user does not assign a value, the default value will be used. 78 * {@link ScanOptions#interval} set to 0, {@link ScanOptions#dutyMode} set to {@link SCAN_MODE_LOW_POWER} 79 * and {@link ScanOptions#matchMode} set to {@link MATCH_MODE_AGGRESSIVE}. 80 * @throws { BusinessError } 201 - Permission denied. 81 * @throws { BusinessError } 401 - Invalid parameter. 82 * @throws { BusinessError } 801 - Capability not supported. 83 * @throws { BusinessError } 2900001 - Service stopped. 84 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 85 * @throws { BusinessError } 2900099 - Operation failed. 86 * @syscap SystemCapability.Communication.Bluetooth.Core 87 * @since 10 88 */ 89 function startBLEScan(filters: Array<ScanFilter>, options?: ScanOptions): void; 90 91 /** 92 * Stops BLE scanning. 93 * 94 * @permission ohos.permission.ACCESS_BLUETOOTH 95 * @throws { BusinessError } 201 - Permission denied. 96 * @throws { BusinessError } 801 - Capability not supported. 97 * @throws { BusinessError } 2900001 - Service stopped. 98 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 99 * @throws { BusinessError } 2900099 - Operation failed. 100 * @syscap SystemCapability.Communication.Bluetooth.Core 101 * @since 10 102 */ 103 function stopBLEScan(): void; 104 105 /** 106 * Starts BLE advertising. 107 * 108 * @permission ohos.permission.ACCESS_BLUETOOTH 109 * @param { AdvertiseSetting } setting - Indicates the settings for BLE advertising. 110 * If you need to use the default value, set this parameter to {@code null}. 111 * @param { AdvertiseData } advData - Indicates the advertising data. 112 * @param { AdvertiseData } advResponse - Indicates the scan response associated with the advertising data. 113 * @throws { BusinessError } 201 - Permission denied. 114 * @throws { BusinessError } 401 - Invalid parameter. 115 * @throws { BusinessError } 801 - Capability not supported. 116 * @throws { BusinessError } 2900001 - Service stopped. 117 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 118 * @throws { BusinessError } 2900099 - Operation failed. 119 * @syscap SystemCapability.Communication.Bluetooth.Core 120 * @since 10 121 */ 122 function startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void; 123 124 /** 125 * Stops BLE advertising. 126 * 127 * @permission ohos.permission.ACCESS_BLUETOOTH 128 * @throws { BusinessError } 201 - Permission denied. 129 * @throws { BusinessError } 801 - Capability not supported. 130 * @throws { BusinessError } 2900001 - Service stopped. 131 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 132 * @throws { BusinessError } 2900099 - Operation failed. 133 * @syscap SystemCapability.Communication.Bluetooth.Core 134 * @since 10 135 */ 136 function stopAdvertising(): void; 137 138 /** 139 * Subscribe BLE scan result. 140 * 141 * @permission ohos.permission.ACCESS_BLUETOOTH 142 * @param { 'BLEDeviceFind' } type - Type of the scan result event to listen for. 143 * @param { Callback<Array<ScanResult>> } callback - Callback used to listen for the scan result event. 144 * @throws { BusinessError } 201 - Permission denied. 145 * @throws { BusinessError } 401 - Invalid parameter. 146 * @throws { BusinessError } 801 - Capability not supported. 147 * @throws { BusinessError } 2900099 - Operation failed. 148 * @syscap SystemCapability.Communication.Bluetooth.Core 149 * @since 10 150 */ 151 function on(type: 'BLEDeviceFind', callback: Callback<Array<ScanResult>>): void; 152 153 /** 154 * Unsubscribe BLE scan result. 155 * 156 * @permission ohos.permission.ACCESS_BLUETOOTH 157 * @param { 'BLEDeviceFind' } type - Type of the scan result event to listen for. 158 * @param { Callback<Array<ScanResult>> } callback - Callback used to listen for the scan result event. 159 * @throws { BusinessError } 201 - Permission denied. 160 * @throws { BusinessError } 401 - Invalid parameter. 161 * @throws { BusinessError } 801 - Capability not supported. 162 * @throws { BusinessError } 2900099 - Operation failed. 163 * @syscap SystemCapability.Communication.Bluetooth.Core 164 * @since 10 165 */ 166 function off(type: 'BLEDeviceFind', callback?: Callback<Array<ScanResult>>): void; 167 168 /** 169 * Manages GATT server. Before calling an Gatt server method, you must use {@link createGattServer} to create an GattServer instance. 170 * 171 * @typedef GattServer 172 * @syscap SystemCapability.Communication.Bluetooth.Core 173 * @since 10 174 */ 175 interface GattServer { 176 /** 177 * Adds a specified service to be hosted. 178 * <p>The added service and its characteristics are provided by the local device. 179 * 180 * @permission ohos.permission.ACCESS_BLUETOOTH 181 * @param { GattService } service - Indicates the service to add. 182 * @throws { BusinessError } 201 - Permission denied. 183 * @throws { BusinessError } 401 - Invalid parameter. 184 * @throws { BusinessError } 801 - Capability not supported. 185 * @throws { BusinessError } 2900001 - Service stopped. 186 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 187 * @throws { BusinessError } 2900099 - Operation failed. 188 * @syscap SystemCapability.Communication.Bluetooth.Core 189 * @since 10 190 */ 191 addService(service: GattService): void; 192 193 /** 194 * Removes a specified service from the list of GATT services provided by this device. 195 * 196 * @permission ohos.permission.ACCESS_BLUETOOTH 197 * @param { string } serviceUuid - Indicates the UUID of the service to remove. 198 * @throws { BusinessError } 201 - Permission denied. 199 * @throws { BusinessError } 401 - Invalid parameter. 200 * @throws { BusinessError } 801 - Capability not supported. 201 * @throws { BusinessError } 2900001 - Service stopped. 202 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 203 * @throws { BusinessError } 2900004 - Profile is not supported. 204 * @throws { BusinessError } 2900099 - Operation failed. 205 * @syscap SystemCapability.Communication.Bluetooth.Core 206 * @since 10 207 */ 208 removeService(serviceUuid: string): void; 209 210 /** 211 * Closes this {@code GattServer} object and unregisters its callbacks. 212 * 213 * @permission ohos.permission.ACCESS_BLUETOOTH 214 * @throws { BusinessError } 201 - Permission denied. 215 * @throws { BusinessError } 801 - Capability not supported. 216 * @throws { BusinessError } 2900001 - Service stopped. 217 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 218 * @throws { BusinessError } 2900099 - Operation failed. 219 * @syscap SystemCapability.Communication.Bluetooth.Core 220 * @since 10 221 */ 222 close(): void; 223 224 /** 225 * Sends a notification of a change in a specified local characteristic with a asynchronous callback. 226 * <p>This method should be called for every BLE peripheral device that has requested notifications. 227 * 228 * @permission ohos.permission.ACCESS_BLUETOOTH 229 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 230 * @param { NotifyCharacteristic } notifyCharacteristic - Indicates the local characteristic that has changed. 231 * @param { AsyncCallback<void> } callback - Callback used to return the result. 232 * @throws { BusinessError } 201 - Permission denied. 233 * @throws { BusinessError } 401 - Invalid parameter. 234 * @throws { BusinessError } 801 - Capability not supported. 235 * @throws { BusinessError } 2900001 - Service stopped. 236 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 237 * @throws { BusinessError } 2900099 - Operation failed. 238 * @syscap SystemCapability.Communication.Bluetooth.Core 239 * @since 10 240 */ 241 notifyCharacteristicChanged( 242 deviceId: string, 243 notifyCharacteristic: NotifyCharacteristic, 244 callback: AsyncCallback<void> 245 ): void; 246 247 /** 248 * Sends a notification of a change in a specified local characteristic with a asynchronous callback. 249 * <p>This method should be called for every BLE peripheral device that has requested notifications. 250 * 251 * @permission ohos.permission.ACCESS_BLUETOOTH 252 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 253 * @param { NotifyCharacteristic } notifyCharacteristic - Indicates the local characteristic that has changed. 254 * @returns { Promise<void> } Promise used to return the result. 255 * @throws { BusinessError } 201 - Permission denied. 256 * @throws { BusinessError } 401 - Invalid parameter. 257 * @throws { BusinessError } 801 - Capability not supported. 258 * @throws { BusinessError } 2900001 - Service stopped. 259 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 260 * @throws { BusinessError } 2900099 - Operation failed. 261 * @syscap SystemCapability.Communication.Bluetooth.Core 262 * @since 10 263 */ 264 notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): Promise<void>; 265 266 /** 267 * Sends a response to a specified read or write request to a given BLE peripheral device. 268 * 269 * @permission ohos.permission.ACCESS_BLUETOOTH 270 * @param { ServerResponse } serverResponse - Indicates the response parameters {@link ServerResponse}. 271 * @throws { BusinessError } 201 - Permission denied. 272 * @throws { BusinessError } 401 - Invalid parameter. 273 * @throws { BusinessError } 801 - Capability not supported. 274 * @throws { BusinessError } 2900001 - Service stopped. 275 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 276 * @throws { BusinessError } 2900099 - Operation failed. 277 * @syscap SystemCapability.Communication.Bluetooth.Core 278 * @since 10 279 */ 280 sendResponse(serverResponse: ServerResponse): void; 281 282 /** 283 * Subscribe characteristic read event. 284 * 285 * @permission ohos.permission.ACCESS_BLUETOOTH 286 * @param { 'characteristicRead' } type - Type of the characteristic read event to listen for. 287 * @param { Callback<CharacteristicReadRequest> } callback - Callback used to listen for the characteristic read event. 288 * @throws { BusinessError } 201 - Permission denied. 289 * @throws { BusinessError } 401 - Invalid parameter. 290 * @throws { BusinessError } 801 - Capability not supported. 291 * @syscap SystemCapability.Communication.Bluetooth.Core 292 * @since 10 293 */ 294 on(type: 'characteristicRead', callback: Callback<CharacteristicReadRequest>): void; 295 296 /** 297 * Unsubscribe characteristic read event. 298 * 299 * @permission ohos.permission.ACCESS_BLUETOOTH 300 * @param { 'characteristicRead' } type - Type of the characteristic read event to listen for. 301 * @param { Callback<CharacteristicReadRequest> } callback - Callback used to listen for the characteristic read event. 302 * @throws { BusinessError } 201 - Permission denied. 303 * @throws { BusinessError } 401 - Invalid parameter. 304 * @throws { BusinessError } 801 - Capability not supported. 305 * @syscap SystemCapability.Communication.Bluetooth.Core 306 * @since 10 307 */ 308 off(type: 'characteristicRead', callback?: Callback<CharacteristicReadRequest>): void; 309 310 /** 311 * Subscribe characteristic write event. 312 * 313 * @permission ohos.permission.ACCESS_BLUETOOTH 314 * @param { 'characteristicWrite' } type - Type of the characteristic write event to listen for. 315 * @param { Callback<CharacteristicWriteRequest> } callback - Callback used to listen for the characteristic write event. 316 * @throws { BusinessError } 201 - Permission denied. 317 * @throws { BusinessError } 401 - Invalid parameter. 318 * @throws { BusinessError } 801 - Capability not supported. 319 * @syscap SystemCapability.Communication.Bluetooth.Core 320 * @since 10 321 */ 322 on(type: 'characteristicWrite', callback: Callback<CharacteristicWriteRequest>): void; 323 324 /** 325 * Unsubscribe characteristic write event. 326 * 327 * @permission ohos.permission.ACCESS_BLUETOOTH 328 * @param { 'characteristicWrite' } type - Type of the characteristic write event to listen for. 329 * @param { Callback<CharacteristicWriteRequest> } callback - Callback used to listen for the characteristic write event. 330 * @throws { BusinessError } 201 - Permission denied. 331 * @throws { BusinessError } 401 - Invalid parameter. 332 * @throws { BusinessError } 801 - Capability not supported. 333 * @syscap SystemCapability.Communication.Bluetooth.Core 334 * @since 10 335 */ 336 off(type: 'characteristicWrite', callback?: Callback<CharacteristicWriteRequest>): void; 337 338 /** 339 * Subscribe descriptor read event. 340 * 341 * @permission ohos.permission.ACCESS_BLUETOOTH 342 * @param { 'descriptorRead' } type - Type of the descriptor read event to listen for. 343 * @param { Callback<DescriptorReadRequest> } callback - Callback used to listen for the descriptor read event. 344 * @throws { BusinessError } 201 - Permission denied. 345 * @throws { BusinessError } 401 - Invalid parameter. 346 * @throws { BusinessError } 801 - Capability not supported. 347 * @syscap SystemCapability.Communication.Bluetooth.Core 348 * @since 10 349 */ 350 on(type: 'descriptorRead', callback: Callback<DescriptorReadRequest>): void; 351 352 /** 353 * Unsubscribe descriptor read event. 354 * 355 * @permission ohos.permission.ACCESS_BLUETOOTH 356 * @param { 'descriptorRead' } type - Type of the descriptor read event to listen for. 357 * @param { Callback<DescriptorReadRequest> } callback - Callback used to listen for the descriptor read event. 358 * @throws { BusinessError } 201 - Permission denied. 359 * @throws { BusinessError } 401 - Invalid parameter. 360 * @throws { BusinessError } 801 - Capability not supported. 361 * @syscap SystemCapability.Communication.Bluetooth.Core 362 * @since 10 363 */ 364 off(type: 'descriptorRead', callback?: Callback<DescriptorReadRequest>): void; 365 366 /** 367 * Subscribe descriptor write event. 368 * 369 * @permission ohos.permission.ACCESS_BLUETOOTH 370 * @param { 'descriptorWrite' } type - Type of the descriptor write event to listen for. 371 * @param { Callback<DescriptorWriteRequest> } callback - Callback used to listen for the descriptor write event. 372 * @throws { BusinessError } 201 - Permission denied. 373 * @throws { BusinessError } 401 - Invalid parameter. 374 * @throws { BusinessError } 801 - Capability not supported. 375 * @syscap SystemCapability.Communication.Bluetooth.Core 376 * @since 10 377 */ 378 on(type: 'descriptorWrite', callback: Callback<DescriptorWriteRequest>): void; 379 380 /** 381 * Unsubscribe descriptor write event. 382 * 383 * @permission ohos.permission.ACCESS_BLUETOOTH 384 * @param { 'descriptorWrite' } type - Type of the descriptor write event to listen for. 385 * @param { Callback<DescriptorWriteRequest> } callback - Callback used to listen for the descriptor write event. 386 * @throws { BusinessError } 201 - Permission denied. 387 * @throws { BusinessError } 401 - Invalid parameter. 388 * @throws { BusinessError } 801 - Capability not supported. 389 * @syscap SystemCapability.Communication.Bluetooth.Core 390 * @since 10 391 */ 392 off(type: 'descriptorWrite', callback?: Callback<DescriptorWriteRequest>): void; 393 394 /** 395 * Subscribe server connection state changed event. 396 * 397 * @permission ohos.permission.ACCESS_BLUETOOTH 398 * @param { 'connectionStateChange' } type - Type of the connection state changed event to listen for. 399 * @param { Callback<BLEConnectionChangeState> } callback - Callback used to listen for the connection state changed event. 400 * @throws { BusinessError } 201 - Permission denied. 401 * @throws { BusinessError } 401 - Invalid parameter. 402 * @throws { BusinessError } 801 - Capability not supported. 403 * @syscap SystemCapability.Communication.Bluetooth.Core 404 * @since 10 405 */ 406 on(type: 'connectionStateChange', callback: Callback<BLEConnectionChangeState>): void; 407 408 /** 409 * Unsubscribe server connection state changed event. 410 * 411 * @permission ohos.permission.ACCESS_BLUETOOTH 412 * @param { 'connectionStateChange' } type - Type of the connection state changed event to listen for. 413 * @param { Callback<BLEConnectionChangeState> } callback - Callback used to listen for the connection state changed event. 414 * @throws { BusinessError } 201 - Permission denied. 415 * @throws { BusinessError } 401 - Invalid parameter. 416 * @throws { BusinessError } 801 - Capability not supported. 417 * @syscap SystemCapability.Communication.Bluetooth.Core 418 * @since 10 419 */ 420 off(type: 'connectionStateChange', callback?: Callback<BLEConnectionChangeState>): void; 421 422 /** 423 * Subscribe mtu changed event. 424 * 425 * @permission ohos.permission.ACCESS_BLUETOOTH 426 * @param { 'BLEMtuChange' } type - Type of the mtu changed event to listen for. 427 * @param { Callback<number> } callback - Callback used to listen for the mtu changed event. 428 * @throws { BusinessError } 201 - Permission denied. 429 * @throws { BusinessError } 401 - Invalid parameter. 430 * @throws { BusinessError } 801 - Capability not supported. 431 * @syscap SystemCapability.Communication.Bluetooth.Core 432 * @since 10 433 */ 434 on(type: 'BLEMtuChange', callback: Callback<number>): void; 435 436 /** 437 * Unsubscribe mtu changed event. 438 * 439 * @permission ohos.permission.ACCESS_BLUETOOTH 440 * @param { 'BLEMtuChange' } type - Type of the mtu changed event to listen for. 441 * @param { Callback<number> } callback - Callback used to listen for the mtu changed event. 442 * @throws { BusinessError } 201 - Permission denied. 443 * @throws { BusinessError } 401 - Invalid parameter. 444 * @throws { BusinessError } 801 - Capability not supported. 445 * @syscap SystemCapability.Communication.Bluetooth.Core 446 * @since 10 447 */ 448 off(type: 'BLEMtuChange', callback?: Callback<number>): void; 449 } 450 451 /** 452 * Manages GATT client. Before calling an Gatt client method, you must use {@link createGattClientDevice} to create an GattClientDevice instance. 453 * 454 * @typedef GattClientDevice 455 * @syscap SystemCapability.Communication.Bluetooth.Core 456 * @since 10 457 */ 458 interface GattClientDevice { 459 /** 460 * Connects to a BLE peripheral device. 461 * <p>The 'BLEConnectionStateChange' event is subscribed to return the connection state. 462 * 463 * @permission ohos.permission.ACCESS_BLUETOOTH 464 * @throws { BusinessError } 201 - Permission denied. 465 * @throws { BusinessError } 801 - Capability not supported. 466 * @throws { BusinessError } 2900001 - Service stopped. 467 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 468 * @throws { BusinessError } 2900099 - Operation failed. 469 * @syscap SystemCapability.Communication.Bluetooth.Core 470 * @since 10 471 */ 472 connect(): void; 473 474 /** 475 * Disconnects from or stops an ongoing connection to a BLE peripheral device. 476 * 477 * @permission ohos.permission.ACCESS_BLUETOOTH 478 * @throws { BusinessError } 201 - Permission denied. 479 * @throws { BusinessError } 801 - Capability not supported. 480 * @throws { BusinessError } 2900001 - Service stopped. 481 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 482 * @throws { BusinessError } 2900099 - Operation failed. 483 * @syscap SystemCapability.Communication.Bluetooth.Core 484 * @since 10 485 */ 486 disconnect(): void; 487 488 /** 489 * Disables a BLE peripheral device. 490 * <p> This method unregisters the device and clears the registered callbacks and handles. 491 * 492 * @permission ohos.permission.ACCESS_BLUETOOTH 493 * @throws { BusinessError } 201 - Permission denied. 494 * @throws { BusinessError } 801 - Capability not supported. 495 * @throws { BusinessError } 2900001 - Service stopped. 496 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 497 * @throws { BusinessError } 2900099 - Operation failed. 498 * @syscap SystemCapability.Communication.Bluetooth.Core 499 * @since 10 500 */ 501 close(): void; 502 503 /** 504 * Obtains the name of BLE peripheral device. 505 * 506 * @permission ohos.permission.ACCESS_BLUETOOTH 507 * @param { AsyncCallback<string> } callback - Callback used to obtain the device name. 508 * @throws { BusinessError } 201 - Permission denied. 509 * @throws { BusinessError } 401 - Invalid parameter. 510 * @throws { BusinessError } 801 - Capability not supported. 511 * @throws { BusinessError } 2900001 - Service stopped. 512 * @throws { BusinessError } 2900099 - Operation failed. 513 * @syscap SystemCapability.Communication.Bluetooth.Core 514 * @since 10 515 */ 516 getDeviceName(callback: AsyncCallback<string>): void; 517 518 /** 519 * Obtains the name of BLE peripheral device. 520 * 521 * @permission ohos.permission.ACCESS_BLUETOOTH 522 * @returns { Promise<string> } Returns a string representation of the name if obtained; 523 * returns {@code null} if the name fails to be obtained or the name does not exist. 524 * @throws { BusinessError } 201 - Permission denied. 525 * @throws { BusinessError } 401 - Invalid parameter. 526 * @throws { BusinessError } 801 - Capability not supported. 527 * @throws { BusinessError } 2900001 - Service stopped. 528 * @throws { BusinessError } 2900099 - Operation failed. 529 * @syscap SystemCapability.Communication.Bluetooth.Core 530 * @since 10 531 */ 532 getDeviceName(): Promise<string>; 533 534 /** 535 * Starts discovering services. 536 * 537 * @permission ohos.permission.ACCESS_BLUETOOTH 538 * @param { AsyncCallback<Array<GattService>> } callback - Callback used to catch the services. 539 * @throws { BusinessError } 201 - Permission denied. 540 * @throws { BusinessError } 401 - Invalid parameter. 541 * @throws { BusinessError } 801 - Capability not supported. 542 * @throws { BusinessError } 2900001 - Service stopped. 543 * @throws { BusinessError } 2900099 - Operation failed. 544 * @syscap SystemCapability.Communication.Bluetooth.Core 545 * @since 10 546 */ 547 getServices(callback: AsyncCallback<Array<GattService>>): void; 548 549 /** 550 * Starts discovering services. 551 * 552 * @permission ohos.permission.ACCESS_BLUETOOTH 553 * @returns { Promise<Array<GattService>> } Returns the list of services {@link GattService} of the BLE peripheral device. 554 * @throws { BusinessError } 201 - Permission denied. 555 * @throws { BusinessError } 401 - Invalid parameter. 556 * @throws { BusinessError } 801 - Capability not supported. 557 * @throws { BusinessError } 2900001 - Service stopped. 558 * @throws { BusinessError } 2900099 - Operation failed. 559 * @syscap SystemCapability.Communication.Bluetooth.Core 560 * @since 10 561 */ 562 getServices(): Promise<Array<GattService>>; 563 564 /** 565 * Reads the characteristic of a BLE peripheral device. 566 * 567 * @permission ohos.permission.ACCESS_BLUETOOTH 568 * @param { BLECharacteristic } characteristic - Indicates the characteristic to read. 569 * @param { AsyncCallback<BLECharacteristic> } callback - Callback invoked to return the characteristic value read. 570 * @throws { BusinessError } 201 - Permission denied. 571 * @throws { BusinessError } 401 - Invalid parameter. 572 * @throws { BusinessError } 801 - Capability not supported. 573 * @throws { BusinessError } 2900001 - Service stopped. 574 * @throws { BusinessError } 2901000 - Read forbidden. 575 * @throws { BusinessError } 2900099 - Operation failed. 576 * @syscap SystemCapability.Communication.Bluetooth.Core 577 * @since 10 578 */ 579 readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback<BLECharacteristic>): void; 580 581 /** 582 * Reads the characteristic of a BLE peripheral device. 583 * 584 * @permission ohos.permission.ACCESS_BLUETOOTH 585 * @param { BLECharacteristic } characteristic - Indicates the characteristic to read. 586 * @returns { Promise<BLECharacteristic> } - Promise used to return the characteristic value read. 587 * @throws { BusinessError } 201 - Permission denied. 588 * @throws { BusinessError } 401 - Invalid parameter. 589 * @throws { BusinessError } 801 - Capability not supported. 590 * @throws { BusinessError } 2900001 - Service stopped. 591 * @throws { BusinessError } 2901000 - Read forbidden. 592 * @throws { BusinessError } 2900099 - Operation failed. 593 * @syscap SystemCapability.Communication.Bluetooth.Core 594 * @since 10 595 */ 596 readCharacteristicValue(characteristic: BLECharacteristic): Promise<BLECharacteristic>; 597 598 /** 599 * Reads the descriptor of a BLE peripheral device. 600 * 601 * @permission ohos.permission.ACCESS_BLUETOOTH 602 * @param { BLEDescriptor } descriptor - Indicates the descriptor to read. 603 * @param { AsyncCallback<BLEDescriptor> } callback - Callback invoked to return the descriptor read. 604 * @throws { BusinessError } 201 - Permission denied. 605 * @throws { BusinessError } 401 - Invalid parameter. 606 * @throws { BusinessError } 801 - Capability not supported. 607 * @throws { BusinessError } 2900001 - Service stopped. 608 * @throws { BusinessError } 2901000 - Read forbidden. 609 * @throws { BusinessError } 2900099 - Operation failed. 610 * @syscap SystemCapability.Communication.Bluetooth.Core 611 * @since 10 612 */ 613 readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback<BLEDescriptor>): void; 614 615 /** 616 * Reads the descriptor of a BLE peripheral device. 617 * 618 * @permission ohos.permission.ACCESS_BLUETOOTH 619 * @param { BLEDescriptor } descriptor - Indicates the descriptor to read. 620 * @returns { Promise<BLEDescriptor> } - Promise used to return the descriptor read. 621 * @throws { BusinessError } 201 - Permission denied. 622 * @throws { BusinessError } 401 - Invalid parameter. 623 * @throws { BusinessError } 801 - Capability not supported. 624 * @throws { BusinessError } 2900001 - Service stopped. 625 * @throws { BusinessError } 2901000 - Read forbidden. 626 * @throws { BusinessError } 2900099 - Operation failed. 627 * @syscap SystemCapability.Communication.Bluetooth.Core 628 * @since 10 629 */ 630 readDescriptorValue(descriptor: BLEDescriptor): Promise<BLEDescriptor>; 631 632 /** 633 * Writes the characteristic of a BLE peripheral device. 634 * 635 * @permission ohos.permission.ACCESS_BLUETOOTH 636 * @param { BLECharacteristic } characteristic - Indicates the characteristic to write. 637 * @param { GattWriteType } writeType - Write type of the characteristic. 638 * @param { AsyncCallback<void> } callback - Callback used to return the result. 639 * @throws { BusinessError } 201 - Permission denied. 640 * @throws { BusinessError } 401 - Invalid parameter. 641 * @throws { BusinessError } 801 - Capability not supported. 642 * @throws { BusinessError } 2900001 - Service stopped. 643 * @throws { BusinessError } 2901001 - Write forbidden. 644 * @throws { BusinessError } 2900099 - Operation failed. 645 * @syscap SystemCapability.Communication.Bluetooth.Core 646 * @since 10 647 */ 648 writeCharacteristicValue( 649 characteristic: BLECharacteristic, 650 writeType: GattWriteType, 651 callback: AsyncCallback<void> 652 ): void; 653 654 /** 655 * Writes the characteristic of a BLE peripheral device. 656 * 657 * @permission ohos.permission.ACCESS_BLUETOOTH 658 * @param { BLECharacteristic } characteristic - Indicates the characteristic to write. 659 * @param { GattWriteType } writeType - Write type of the characteristic. 660 * @returns { Promise<void> } Promise used to return the result. 661 * @throws { BusinessError } 201 - Permission denied. 662 * @throws { BusinessError } 401 - Invalid parameter. 663 * @throws { BusinessError } 801 - Capability not supported. 664 * @throws { BusinessError } 2900001 - Service stopped. 665 * @throws { BusinessError } 2901001 - Write forbidden. 666 * @throws { BusinessError } 2900099 - Operation failed. 667 * @syscap SystemCapability.Communication.Bluetooth.Core 668 * @since 10 669 */ 670 writeCharacteristicValue(characteristic: BLECharacteristic, writeType: GattWriteType): Promise<void>; 671 672 /** 673 * Writes the descriptor of a BLE peripheral device. 674 * 675 * @permission ohos.permission.ACCESS_BLUETOOTH 676 * @param { BLEDescriptor } descriptor - Indicates the descriptor to write. 677 * @param { AsyncCallback<void> } callback - Callback used to return the result. 678 * @throws { BusinessError } 201 - Permission denied. 679 * @throws { BusinessError } 401 - Invalid parameter. 680 * @throws { BusinessError } 801 - Capability not supported. 681 * @throws { BusinessError } 2900001 - Service stopped. 682 * @throws { BusinessError } 2901001 - Write forbidden. 683 * @throws { BusinessError } 2900099 - Operation failed. 684 * @syscap SystemCapability.Communication.Bluetooth.Core 685 * @since 10 686 */ 687 writeDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback<void>): void; 688 689 /** 690 * Writes the descriptor of a BLE peripheral device. 691 * 692 * @permission ohos.permission.ACCESS_BLUETOOTH 693 * @param { BLEDescriptor } descriptor - Indicates the descriptor to write. 694 * @returns { Promise<void> } Promise used to return the result. 695 * @throws { BusinessError } 201 - Permission denied. 696 * @throws { BusinessError } 401 - Invalid parameter. 697 * @throws { BusinessError } 801 - Capability not supported. 698 * @throws { BusinessError } 2900001 - Service stopped. 699 * @throws { BusinessError } 2901001 - Write forbidden. 700 * @throws { BusinessError } 2900099 - Operation failed. 701 * @syscap SystemCapability.Communication.Bluetooth.Core 702 * @since 10 703 */ 704 writeDescriptorValue(descriptor: BLEDescriptor): Promise<void>; 705 706 /** 707 * Get the RSSI value of this BLE peripheral device. 708 * 709 * @permission ohos.permission.ACCESS_BLUETOOTH 710 * @param { AsyncCallback<number> } callback - Callback invoked to return the RSSI, in dBm. 711 * @throws { BusinessError } 201 - Permission denied. 712 * @throws { BusinessError } 401 - Invalid parameter. 713 * @throws { BusinessError } 801 - Capability not supported. 714 * @throws { BusinessError } 2900099 - Operation failed. 715 * @syscap SystemCapability.Communication.Bluetooth.Core 716 * @since 10 717 */ 718 getRssiValue(callback: AsyncCallback<number>): void; 719 720 /** 721 * Get the RSSI value of this BLE peripheral device. 722 * 723 * @permission ohos.permission.ACCESS_BLUETOOTH 724 * @returns { Promise<number> } Returns the RSSI value. 725 * @throws { BusinessError } 201 - Permission denied. 726 * @throws { BusinessError } 401 - Invalid parameter. 727 * @throws { BusinessError } 801 - Capability not supported. 728 * @throws { BusinessError } 2900099 - Operation failed. 729 * @syscap SystemCapability.Communication.Bluetooth.Core 730 * @since 10 731 */ 732 getRssiValue(): Promise<number>; 733 734 /** 735 * Set the mtu size of a BLE peripheral device. 736 * 737 * @permission ohos.permission.ACCESS_BLUETOOTH 738 * @param { number } mtu - The maximum transmission unit. 739 * @throws { BusinessError } 201 - Permission denied. 740 * @throws { BusinessError } 401 - Invalid parameter. 741 * @throws { BusinessError } 801 - Capability not supported. 742 * @throws { BusinessError } 2900001 - Service stopped. 743 * @throws { BusinessError } 2900099 - Operation failed. 744 * @syscap SystemCapability.Communication.Bluetooth.Core 745 * @since 10 746 */ 747 setBLEMtuSize(mtu: number): void; 748 749 /** 750 * Enables or disables notification of a characteristic when value changed. 751 * 752 * @permission ohos.permission.ACCESS_BLUETOOTH 753 * @param { BLECharacteristic } characteristic - Indicates the characteristic to indicate. 754 * @param { boolean } enable - Specifies whether to enable indication of the characteristic. The value {@code true} indicates 755 * that notification is enabled, and the value {@code false} indicates that indication is disabled. 756 * @param { AsyncCallback<void> } callback - the callback of setCharacteristicChangeNotification. 757 * @throws { BusinessError } 201 - Permission denied. 758 * @throws { BusinessError } 401 - Invalid parameter. 759 * @throws { BusinessError } 801 - Capability not supported. 760 * @throws { BusinessError } 2900001 - Service stopped. 761 * @throws { BusinessError } 2900099 - Operation failed. 762 * @syscap SystemCapability.Communication.Bluetooth.Core 763 * @since 10 764 */ 765 setCharacteristicChangeNotification( 766 characteristic: BLECharacteristic, 767 enable: boolean, 768 callback: AsyncCallback<void> 769 ): void; 770 771 /** 772 * Enables or disables indication of a characteristic when value changed. 773 * 774 * @permission ohos.permission.ACCESS_BLUETOOTH 775 * @param { BLECharacteristic } characteristic - Indicates the characteristic to indicate. 776 * @param { boolean } enable - Specifies whether to enable indication of the characteristic. The value {@code true} indicates 777 * that indication is enabled, and the value {@code false} indicates that indication is disabled. 778 * @returns { Promise<void> } Returns the promise object. 779 * @throws { BusinessError } 201 - Permission denied. 780 * @throws { BusinessError } 401 - Invalid parameter. 781 * @throws { BusinessError } 801 - Capability not supported. 782 * @throws { BusinessError } 2900001 - Service stopped. 783 * @throws { BusinessError } 2900099 - Operation failed. 784 * @syscap SystemCapability.Communication.Bluetooth.Core 785 * @since 10 786 */ 787 setCharacteristicChangeNotification(characteristic: BLECharacteristic, enable: boolean): Promise<void>; 788 789 /** 790 * Enables or disables indication of a characteristic when value changed. 791 * 792 * @permission ohos.permission.ACCESS_BLUETOOTH 793 * @param { BLECharacteristic } characteristic - Indicates the characteristic to indicate. 794 * @param { boolean } enable - Specifies whether to enable indication of the characteristic. The value {@code true} indicates 795 * that indication is enabled, and the value {@code false} indicates that indication is disabled. 796 * @param { AsyncCallback<void> } callback - the callback of setCharacteristicChangeIndication. 797 * @throws { BusinessError } 201 - Permission denied. 798 * @throws { BusinessError } 401 - Invalid parameter. 799 * @throws { BusinessError } 801 - Capability not supported. 800 * @throws { BusinessError } 2900001 - Service stopped. 801 * @throws { BusinessError } 2900099 - Operation failed. 802 * @syscap SystemCapability.Communication.Bluetooth.Core 803 * @since 10 804 */ 805 setCharacteristicChangeIndication( 806 characteristic: BLECharacteristic, 807 enable: boolean, 808 callback: AsyncCallback<void> 809 ): void; 810 811 /** 812 * Enables or disables indication of a characteristic when value changed. 813 * 814 * @permission ohos.permission.ACCESS_BLUETOOTH 815 * @param { BLECharacteristic } characteristic - Indicates the characteristic to indicate. 816 * @param { boolean } enable - Specifies whether to enable indication of the characteristic. The value {@code true} indicates 817 * that indication is enabled, and the value {@code false} indicates that indication is disabled. 818 * @returns { Promise<void> } Returns the promise object. 819 * @throws { BusinessError } 201 - Permission denied. 820 * @throws { BusinessError } 401 - Invalid parameter. 821 * @throws { BusinessError } 801 - Capability not supported. 822 * @throws { BusinessError } 2900001 - Service stopped. 823 * @throws { BusinessError } 2900099 - Operation failed. 824 * @syscap SystemCapability.Communication.Bluetooth.Core 825 * @since 10 826 */ 827 setCharacteristicChangeIndication(characteristic: BLECharacteristic, enable: boolean): Promise<void>; 828 829 /** 830 * Subscribe characteristic value changed event. 831 * 832 * @permission ohos.permission.ACCESS_BLUETOOTH 833 * @param { 'BLECharacteristicChange' } type - Type of the characteristic value changed event to listen for. 834 * @param { Callback<BLECharacteristic> } callback - Callback used to listen for the characteristic value changed event. 835 * @throws { BusinessError } 201 - Permission denied. 836 * @throws { BusinessError } 401 - Invalid parameter. 837 * @throws { BusinessError } 801 - Capability not supported. 838 * @syscap SystemCapability.Communication.Bluetooth.Core 839 * @since 10 840 */ 841 on(type: 'BLECharacteristicChange', callback: Callback<BLECharacteristic>): void; 842 843 /** 844 * Unsubscribe characteristic value changed event. 845 * 846 * @permission ohos.permission.ACCESS_BLUETOOTH 847 * @param { 'BLECharacteristicChange' } type - Type of the characteristic value changed event to listen for. 848 * @param { Callback<BLECharacteristic> } callback - Callback used to listen for the characteristic value changed event. 849 * @throws { BusinessError } 201 - Permission denied. 850 * @throws { BusinessError } 401 - Invalid parameter. 851 * @throws { BusinessError } 801 - Capability not supported. 852 * @syscap SystemCapability.Communication.Bluetooth.Core 853 * @since 10 854 */ 855 off(type: 'BLECharacteristicChange', callback?: Callback<BLECharacteristic>): void; 856 857 /** 858 * Subscribe client connection state changed event. 859 * 860 * @permission ohos.permission.ACCESS_BLUETOOTH 861 * @param { 'BLEConnectionStateChange' } type - Type of the connection state changed event to listen for. 862 * @param { Callback<BLEConnectionChangeState> } callback - Callback used to listen for the connection state changed event. 863 * @throws { BusinessError } 201 - Permission denied. 864 * @throws { BusinessError } 401 - Invalid parameter. 865 * @throws { BusinessError } 801 - Capability not supported. 866 * @syscap SystemCapability.Communication.Bluetooth.Core 867 * @since 10 868 */ 869 on(type: 'BLEConnectionStateChange', callback: Callback<BLEConnectionChangeState>): void; 870 871 /** 872 * Unsubscribe client connection state changed event. 873 * 874 * @permission ohos.permission.ACCESS_BLUETOOTH 875 * @param { 'BLEConnectionStateChange' } type - Type of the connection state changed event to listen for. 876 * @param { Callback<BLEConnectionChangeState> } callback - Callback used to listen for the connection state changed event. 877 * @throws { BusinessError } 201 - Permission denied. 878 * @throws { BusinessError } 401 - Invalid parameter. 879 * @throws { BusinessError } 801 - Capability not supported. 880 * @syscap SystemCapability.Communication.Bluetooth.Core 881 * @since 10 882 */ 883 off(type: 'BLEConnectionStateChange', callback?: Callback<BLEConnectionChangeState>): void; 884 885 /** 886 * Subscribe mtu changed event. 887 * 888 * @permission ohos.permission.ACCESS_BLUETOOTH 889 * @param { 'BLEMtuChange' } type - Type of the mtu changed event to listen for. 890 * @param { Callback<number> } callback - Callback used to listen for the mtu changed event. 891 * @throws { BusinessError } 201 - Permission denied. 892 * @throws { BusinessError } 401 - Invalid parameter. 893 * @throws { BusinessError } 801 - Capability not supported. 894 * @syscap SystemCapability.Communication.Bluetooth.Core 895 * @since 10 896 */ 897 on(type: 'BLEMtuChange', callback: Callback<number>): void; 898 899 /** 900 * Unsubscribe mtu changed event. 901 * 902 * @permission ohos.permission.ACCESS_BLUETOOTH 903 * @param { 'BLEMtuChange' } type - Type of the mtu changed event to listen for. 904 * @param { Callback<number> } callback - Callback used to listen for the mtu changed event. 905 * @throws { BusinessError } 201 - Permission denied. 906 * @throws { BusinessError } 401 - Invalid parameter. 907 * @throws { BusinessError } 801 - Capability not supported. 908 * @syscap SystemCapability.Communication.Bluetooth.Core 909 * @since 10 910 */ 911 off(type: 'BLEMtuChange', callback?: Callback<number>): void; 912 } 913 914 /** 915 * Describes the Gatt service. 916 * 917 * @typedef GattService 918 * @syscap SystemCapability.Communication.Bluetooth.Core 919 * @since 10 920 */ 921 interface GattService { 922 /** 923 * The UUID of a GattService instance 924 * 925 * @syscap SystemCapability.Communication.Bluetooth.Core 926 * @since 10 927 */ 928 serviceUuid: string; 929 /** 930 * Indicates whether the GattService instance is primary or secondary. 931 * 932 * @syscap SystemCapability.Communication.Bluetooth.Core 933 * @since 10 934 */ 935 isPrimary: boolean; 936 /** 937 * The {@link BLECharacteristic} list belongs to this GattService instance 938 * 939 * @syscap SystemCapability.Communication.Bluetooth.Core 940 * @since 10 941 */ 942 characteristics: Array<BLECharacteristic>; 943 /** 944 * The list of GATT services contained in the service 945 * 946 * @syscap SystemCapability.Communication.Bluetooth.Core 947 * @since 10 948 */ 949 includeServices?: Array<GattService>; 950 } 951 952 /** 953 * Describes the Gatt characteristic. 954 * 955 * @typedef BLECharacteristic 956 * @syscap SystemCapability.Communication.Bluetooth.Core 957 * @since 10 958 */ 959 interface BLECharacteristic { 960 /** 961 * The UUID of the {@link GattService} instance to which the characteristic belongs 962 * 963 * @syscap SystemCapability.Communication.Bluetooth.Core 964 * @since 10 965 */ 966 serviceUuid: string; 967 /** 968 * The UUID of a BLECharacteristic instance 969 * 970 * @syscap SystemCapability.Communication.Bluetooth.Core 971 * @since 10 972 */ 973 characteristicUuid: string; 974 /** 975 * The value of a BLECharacteristic instance 976 * 977 * @syscap SystemCapability.Communication.Bluetooth.Core 978 * @since 10 979 */ 980 characteristicValue: ArrayBuffer; 981 /** 982 * The list of {@link BLEDescriptor} contained in the characteristic 983 * 984 * @syscap SystemCapability.Communication.Bluetooth.Core 985 * @since 10 986 */ 987 descriptors: Array<BLEDescriptor>; 988 /** 989 * The properties of a BLECharacteristic instance 990 * 991 * @syscap SystemCapability.Communication.Bluetooth.Core 992 * @since 10 993 */ 994 properties?: GattProperties; 995 } 996 997 /** 998 * Describes the Gatt descriptor. 999 * 1000 * @typedef BLEDescriptor 1001 * @syscap SystemCapability.Communication.Bluetooth.Core 1002 * @since 10 1003 */ 1004 interface BLEDescriptor { 1005 /** 1006 * The UUID of the {@link GattService} instance to which the descriptor belongs 1007 * 1008 * @syscap SystemCapability.Communication.Bluetooth.Core 1009 * @since 10 1010 */ 1011 serviceUuid: string; 1012 /** 1013 * The UUID of the {@link BLECharacteristic} instance to which the descriptor belongs 1014 * 1015 * @syscap SystemCapability.Communication.Bluetooth.Core 1016 * @since 10 1017 */ 1018 characteristicUuid: string; 1019 /** 1020 * The UUID of the BLEDescriptor instance 1021 * 1022 * @syscap SystemCapability.Communication.Bluetooth.Core 1023 * @since 10 1024 */ 1025 descriptorUuid: string; 1026 /** 1027 * The value of the BLEDescriptor instance 1028 * 1029 * @syscap SystemCapability.Communication.Bluetooth.Core 1030 * @since 10 1031 */ 1032 descriptorValue: ArrayBuffer; 1033 } 1034 1035 /** 1036 * Describes the value of the indication or notification sent by the Gatt server. 1037 * 1038 * @typedef NotifyCharacteristic 1039 * @syscap SystemCapability.Communication.Bluetooth.Core 1040 * @since 10 1041 */ 1042 interface NotifyCharacteristic { 1043 /** 1044 * The UUID of the {@link GattService} instance to which the characteristic belongs 1045 * 1046 * @syscap SystemCapability.Communication.Bluetooth.Core 1047 * @since 10 1048 */ 1049 serviceUuid: string; 1050 /** 1051 * The UUID of a NotifyCharacteristic instance 1052 * 1053 * @syscap SystemCapability.Communication.Bluetooth.Core 1054 * @since 10 1055 */ 1056 characteristicUuid: string; 1057 /** 1058 * The value of a NotifyCharacteristic instance 1059 * 1060 * @syscap SystemCapability.Communication.Bluetooth.Core 1061 * @since 10 1062 */ 1063 characteristicValue: ArrayBuffer; 1064 /** 1065 * Specifies whether to request confirmation from the BLE peripheral device (indication) or 1066 * send a notification. Value {@code true} indicates the former and {@code false} indicates the latter. 1067 * 1068 * @syscap SystemCapability.Communication.Bluetooth.Core 1069 * @since 10 1070 */ 1071 confirm: boolean; 1072 } 1073 1074 /** 1075 * Describes the parameters of the Gatt client's characteristic read request. 1076 * 1077 * @typedef CharacteristicReadRequest 1078 * @syscap SystemCapability.Communication.Bluetooth.Core 1079 * @since 10 1080 */ 1081 interface CharacteristicReadRequest { 1082 /** 1083 * Indicates the address of the client that initiates the read request 1084 * 1085 * @syscap SystemCapability.Communication.Bluetooth.Core 1086 * @since 10 1087 */ 1088 deviceId: string; 1089 /** 1090 * The Id of the read request 1091 * 1092 * @syscap SystemCapability.Communication.Bluetooth.Core 1093 * @since 10 1094 */ 1095 transId: number; 1096 /** 1097 * Indicates the byte offset of the start position for reading characteristic value 1098 * 1099 * @syscap SystemCapability.Communication.Bluetooth.Core 1100 * @since 10 1101 */ 1102 offset: number; 1103 /** 1104 * The UUID of a CharacteristicReadRequest instance 1105 * 1106 * @syscap SystemCapability.Communication.Bluetooth.Core 1107 * @since 10 1108 */ 1109 characteristicUuid: string; 1110 /** 1111 * The UUID of the service to which the characteristic belongs 1112 * 1113 * @syscap SystemCapability.Communication.Bluetooth.Core 1114 * @since 10 1115 */ 1116 serviceUuid: string; 1117 } 1118 1119 /** 1120 * Describes the parameters of the of the Gatt client's characteristic write request. 1121 * 1122 * @typedef CharacteristicWriteRequest 1123 * @syscap SystemCapability.Communication.Bluetooth.Core 1124 * @since 10 1125 */ 1126 interface CharacteristicWriteRequest { 1127 /** 1128 * Indicates the address of the client that initiates the write request 1129 * 1130 * @syscap SystemCapability.Communication.Bluetooth.Core 1131 * @since 10 1132 */ 1133 deviceId: string; 1134 /** 1135 * The Id of the write request 1136 * 1137 * @syscap SystemCapability.Communication.Bluetooth.Core 1138 * @since 10 1139 */ 1140 transId: number; 1141 /** 1142 * Indicates the byte offset of the start position for writing characteristic value 1143 * 1144 * @syscap SystemCapability.Communication.Bluetooth.Core 1145 * @since 10 1146 */ 1147 offset: number; 1148 /** 1149 * Whether this request should be pending for later operation 1150 * 1151 * @syscap SystemCapability.Communication.Bluetooth.Core 1152 * @since 10 1153 */ 1154 isPrepared: boolean; 1155 /** 1156 * Whether the remote client need a response 1157 * 1158 * @syscap SystemCapability.Communication.Bluetooth.Core 1159 * @since 10 1160 */ 1161 needRsp: boolean; 1162 /** 1163 * Indicates the value to be written 1164 * 1165 * @syscap SystemCapability.Communication.Bluetooth.Core 1166 * @since 10 1167 */ 1168 value: ArrayBuffer; 1169 /** 1170 * The UUID of a CharacteristicWriteRequest instance 1171 * 1172 * @syscap SystemCapability.Communication.Bluetooth.Core 1173 * @since 10 1174 */ 1175 characteristicUuid: string; 1176 /** 1177 * The UUID of the service to which the characteristic belongs 1178 * 1179 * @syscap SystemCapability.Communication.Bluetooth.Core 1180 * @since 10 1181 */ 1182 serviceUuid: string; 1183 } 1184 1185 /** 1186 * Describes the parameters of the Gatt client's descriptor read request. 1187 * 1188 * @typedef DescriptorReadRequest 1189 * @syscap SystemCapability.Communication.Bluetooth.Core 1190 * @since 10 1191 */ 1192 interface DescriptorReadRequest { 1193 /** 1194 * Indicates the address of the client that initiates the read request 1195 * 1196 * @syscap SystemCapability.Communication.Bluetooth.Core 1197 * @since 10 1198 */ 1199 deviceId: string; 1200 /** 1201 * The Id of the read request 1202 * 1203 * @syscap SystemCapability.Communication.Bluetooth.Core 1204 * @since 10 1205 */ 1206 transId: number; 1207 /** 1208 * Indicates the byte offset of the start position for reading characteristic value 1209 * 1210 * @syscap SystemCapability.Communication.Bluetooth.Core 1211 * @since 10 1212 */ 1213 offset: number; 1214 /** 1215 * The UUID of a DescriptorReadRequest instance 1216 * 1217 * @syscap SystemCapability.Communication.Bluetooth.Core 1218 * @since 10 1219 */ 1220 descriptorUuid: string; 1221 /** 1222 * The UUID of the characteristic to which the descriptor belongs 1223 * 1224 * @syscap SystemCapability.Communication.Bluetooth.Core 1225 * @since 10 1226 */ 1227 characteristicUuid: string; 1228 /** 1229 * The UUID of the service to which the descriptor belongs 1230 * 1231 * @syscap SystemCapability.Communication.Bluetooth.Core 1232 * @since 10 1233 */ 1234 serviceUuid: string; 1235 } 1236 1237 /** 1238 * Describes the parameters of the Gatt client's characteristic write request. 1239 * 1240 * @typedef DescriptorWriteRequest 1241 * @syscap SystemCapability.Communication.Bluetooth.Core 1242 * @since 10 1243 */ 1244 interface DescriptorWriteRequest { 1245 /** 1246 * Indicates the address of the client that initiates the write request 1247 * 1248 * @syscap SystemCapability.Communication.Bluetooth.Core 1249 * @since 10 1250 */ 1251 deviceId: string; 1252 /** 1253 * The Id of the write request 1254 * 1255 * @syscap SystemCapability.Communication.Bluetooth.Core 1256 * @since 10 1257 */ 1258 transId: number; 1259 /** 1260 * Indicates the byte offset of the start position for writing characteristic value 1261 * 1262 * @syscap SystemCapability.Communication.Bluetooth.Core 1263 * @since 10 1264 */ 1265 offset: number; 1266 /** 1267 * Whether this request should be pending for later operation 1268 * 1269 * @syscap SystemCapability.Communication.Bluetooth.Core 1270 * @since 10 1271 */ 1272 isPrepared: boolean; 1273 /** 1274 * Whether the remote client need a response 1275 * 1276 * @syscap SystemCapability.Communication.Bluetooth.Core 1277 * @since 10 1278 */ 1279 needRsp: boolean; 1280 /** 1281 * Indicates the value to be written 1282 * 1283 * @syscap SystemCapability.Communication.Bluetooth.Core 1284 * @since 10 1285 */ 1286 value: ArrayBuffer; 1287 /** 1288 * The UUID of a DescriptorWriteRequest instance 1289 * 1290 * @syscap SystemCapability.Communication.Bluetooth.Core 1291 * @since 10 1292 */ 1293 descriptorUuid: string; 1294 /** 1295 * The UUID of the characteristic to which the descriptor belongs 1296 * 1297 * @syscap SystemCapability.Communication.Bluetooth.Core 1298 * @since 10 1299 */ 1300 characteristicUuid: string; 1301 /** 1302 * The UUID of the service to which the descriptor belongs 1303 * 1304 * @syscap SystemCapability.Communication.Bluetooth.Core 1305 * @since 10 1306 */ 1307 serviceUuid: string; 1308 } 1309 1310 /** 1311 * Describes the parameters of a response send by the server to a specified read or write request. 1312 * 1313 * @typedef ServerResponse 1314 * @syscap SystemCapability.Communication.Bluetooth.Core 1315 * @since 10 1316 */ 1317 interface ServerResponse { 1318 /** 1319 * Indicates the address of the client to which to send the response 1320 * 1321 * @syscap SystemCapability.Communication.Bluetooth.Core 1322 * @since 10 1323 */ 1324 deviceId: string; 1325 /** 1326 * The Id of the write request 1327 * 1328 * @syscap SystemCapability.Communication.Bluetooth.Core 1329 * @since 10 1330 */ 1331 transId: number; 1332 /** 1333 * Indicates the status of the read or write request, set this parameter to '0' in normal cases 1334 * 1335 * @syscap SystemCapability.Communication.Bluetooth.Core 1336 * @since 10 1337 */ 1338 status: number; 1339 /** 1340 * Indicates the byte offset of the start position for reading or writing operation 1341 * 1342 * @syscap SystemCapability.Communication.Bluetooth.Core 1343 * @since 10 1344 */ 1345 offset: number; 1346 /** 1347 * Indicates the value to be sent 1348 * 1349 * @syscap SystemCapability.Communication.Bluetooth.Core 1350 * @since 10 1351 */ 1352 value: ArrayBuffer; 1353 } 1354 1355 /** 1356 * Describes the Gatt profile connection state. 1357 * 1358 * @typedef BLEConnectionChangeState 1359 * @syscap SystemCapability.Communication.Bluetooth.Core 1360 * @since 10 1361 */ 1362 interface BLEConnectionChangeState { 1363 /** 1364 * Indicates the peer device address 1365 * 1366 * @syscap SystemCapability.Communication.Bluetooth.Core 1367 * @since 10 1368 */ 1369 deviceId: string; 1370 /** 1371 * Connection state of the Gatt profile 1372 * 1373 * @syscap SystemCapability.Communication.Bluetooth.Core 1374 * @since 10 1375 */ 1376 state: ProfileConnectionState; 1377 } 1378 1379 /** 1380 * Describes the contents of the scan results. 1381 * 1382 * @typedef ScanResult 1383 * @syscap SystemCapability.Communication.Bluetooth.Core 1384 * @since 10 1385 */ 1386 interface ScanResult { 1387 /** 1388 * Address of the scanned device 1389 * 1390 * @syscap SystemCapability.Communication.Bluetooth.Core 1391 * @since 10 1392 */ 1393 deviceId: string; 1394 /** 1395 * RSSI of the remote device 1396 * 1397 * @syscap SystemCapability.Communication.Bluetooth.Core 1398 * @since 10 1399 */ 1400 rssi: number; 1401 /** 1402 * The raw data of broadcast packet 1403 * 1404 * @syscap SystemCapability.Communication.Bluetooth.Core 1405 * @since 10 1406 */ 1407 data: ArrayBuffer; 1408 /** 1409 * The local name of the BLE device 1410 * 1411 * @syscap SystemCapability.Communication.Bluetooth.Core 1412 * @since 10 1413 */ 1414 deviceName: string; 1415 /** 1416 * Connectable of the remote device 1417 * 1418 * @syscap SystemCapability.Communication.Bluetooth.Core 1419 * @since 10 1420 */ 1421 connectable: boolean; 1422 } 1423 1424 /** 1425 * Describes the settings for BLE advertising. 1426 * 1427 * @typedef AdvertiseSetting 1428 * @syscap SystemCapability.Communication.Bluetooth.Core 1429 * @since 10 1430 */ 1431 interface AdvertiseSetting { 1432 /** 1433 * Minimum slot value for the advertising interval, which is {@code 32} (20 ms) 1434 * Maximum slot value for the advertising interval, which is {@code 16777215} (10485.759375s) 1435 * Default slot value for the advertising interval, which is {@code 1600} (1s) 1436 * 1437 * @syscap SystemCapability.Communication.Bluetooth.Core 1438 * @since 10 1439 */ 1440 interval?: number; 1441 /** 1442 * Minimum transmission power level for advertising, which is {@code -127} 1443 * Maximum transmission power level for advertising, which is {@code 1} 1444 * Default transmission power level for advertising, which is {@code -7} 1445 * 1446 * @syscap SystemCapability.Communication.Bluetooth.Core 1447 * @since 10 1448 */ 1449 txPower?: number; 1450 /** 1451 * Indicates whether the BLE is connectable, default is {@code true} 1452 * 1453 * @syscap SystemCapability.Communication.Bluetooth.Core 1454 * @since 10 1455 */ 1456 connectable?: boolean; 1457 } 1458 1459 /** 1460 * Describes the advertising data. 1461 * 1462 * @typedef AdvertiseData 1463 * @syscap SystemCapability.Communication.Bluetooth.Core 1464 * @since 10 1465 */ 1466 interface AdvertiseData { 1467 /** 1468 * The specified service UUID list to this advertisement 1469 * 1470 * @syscap SystemCapability.Communication.Bluetooth.Core 1471 * @since 10 1472 */ 1473 serviceUuids: Array<string>; 1474 /** 1475 * The specified manufacturer data list to this advertisement 1476 * 1477 * @syscap SystemCapability.Communication.Bluetooth.Core 1478 * @since 10 1479 */ 1480 manufactureData: Array<ManufactureData>; 1481 /** 1482 * The specified service data list to this advertisement 1483 * 1484 * @syscap SystemCapability.Communication.Bluetooth.Core 1485 * @since 10 1486 */ 1487 serviceData: Array<ServiceData>; 1488 /** 1489 * Indicates whether the device name will be included in the advertisement packet. 1490 * 1491 * @syscap SystemCapability.Communication.Bluetooth.Core 1492 * @since 10 1493 */ 1494 includeDeviceName?: boolean; 1495 } 1496 1497 /** 1498 * Describes the manufacturer data. 1499 * 1500 * @typedef ManufactureData 1501 * @syscap SystemCapability.Communication.Bluetooth.Core 1502 * @since 10 1503 */ 1504 interface ManufactureData { 1505 /** 1506 * Indicates the manufacturer ID assigned by Bluetooth SIG 1507 * 1508 * @syscap SystemCapability.Communication.Bluetooth.Core 1509 * @since 10 1510 */ 1511 manufactureId: number; 1512 /** 1513 * Indicates the manufacturer data to add 1514 * 1515 * @syscap SystemCapability.Communication.Bluetooth.Core 1516 * @since 10 1517 */ 1518 manufactureValue: ArrayBuffer; 1519 } 1520 1521 /** 1522 * Describes the service data. 1523 * 1524 * @typedef ServiceData 1525 * @syscap SystemCapability.Communication.Bluetooth.Core 1526 * @since 10 1527 */ 1528 interface ServiceData { 1529 /** 1530 * Indicates the UUID of the service data to add 1531 * 1532 * @syscap SystemCapability.Communication.Bluetooth.Core 1533 * @since 10 1534 */ 1535 serviceUuid: string; 1536 /** 1537 * Indicates the service data to add 1538 * 1539 * @syscap SystemCapability.Communication.Bluetooth.Core 1540 * @since 10 1541 */ 1542 serviceValue: ArrayBuffer; 1543 } 1544 1545 /** 1546 * Describes the criteria for filtering scanning results can be set. 1547 * 1548 * @typedef ScanFilter 1549 * @syscap SystemCapability.Communication.Bluetooth.Core 1550 * @since 10 1551 */ 1552 interface ScanFilter { 1553 /** 1554 * The address of a BLE peripheral device 1555 * 1556 * @syscap SystemCapability.Communication.Bluetooth.Core 1557 * @since 10 1558 */ 1559 deviceId?: string; 1560 1561 /** 1562 * The name of a BLE peripheral device 1563 * 1564 * @syscap SystemCapability.Communication.Bluetooth.Core 1565 * @since 10 1566 */ 1567 name?: string; 1568 1569 /** 1570 * The service UUID of a BLE peripheral device 1571 * 1572 * @syscap SystemCapability.Communication.Bluetooth.Core 1573 * @since 10 1574 */ 1575 serviceUuid?: string; 1576 1577 /** 1578 * Service UUID mask. 1579 * 1580 * @syscap SystemCapability.Communication.Bluetooth.Core 1581 * @since 10 1582 */ 1583 serviceUuidMask?: string; 1584 1585 /** 1586 * Service solicitation UUID. 1587 * 1588 * @syscap SystemCapability.Communication.Bluetooth.Core 1589 * @since 10 1590 */ 1591 serviceSolicitationUuid?: string; 1592 1593 /** 1594 * Service solicitation UUID mask. 1595 * 1596 * @syscap SystemCapability.Communication.Bluetooth.Core 1597 * @since 10 1598 */ 1599 serviceSolicitationUuidMask?: string; 1600 1601 /** 1602 * Service data. 1603 * 1604 * @syscap SystemCapability.Communication.Bluetooth.Core 1605 * @since 10 1606 */ 1607 serviceData?: ArrayBuffer; 1608 1609 /** 1610 * Service data mask. 1611 * 1612 * @syscap SystemCapability.Communication.Bluetooth.Core 1613 * @since 10 1614 */ 1615 serviceDataMask?: ArrayBuffer; 1616 1617 /** 1618 * Manufacture id. 1619 * 1620 * @syscap SystemCapability.Communication.Bluetooth.Core 1621 * @since 10 1622 */ 1623 manufactureId?: number; 1624 1625 /** 1626 * Manufacture data. 1627 * 1628 * @syscap SystemCapability.Communication.Bluetooth.Core 1629 * @since 10 1630 */ 1631 manufactureData?: ArrayBuffer; 1632 1633 /** 1634 * Manufacture data mask. 1635 * 1636 * @syscap SystemCapability.Communication.Bluetooth.Core 1637 * @since 10 1638 */ 1639 manufactureDataMask?: ArrayBuffer; 1640 } 1641 1642 /** 1643 * Describes the parameters for scan. 1644 * 1645 * @typedef ScanOptions 1646 * @syscap SystemCapability.Communication.Bluetooth.Core 1647 * @since 10 1648 */ 1649 interface ScanOptions { 1650 /** 1651 * Time of delay for reporting the scan result 1652 * 1653 * @syscap SystemCapability.Communication.Bluetooth.Core 1654 * @since 10 1655 */ 1656 interval?: number; 1657 /** 1658 * Bluetooth LE scan mode 1659 * 1660 * @syscap SystemCapability.Communication.Bluetooth.Core 1661 * @since 10 1662 */ 1663 dutyMode?: ScanDuty; 1664 /** 1665 * Match mode for Bluetooth LE scan filters hardware match 1666 * 1667 * @syscap SystemCapability.Communication.Bluetooth.Core 1668 * @since 10 1669 */ 1670 matchMode?: MatchMode; 1671 } 1672 1673 /** 1674 * Describes the properties of a gatt characteristic. 1675 * 1676 * @typedef GattProperties 1677 * @syscap SystemCapability.Communication.Bluetooth.Core 1678 * @since 10 1679 */ 1680 interface GattProperties { 1681 /** 1682 * Support write property of the characteristic. 1683 * 1684 * @syscap SystemCapability.Communication.Bluetooth.Core 1685 * @since 10 1686 */ 1687 write?: boolean; 1688 /** 1689 * Support write no response property of the characteristic. 1690 * 1691 * @syscap SystemCapability.Communication.Bluetooth.Core 1692 * @since 10 1693 */ 1694 writeNoResponse?: boolean; 1695 /** 1696 * Support read property of the characteristic. 1697 * 1698 * @syscap SystemCapability.Communication.Bluetooth.Core 1699 * @since 10 1700 */ 1701 read?: boolean; 1702 /** 1703 * Support notify property of the characteristic. 1704 * 1705 * @syscap SystemCapability.Communication.Bluetooth.Core 1706 * @since 10 1707 */ 1708 notify?: boolean; 1709 /** 1710 * Support indicate property of the characteristic. 1711 * 1712 * @syscap SystemCapability.Communication.Bluetooth.Core 1713 * @since 10 1714 */ 1715 indicate?: boolean; 1716 } 1717 1718 /** 1719 * The enum of gatt characteristic write type 1720 * 1721 * @enum { number } 1722 * @syscap SystemCapability.Communication.Bluetooth.Core 1723 * @since 10 1724 */ 1725 enum GattWriteType { 1726 /** 1727 * Write characteristic with response. 1728 * 1729 * @syscap SystemCapability.Communication.Bluetooth.Core 1730 * @since 10 1731 */ 1732 WRITE = 1, 1733 /** 1734 * Write characteristic without response. 1735 * 1736 * @syscap SystemCapability.Communication.Bluetooth.Core 1737 * @since 10 1738 */ 1739 WRITE_NO_RESPONSE = 2 1740 } 1741 1742 /** 1743 * The enum of scan duty. 1744 * 1745 * @enum { number } 1746 * @syscap SystemCapability.Communication.Bluetooth.Core 1747 * @since 10 1748 */ 1749 enum ScanDuty { 1750 /** 1751 * low power mode 1752 * 1753 * @syscap SystemCapability.Communication.Bluetooth.Core 1754 * @since 10 1755 */ 1756 SCAN_MODE_LOW_POWER = 0, 1757 /** 1758 * balanced power mode 1759 * 1760 * @syscap SystemCapability.Communication.Bluetooth.Core 1761 * @since 10 1762 */ 1763 SCAN_MODE_BALANCED = 1, 1764 /** 1765 * Scan using highest duty cycle 1766 * 1767 * @syscap SystemCapability.Communication.Bluetooth.Core 1768 * @since 10 1769 */ 1770 SCAN_MODE_LOW_LATENCY = 2 1771 } 1772 1773 /** 1774 * The enum of BLE match mode. 1775 * 1776 * @enum { number } 1777 * @syscap SystemCapability.Communication.Bluetooth.Core 1778 * @since 10 1779 */ 1780 enum MatchMode { 1781 /** 1782 * aggressive mode 1783 * 1784 * @syscap SystemCapability.Communication.Bluetooth.Core 1785 * @since 10 1786 */ 1787 MATCH_MODE_AGGRESSIVE = 1, 1788 /** 1789 * sticky mode 1790 * 1791 * @syscap SystemCapability.Communication.Bluetooth.Core 1792 * @since 10 1793 */ 1794 MATCH_MODE_STICKY = 2 1795 } 1796} 1797 1798export default ble;