このドキュメントは、WVBluetooth JavaScript クラスの API リファレンスです。これらの API を使用して、HTML5 アプリやミニアプリを開発します。機能には、Bluetooth 権限のリクエスト、BLE デバイスのスキャン、Bluetooth デバイスへの接続、デバイスサービスの検出などがあります。
WVBluetooth.requestAuthorization
必要な Bluetooth 権限をリクエストし、Bluetooth を有効にします。
入力パラメーター
なし。
コールバックパラメーター
成功コールバックパラメーター:
[
object] value: 次のキーと値のペアを含む JSON オブジェクト。[
string] state: 'poweredOn' を返します。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
window.WindVane.call('WVBluetooth', 'requestAuthorization', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});WVBluetooth.scan
BLE デバイスをスキャンします。
入力パラメーター
なし。
コールバックパラメーター
成功コールバックパラメーター:
なし。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
イベントリスニング
WV.Event.WVBluetooth.discoverDevice: BLE デバイスの検出
イベントパラメーター:
[
string] name: Bluetooth デバイスの名前。[
string] deviceId: デバイスの Bluetooth アドレス。
document.addEventListener('WV.Event.WVBluetooth.discoverDevice', function (e) {
alert('event discoverDevice: ' + JSON.stringify(e.param));
});
window.WindVane.call('WVBluetooth', 'scan', {}, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.stopScan
BLE デバイスのスキャンを停止します。
入力パラメーター
なし。
コールバックパラメーター
成功コールバックパラメーター:
なし。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
window.WindVane.call('WVBluetooth', 'stopScan', {}, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.connect
Bluetooth アドレスを使用して Bluetooth デバイスに接続します。
入力パラメーター
[
string] deviceId: デバイスの Bluetooth アドレス。
コールバックパラメーター
成功コールバックパラメーター:
なし。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
var params = {
deviceId: '00:aa:bb:cc:dd'
};
window.WindVane.call('WVBluetooth', 'connect', params, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.disconnect
接続されている Bluetooth デバイスから切断します。
入力パラメーター
なし。
コールバックパラメーター
成功コールバックパラメーター:
なし。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
イベントリスニング
WV.Event.WVBluetooth.GATTServerDisconnected: Bluetooth 接続の切断
document.addEventListener('WV.Event.WVBluetooth.GATTServerDisconnected', function (e) {
alert('event GATTServerDisconnected: ' + JSON.stringify(e.param));
});
window.WindVane.call('WVBluetooth', 'disconnect', {}, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.getServices
BLE デバイス上のサービスの検出を開始します。
入力パラメーター
[
string] deviceId: デバイスの Bluetooth アドレス。
このメソッドを呼び出す前に、デバイスに接続する必要があります。
コールバックパラメーター
成功コールバックパラメーター:
[
boolean] started: サービス検出が正常に開始された場合はtrue、それ以外の場合はfalse。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
var params = {
deviceId: '00:aa:bb:cc:dd'
};
window.WindVane.call('WVBluetooth', 'getServices', params, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.getCharacteristics
BLE デバイス上の指定されたサービスのすべてのキャラクタリスティックを取得します。
入力パラメーター
[
string] deviceId: デバイスの Bluetooth アドレス。説明このメソッドを呼び出す前に、デバイスに接続する必要があります。
[
string] serviceId: サービス ID (UUID フォーマット)。
コールバックパラメーター
成功コールバックパラメーター:
[
object] characteristics: キャラクタリスティックオブジェクトの配列。各オブジェクトには次のパラメーターが含まれます。[
string] characteristicId: キャラクタリスティック ID (UUID フォーマット)。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx'
};
window.WindVane.call('WVBluetooth', 'getCharacteristics', params, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.writeValue
接続されている BLE デバイスの指定されたキャラクタリスティックに値を書き込みます。
入力パラメーター
[
string] deviceId: 接続されているデバイスの Bluetooth アドレス。[
string] serviceId: サービス ID (UUID フォーマット)。[
string] characteristicId: キャラクタリスティック ID (UUID フォーマット)。[
string] value: 書き込む値。説明値は Base64 でエンコードされた文字列である必要があります。
コールバックパラメーター
成功コールバックパラメーター:
なし。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
イベントリスニング
WV.Event.WVBluetooth.characteristicValueChanged: キャラクタリスティック値の変更 (startNotifications が必要)
document.addEventListener('WV.Event.WVBluetooth.characteristicValueChanged', function (e) {
alert('event characteristicValueChanged: ' + JSON.stringify(e.param));
});
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx',
value: 'xxx'
};
window.WindVane.call('WVBluetooth', 'writeValue', params, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.readValue
接続されている BLE デバイスから指定されたキャラクタリスティックの値を読み取ります。
入力パラメーター
[
string] deviceId: デバイスの Bluetooth アドレス。説明このメソッドを呼び出す前に、デバイスに接続する必要があります。
[
string] serviceId: サービス ID (UUID フォーマット)。[
string] characteristicId: キャラクタリスティック ID (UUID フォーマット)。
コールバックパラメーター
成功コールバックパラメーター:
キャラクタリスティックの値を含むオブジェクト。値は Base64 でエンコードされた文字列です。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx'
};
window.WindVane.call('WVBluetooth', 'readValue', params, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.startNotifications
キャラクタリスティック値の変更通知を有効にします。
入力パラメーター
[
string] deviceId: デバイスの Bluetooth アドレス。説明このメソッドを呼び出す前に、デバイスに接続する必要があります。
[
string] serviceId: サービス ID (UUID フォーマット)。[
string] characteristicId: キャラクタリスティック ID (UUID フォーマット)。
コールバックパラメーター
成功コールバックパラメーター:
なし。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx'
};
window.WindVane.call('WVBluetooth', 'startNotifications', params, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}WVBluetooth.stopNotifications
キャラクタリスティック値の変更通知を無効にします。
入力パラメーター
[
string] deviceId: デバイスの Bluetooth アドレス。説明このメソッドを呼び出す前に、デバイスに接続する必要があります。
[
string] serviceId: サービス ID (UUID フォーマット)。[
string] characteristicId: キャラクタリスティック ID (UUID フォーマット)。
コールバックパラメーター
成功コールバックパラメーター:
なし。
失敗コールバックパラメーター:
[
string] msg: エラーメッセージ。
var params = {
deviceId: '00:aa:bb:cc:dd',
serviceId: 'xxxx',
characteristicId: 'xxx'
};
window.WindVane.call('WVBluetooth', 'stopNotifications', params, function(e) {
}, function(e) {
alert('failure: ' + JSON.stringify(e));
}