概要


省電力のBLE(Bluetooth Low Energy)を使用することで、センサ機器やウェアラブル機器などと通信することができます。Open Web BoardはオンボードでBLEを備えており、Webアプリから利用することができます。現在使用可能なプロファイルはGATTのみですが、GATTをベースにしたプロファイルも多いため、開発者が必要なプロファイルを実装することも可能です。



BLE実装の仕組み


Firefox OSは、現在 BLE APIを備えていません(※2015/1/16現在)。そのため、外部機器との接続が必要なOpen Web Boardでは、独自に一時的なWeb APIとしてFirefox OSのgeckoへ機能追加を行っています。これによって拡張されたAPIは owbBleという名前で利用できます。

Firefox OSでもBLE APIの正式な実装が検討されており(※2015/1/16現在)、将来的には正式なWeb APIへ移行することになるでしょう。



使用方法


ここでは簡単なBLEの使用方法をご紹介いたします。詳細はBLEサンプルアプリ及びAPIリファレンスをご参照ください。

■事前設定

Open Web Board上のBLEは、通常のBluetoothの設定と連動しています。使用する前に、環境設定アプリでFirefox OSのBluetooth設定をONにしてください。

■マニフェストファイル

BLEを使用する場合も、Bluetoothと同じく、"bluetooth" パーミッションを必要とします。Webアプリのマニフェストファイルに下記のような permissionを指定してください。permissionに関する詳細はこちらをご参照ください。
{
  (省略)
    "type": "certified",
    "permissions": {
      "bluetooth":{}
    }
}
			
bluetoothパーミッションはcertifed権限が必要になります。もしアプリが動かない場合は、certifiedアプリのデバッグが有効になっているかご確認ください。設定はこちらをご参照ください。

■プログラム

BLEを使用する際の大まかな流れは下記のようになります。BLEをのオブジェクトを取得し、必要な設定を行った後に、センサなどのペリフェラルをスキャンし、目的のペリフェラルに接続して値の読み書きを行います。


全体の流れ

1. BLEオブジェクトの取得
Open Web Boardでは下記のようにして、BLEオブジェクトを取得できます。このオブジェクトはOpen Web Board固有のため、他のFirefox OS端末では利用できません。またbluetoothManagerも、Bluetoothアダプタを取得する際に必要です。
var bluetoothManager = navigator.mozBluetooth;
var bleManager = navigator.owbBle;


2. BLEクライアントの初期設定
bluetoothManagerを使用してBLEに使用するアダプタを取得します。Open Web Board上には一つしかありませんので、このBluetoothアダプタが取得できます。取得に成功後、必要なコールバック関数の設定を行います。コールバック関数の詳細はAPIリファレンスをご参照ください。

コールバック関数を設定後、BLEとして動作するためにアプリをクライアント(セントラル)として登録します。成功すればコールバック関数に、クライアントIFが返ります。このクライアントIFは今後の関数呼び出しに必要なものなので保持しておきます。

var defaultAdapter = null;
var req = bluetoothManager.getDefaultAdapter(); // アダプタを取得
req.onsuccess = function bt_getAdapterSuccess() {  
  defaultAdapter = req.result;  //	成功するとアダプタを取得できる
  if (defaultAdapter != null) {
    Log.d(TAG, "defaultAdapter:" + defaultAdapter.name);
    defaultAdapter.onregisterclient = onRegisterClient;
    defaultAdapter.onscanresult = onScanResult;
    defaultAdapter.onconnectble = onConnectble;
    defaultAdapter.ondisconnectble = onDisconnectble;
    defaultAdapter.onsearchcomplete = onSearchComplete;
    defaultAdapter.onsearchresult = onSearchResult;
    defaultAdapter.ongetcharacteristic = onGetCharacteristic;
    defaultAdapter.ongetdescriptor = onGetDescriptor;
    defaultAdapter.ongetIncludedservice = onGetIncludedService;
    defaultAdapter.onregisterfornotification = onRegisterforNotification;
    defaultAdapter.onnotify = onNotify;
    defaultAdapter.onreadcharacteristic = onReadCharacteristic;
    defaultAdapter.onwritecharacteristic = onWriteCharacteristic;
    defaultAdapter.onreaddescriptor = onReadDescriptor;
    defaultAdapter.onwritedescriptor = onWriteDescriptor;
    defaultAdapter.onexecuteWrite = onExecutWrite;
    defaultAdapter.onreadremoterssi = onReadRemoterssi;
    defaultAdapter.onblelisten = onBleListen;

    if (bleManager) {			// BLEとしてアプリを登録する。結果は上記のコールバック関数に
      bleManager.registerClient(REGISTER_UUID);
    }
  } else {
    Log.w(TAG, 'bluetooth adapter is null');
  }
};
req.onerror = function bt_getAdapterFailed() {
  Log.d(TAG, 'Can not get bluetooth adapter!');
};

