B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt: Difference between revisions

Jump to navigation Jump to search
add discoverServices
(add discoverServices)
(add discoverServices)
Line 94: Line 94:
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connect.28.29|BluetoothGatt.connect()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connect.28.29|BluetoothGatt.connect()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#disconnect.28.29|BluetoothGatt.disconnect()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#disconnect.28.29|BluetoothGatt.disconnect()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#discoverServices.28.29|BluetoothGatt.discoverServices()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#readRemoteRssi.28.29|BluetoothGatt.readRemoteRssi()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#readRemoteRssi.28.29|BluetoothGatt.readRemoteRssi()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#beginReliableWrite.28.29|BluetoothGatt.beginReliableWrite()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#beginReliableWrite.28.29|BluetoothGatt.beginReliableWrite()]]
Line 138: Line 139:
   }, function onReject(aReason) {
   }, function onReject(aReason) {
     console.log("Rejected with this reason: ", aReason, ". ConnectionState becomes:", gatt.connectionState);
     console.log("Rejected with this reason: ", aReason, ". ConnectionState becomes:", gatt.connectionState);
  };
}
=== discoverServices() ===
; Description
: The method discover services, characteristics, and descriptors offered by the remote GATT server.
; Return
: A Promise to indicate whether the operation is resolved or rejected. If the property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connectionState|connectionState]] is not <tt>connected</tt> when the method is called, the Promise would be rejected.
; Sample
var gatt = device.gatt;
if (gatt && gatt.connectionState === "connected") {
  gatt.discoverServices().then ( function onResolve() {
    console.log("Services, characteristics, and descriptors are successfully discovered.");
  }, function onReject(aReason) {
    console.log("Rejected with this reason: ", aReason);
   };
   };
  }
  }
120

edits

Navigation menu