function onRegisterClient(event) {
  Log.d(TAG, "register status:" + event.status);
  Log.d(TAG, "register client_if:" + event.client_if);
  Log.d(TAG, "register uuid:" + event.uuid);
  if (event.status == 0) {
    regist_uuid = event.uuid;
    client_if = event.client_if;
    // 登録成功!
  }
}


3. デバイスのスキャン
BLEのペリフェラル(サーバ)であるセンサやウェアラブル機器などの周辺デバイスをスキャンします。scanLEDeviceの第二引数にtrueを指定してスキャンを開始します。スキャンのタイムアウトを設定する場合はタイマー等を使用して、一定時間後にfalseにすることで実現できます。

また、スキャン結果は、コールバック関数で指定したonScanResultに返ってきます。デバイス名、アドレス、RSSI等の値を結果から取得できます。
function scanDevices() {
  if (scaning) {
    return;
  }
  scaning = true;
  bleManager.scanLEDevice(client_if, true); // スキャン開始
  searchTimer = setTimeout(function () {
    bleManager.scanLEDevice(client_if, false); // スキャン停止
    clearTimeout(searchTimer);
    searchTimer = undefined;
    scaning = false;
  }, 10000); //  10秒後にスキャンを止める
}

function onScanResult(event) {
  Log.d(TAG, "onScanResult:" + event.bda);
  var device = {
    name : event.adv_data,
    address : event.bda,
    rssi : event.rssi,
    type : event.device_type
  };
}


4. デバイスへの接続
スキャンにより対象のデバイスが見つけた後デバイスに接続します。デバイスに接続することで、デバイスが持つ値の読み書きが可能になります。
接続結果はコールバック関数のonConnectBleに返ります。成功した場合は、接続IDが取得でき、今後の読み書きに使用します。
bleManager.connectBle(client_if, device.address, true);

function onConnectble(event) {
  Log.d(TAG, "connectble status:" + event.status);
  Log.d(TAG, "connectble conn_id:" + event.conn_id);
  if (event.status == 0) {

    conn_id = event.conn_id;
		
  }
}


5. サービスの取得
デバイスが持つサービスの一覧を取得します。searchServiceを使用すると、見つかったサービスがonSearchResultとして返され、すべてのサービスが取得できると最後にonSearchCompleteが呼ばれます。
service_scaning = true;
bleManager.searchService(conn_id, '');

function onSearchResult(event) {
  Log.d(TAG, "onSearchResult:" + event);
  Log.d(TAG, "srvc_id_id_uuid:" + event.srvc_id_id_uuid);
  Log.d(TAG, "srvc_id_id_inst_id:" + event.srvc_id_id_inst_id);
  Log.d(TAG, "srvc_id_is_primary:" + event.srvc_id_is_primary);
  var srvc_id = {
    uuid: event.srvc_id_id_uuid,
    inst_id: event.srvc_id_id_inst_id,
    is_primary: event.srvc_id_is_primary
  };

}

function onSearchComplete(event) {
  Log.d(TAG, "onSearchComplete status:" + event.status);
  service_scaning = false;
}



6. キャラクタリスティックの取得
サービスが持つキャラクタリスティックの一覧を取得します。getCharacteristicの第二引数は上記で取得したサービスIDのオブジェクト、第三の引数はスキャン開始のキャラスタリスティックのIDオブジェクトです。空の内容指定すると最初からスキャンし、次回以降は取得したキャラスタリスティックのIDを市営します。

var start_char_id = {
  uuid: "",
  inst_id: "",
  is_primary: ""
};
bleManager.getCharacteristic(conn_id, srvc_id, start_char_id);

function onGetCharacteristic(event) {
  Log.d(TAG, "onGetCharacteristic:" + event);
  Log.d(TAG, "state:" + event.status);
  Log.d(TAG, "char_id_uuid:" + event.char_id_uuid);
  Log.d(TAG, "char_id_inst_id:" + event.char_id_inst_id);
  Log.d(TAG, "char_prop:" + event.char_prop);

  var char_id = {
    uuid: event.char_id_uuid,
    inst_id: event.char_id_inst_id
  };

  var characteristic = {
    uuid: event.char_id_uuid,
    inst_id: event.char_id_inst_id,
    prop: event.char_prop
  };
	
	//	次のキャラクタリスティックを取得
  bleManager.getCharacteristic(conn_id, srvc_id, char_id);
}



7. 値の取得
指定したキャラスタリステイックの値を取得します。値はコールバック関数のonReadCharacteristicに返ってきます。

var auth_req = 0;
bleManager.readCharacteristic(conn_id, srvc_id, char_id, auth_req);

function onReadCharacteristic(event) {
  Log.d(TAG, "onReadCharacteristic status:" + event.status);
  Log.d(TAG, "onReadCharacteristic value:" + event.value);
  Log.d(TAG, "value_type:" + event.value_type);

  var value = event.value;		// ようやく値を取得できました
}




8. デバイスから切断
接続しているデバイスから切断します。接続IDのほかに、デバイスのアドレスの指定も必要です。結果はonDisconnectbleに返ります。

bleManager.disconnectBle(client_if, bd_addr, conn_id);

function onDisconnectble(event) {
  Log.d(TAG, "disconnectble status:" + event.status);
  if (event.status == 0) {
    conn_id = undefined;
  }
}

以上で、BLEデバイスに接続し値を取得することができました。ほかにも値を書き込んだり、NOTIFYをデバイスから受けることが可能です。詳細はサンプルアプリをご参照ください。



サンプル アプリ


Open Web Boardの標準イメージには、BLEサンプルアプリが入っています。


BLEデバイス(ペリフェラル)をスキャンし、接続してその値の読み書きが可能なアプリです。BLEアプリを開発する際にApache Lisense 2.0にてご利用いただけます。


APIリファレンス


■フロー概要

BLE APIの利用フローを下記の図に示します。


APIコールフロー図

■API仕様

ITEM DESCRIPTION
Function bool RegisterClient(const nsAString& uuid);
Description Registers a GATT client application with the stack
NOTE : TheFunction has a callbackFunction - onregisterclient
Parameters uuid : applicaiton UUID
Returns Execute registerClientFunction successfully or failed
ITEM DESCRIPTION
Function bool UnRegisterClient(int client_if);
Description Unregister a client application from the stack
NOTE : TheFunction has no callbackFunction
Parameters client_if: client interface identifier
Returns Execute unRegisterClientFunction successfully or failed
ITEM DESCRIPTION
Function bool ScanLEDevice(int client_if, bool start);
Description Start or stop LE device scanning
NOTE : TheFunction has a callbackFunction - onscanresult
Parameters client_if : client interface identifier
start : to start or stop scan LE Device
Returns Execute scanLEDeviceFunction successfully or failed
ITEM DESCRIPTION
Function bool ConnectBle(int client_if, const nsAString& bd_addr, bool is_direct);
Description Create a connection to a remote LE or dual-mode device
NOTE : TheFunction has a callbackFunction - onconnectble
Parameters client_if: client interface.
bd_addr: remote device BD address.
is_direct: direct connection or background auto connection
Returns Execute connectBleFunction successfully or failed
ITEM DESCRIPTION
Function bool DisconnectBle(int client_if, const nsAString& bd_addr, int conn_id);
Description Disconnect a remote device or cancel a pending connection
NOTE : TheFunction has a callbackFunction - ondisconnectble     
Parameters client_if: client interface.
bd_addr: remote device BD address.
conn_id: connectino ID to be closed
Returns Execute disconnectBleFunction successfully or failed

 

ITEM DESCRIPTION
Function bool SetListen(int client_if, bool start);
Description Start or stop advertisements to listen for incoming connections
NOTE : TheFunction has no callbackFunction
Parameters client_if : client interface
start : to start or stop listening for connection
Returns Execute setListenFunction successfully or failed
ITEM DESCRIPTION
Function bool Refresh(int client_if, const nsAString& bd_addr);
Description Clear the attribute cache for a given device
NOTE : TheFunction has no callbackFunction
Parameters client_if : client interface
bd_addr : remote device BD address
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool SearchService(int conn_id, const nsAString& filter_uuid);
Description numerate all GATT services on a connected device
Optionally, the results can be filtered for a given UUID
NOTE : TheFunction has a callbackFunction - onsearchresult , onsearchcomplete
Parameters conn_id : connection ID
filter_uuid : the results can be filtered for the filter_uuid
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool GetIncludeService(int conn_id, const BtGattSrvcId& srvc_id, const BtGattSrvcId& start_incl_srvc_id);
Description Enumerate included services for a given service
Set start_incl_srvc_id to NULL to get the first included service
NOTE : TheFunction has a callbackFunction - ongetincludedservice
Parameters conn_id: connection ID which identify the server
srvc_id: the service ID of which the included service is belonged to
start_incl_srvc_id: include service UUID, if NULL find the first available included service
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool GetCharacteristic(int conn_id, const BtGattSrvcId&  srvc_id, const BtGattGattId&  start_char_id);
Description Enumerate characteristics for a given servie.
Set start_char_id to NULL to get the first characteristic
NOTE : TheFunction has a callbackFunction - ongetcharacteristic
Parameters conn_id: connection ID which identify the server
srvc_id: the service ID of which the characteristic is belonged to
char_uuid_cond: Characteristic UUID, if NULL find the first available characteristic
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool GetDescriptor(int conn_id, const BtGattSrvcId& srvc_id, const BtGattGattId& char_id, const BtGattGattId& start_descr_id);
Description Enumerate descriptors for a given characteristic
Set start_descr_id to NULL to get the first descriptor
NOTE : TheFunction has a callbackFunction - ongetdescriptor
Parameters conn_id: connection ID which identify the server
srvc_id: the service ID of which the characteristic is belonged to
char_id: the characteristic ID of which the descriptor is belonged to
start_descr_id: Characteristic Descr UUID, if NULL find the first available characteristic
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool ReadCharacteristic(int conn_id, const BtGattSrvcId&  srvc_id, const BtGattGattId&  char_id, int auth_req);
Description Read a characteristic on a remote device
NOTE : TheFunction has a callbackFunction -onreadcharacteristic
Parameters conn_id: connectino ID
srvc_id: the service ID of which the characteristic is belonged to
char_id: characteritic ID to read
auth_req: authentication requirement
Other       auth_req type:
GATT_AUTH_REQ_NONE              0
GATT_AUTH_REQ_NO_MITM          1  
//unauthenticated encryption
GATT_AUTH_REQ_MITM              2  
//authenticated encryption
GATT_AUTH_REQ_SIGNED_NO_MITM  3
GATT_AUTH_REQ_SIGNED_MITM      4
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool WriteCharacteristic(int conn_id, const BtGattSrvcId&  srvc_id, const BtGattGattId&  char_id, int write_type, int len, int auth_req, const nsAString& p_value);
Description Write a remote characteristic
NOTE : TheFunction has a callbackFunction - onwritecharacteristic
Parameters conn_id: connection ID
srvc_id: the service ID of which the characteristic is belonged to
char_id: characteristic ID to write
write_type: type of write
len: length of the data to be written
auth_req: authentication requirement
p_value: the value to be written
Other        auth_req type:
BTA_GATTC_TYPE_WRITE_NO_RSP           1
BTA_GATTC_TYPE_WRITE                   2
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool ReadDescriptor(int conn_id, const BtGattSrvcId& srvc_id, const BtGattGattId& char_id, const BtGattGattId& descr_id, int auth_req);
Description Read the descriptor for a given characteristic
NOTE : TheFunction has a callbackFunction - onreaddescriptor
Parameters conn_id: connectino ID
srvc_id: the service ID of which the characteristic is belonged to
char_id: characteritic ID to read
descr_id: characteritic descriptor ID to read
auth_req: authentication requirement
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool WriteDescriptor(int conn_id, const BtGattSrvcId& srvc_id, const BtGattGattId& char_id, const BtGattGattId& descr_id, int write_type, int len, int auth_req, const nsAString& p_value);
Description Write a remote descriptor for a given characteristic
NOTE : TheFunction has a callbackFunction - onwritedescriptor
Parameters conn_id: connection ID
srvc_id: the service ID of which the characteristic is belonged to
char_id: characteristic ID to write
descr_id: characteritic descriptor ID to read
write_type: type of write
len: length of the data to be written
auth_req: authentication requirement
p_value: the value to be written
Returns  Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool ExecuteWrite(int conn_id, int execute);
Description       executeWrite
Description    Execute a prepared write operation
NOTE : TheFunction has a callbackFunction - onexecuteWrite
Parameters     conn_id: connection ID
execute: execute or cancel
Returns        Execute refreshFunction successfully or failed
Parameters
ITEM DESCRIPTION
Function bool RegisterForNotification(int client_if, const nsAString& bd_addr, const BtGattSrvcId& srvc_id, const BtGattGattId& char_id);
Description Register to receive notifications or indications for a given characteristic
NOTE : TheFunction has a callbackFunction - onregisterfornotification
Parameters client_if: client interface
bd_addr: target GATT server
srvc_id:the service ID of which the characteristic is belonged to
char_id: pointer to GATT characteristic ID
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool DeregisterForNotification(int client_if, const nsAString& bd_addr, const BtGattSrvcId& srvc_id, const BtGattGattId& char_id);
Description Deregister a previous request for notifications/indications
NOTE : TheFunction has no callbackFunction 
Parameters client_if: client interface
bd_addr: target GATT server
srvc_id:the service ID of which the characteristic is belonged to
char_id: pointer to GATT characteristic ID
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool ReadRemoteRssi(int client_if, const nsAString& bd_addr);
Description Request RSSI for a given remote device
NOTE : TheFunction has a callbackFunction - onreadremoterssi 
Parameters client_if: client interface
bd_addr: target GATT server
Returns Execute refreshFunction successfully or failed
ITEM DESCRIPTION
Function bool SetAdvData(int client_if, bool set_scan_rsp, bool include_name, bool include_txpower, int min_interval, int max_interval, int appearance, uint16_t manufacturer_len, const nsAString& manufacturer_data);
Description  Set the advertising data or scan response data
NOTE : TheFunction has no callbackFunction
Parameters client_if: client interface
set_scan_rsp: true to set adv. data, false to set scan response
include_name:  Inlucde the name in the adv. response
include_txpower: Include TX power value
min_interval:  Minimum desired scan interval (optional)
max_interval: Maximum desired scan interval (optional)
appearance: The appearance flags for the device (optional)
manufacturer_len: Manufacturer specific data length
manufacturer_data: Manufacturer specific data including company ID (optional)
Returns Execute refreshFunction successfully or failed

■コールバック関数仕様

NOTE : The callback function return value parameters are encapsulated in the BluetoothGattEvent, through the BluetoothGattEvent object directly to obtain the corresponding attribute values can be.
ForExample:
onregisterclient callback function has three return value : status, client_if, app_uuid; In gaia, you can get the three attribute values in the following ways:

function  onRegisterClient(event) {
	Log.d(TAG,  "onRegisterClient" + event);
	Log.d(TAG,  "status:" + event.status);
	Log.d(TAG,  "client_if:" + event.client_if);
	Log.d(TAG,  "uuid:" + event.uuid);
	if (event.status == 0)  {
		regist_uuid =  event.uuid;
		client_if = event.client_if;
		scanDevices();
	}
}
			

The callback function list

ITEM DESCRIPTION
Function void onregisterclient(BluetoothGattEvent gattEvent);
Description Callback invoked in response to register_client
Parameters gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.client_if: client interface
gattEvent.app_uuid: application uuid
ITEM DESCRIPTION
Function void onscanresult(BluetoothGattEvent gattEvent);
Description Callback for scan results
Parameters gattEvent.bda: remote device BD address
gattEvent.rssi: remote device rssi
gattEvent.adv_data: remote device name
gattEvent.device_type: device type
ITEM DESCRIPTION
Function void onconnectble(BluetoothGattEvent gattEvent);
Description GATT open callback invoked in response to open
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.client_if: client interface
gattEvent.bda: remote device BD address
ITEM DESCRIPTION
Function void ondisconnectble(BluetoothGattEvent gattEvent);
Description Callback invoked in response to close
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.client_if: client interface
gattEvent.bda: remote device BD address
ITEM DESCRIPTION
Function void onsearchresult(BluetoothGattEvent gattEvent);
Description       onsearchresult
Description   Reports GATT services on a remote device
Parameters    gattEvent.conn_id: connection ID
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
Parameters
ITEM DESCRIPTION
Function void onsearchcomplete(BluetoothGattEvent gattEvent);
Description Invoked in response to search_service when the GATT service search has been completed
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
ITEM DESCRIPTION
Function void ongetcharacteristic(BluetoothGattEvent gattEvent);
Description GATT characteristic enumeration result callback
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
gattEvent.char_prop: GATT_CHAR_PROP(Reference notes 3.2)
ITEM DESCRIPTION
Function void ongetdescriptor(BluetoothGattEvent gattEvent);
Description GATT descriptor enumeration result callback
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
gattEvent.char_prop: GATT_CHAR_PROP(Reference notes 3.2)
gattEvent.descr_id_uuid: the uuid of the escriptorID
gattEvent.descr_id_inst_id: the inst_id of the escriptorID
ITEM DESCRIPTION
Function void get_included_service_callback(BluetoothGattEvent gattEvent);
Description GATT included service enumeration result callback
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.incl_srvc_id_id_uuid: the uuid of the includeServiceID
gattEvent.incl_srvc_id_id_inst_id: the inst_id of the includeServiceID
gattEvent.incl_srvc_id_is_primary: the primary of the includeServiceID
ITEM DESCRIPTION
Function void onregisterfornotification(BluetoothGattEvent gattEvent);
Description Callback invoked in response to [de]register_for_notification
Parameters gattEvent.conn_id: connection ID
gattEvent.registered: 1-registed, 0-deregisted
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
ITEM DESCRIPTION
Function void onnotify(BluetoothGattEvent gattEvent);
Description Remote device notification callback, invoked when a remote device sends a notification or indication that a client has registered for
Parameters gattEvent.conn_id: connection ID
gattEvent.value: Identification
gattEvent.bda: remote device BD address
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
gattEvent.len: notify data size
gattEvent.is_notify: notify data
ITEM DESCRIPTION
Function void onreadcharacteristic(BluetoothGattEvent gattEvent);
Description Reports result of a GATT read operation
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
gattEvent.descr_id_uuid: the uuid of the escriptorID
gattEvent.descr_id_inst_id: the inst_id of the escriptorID
gattEvent.value: characteristic value
gattEvent.value_type: characteristic value type
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
ITEM DESCRIPTION
Function void onwritecharacteristic(BluetoothGattEvent gattEvent);
Description GATT write characteristic operation callback
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
gattEvent.descr_id_uuid: the uuid of the escriptorID
gattEvent.descr_id_inst_id: the inst_id of the escriptorID
ITEM DESCRIPTION
Function void execute_write_callback(BluetoothGattEvent gattEvent);
Description GATT execute prepared write callback
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
ITEM DESCRIPTION
Function void onreaddescriptor(BluetoothGattEvent gattEvent);
Description  Callback invoked in response to read_descriptor
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
gattEvent.descr_id_uuid: the uuid of the escriptorID
gattEvent.descr_id_inst_id: the inst_id of the escriptorID
gattEvent.value: characteristic value
gattEvent.value_type: characteristic value type
ITEM DESCRIPTION
Function void onwritedescriptor(BluetoothGattEvent gattEvent);
Description Callback invoked in response to write_descriptor
Parameters gattEvent.conn_id: connection ID
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
gattEvent.srvc_id_id_uuid: the uuid of the serviceID
gattEvent.srvc_id_id_inst_id: the inst_id of the serviceID
gattEvent.srvc_id_is_primary: the primary of the serviceID
gattEvent.char_id_uuid: the uuid of the characteristicID
gattEvent.char_id_inst_id: the inst_id of the characteristicID
gattEvent.descr_id_uuid: the uuid of the escriptorID
gattEvent.descr_id_inst_id: the inst_id of the escriptorID
ITEM DESCRIPTION
Function void read_remote_rssi_callback(BluetoothGattEvent gattEvent);
Description Callback triggered in response to read_remote_rssi
Parameters gattEevent.client_if: client interface
gattEvent.bda: remote device BD address
gattEvent.rssi: rssi value
gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
ITEM DESCRIPTION
Function void onblelisten(int status, int server_if);
Description Callback indicationg the status of a listen() operation
Parameters gattEvent.status: BTA_GATT_STATUS(Reference notes 3.1)
server_if.server_if: server interface

■定数仕様

BTA_GATT_STATUS
DEFINITION VALUE
GATT_SUCCESS0
GATT_INVALID_HANDLE1
GATT_READ_NOT_PERMIT2
GATT_WRITE_NOT_PERMIT3
GATT_INVALID_PDU4
GATT_INSUF_AUTHENTICATION5
GATT_REQ_NOT_SUPPORTED6
GATT_INVALID_OFFSET7
GATT_INSUF_AUTHORIZATION8
GATT_PREPARE_Q_FULL9
GATT_NOT_FOUND10
GATT_NOT_LONG11
GATT_INSUF_KEY_SIZE12
GATT_INVALID_ATTR_LEN13
GATT_ERR_UNLIKELY14
GATT_INSUF_ENCRYPTION15
GATT_UNSUPPORT_GRP_TYPE16
GATT_INSUF_RESOURCE17
GATT_ILLEGAL_PARAMETER135
GATT_NO_RESOURCES128
GATT_INTERNAL_ERROR129
GATT_WRONG_STATE130
GATT_DB_FULL131
GATT_BUSY132
GATT_ERROR133
GATT_CMD_STARTED134
GATT_PENDING136
GATT_AUTH_FAIL137
GATT_MORE138
GATT_INVALID_CFG139
GATT_DUP_REG140
GATT_ALREADY_OPEN141
GATT_CANCEL142
GATT_CHAR_PROP
DEFINITION VALUE
GATT_CHAR_PROP_BIT_BROADCAST(1 << 0)
GATT_CHAR_PROP_BIT_READ(1 << 1)
GATT_CHAR_PROP_BIT_WRITE_NR(1 << 2)
GATT_CHAR_PROP_BIT_WRITE(1 << 3)
GATT_CHAR_PROP_BIT_NOTIFY(1 << 4)
GATT_CHAR_PROP_BIT_INDICATE (1 << 5)
GATT_CHAR_PROP_BIT_AUTH (1 << 6)
GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7)