diff options
-rw-r--r-- | tests/html/bluetooth_battery_level.html | 61 | ||||
-rw-r--r-- | tests/html/bluetooth_characteristic_info.html | 69 | ||||
-rw-r--r-- | tests/html/bluetooth_descriptor_info.html | 68 | ||||
-rw-r--r-- | tests/html/bluetooth_device_disconnect.html | 94 | ||||
-rw-r--r-- | tests/html/bluetooth_device_info.html | 59 | ||||
-rw-r--r-- | tests/html/bluetooth_primary_service_info.html | 57 |
6 files changed, 408 insertions, 0 deletions
diff --git a/tests/html/bluetooth_battery_level.html b/tests/html/bluetooth_battery_level.html new file mode 100644 index 00000000000..8618df07859 --- /dev/null +++ b/tests/html/bluetooth_battery_level.html @@ -0,0 +1,61 @@ +<!DOCTYPE html> +<html> +<title>Battery Level</title> +<body> + <input id="name" type="text" placeholder="Device Name"> + <input id="namePrefix" type="text" placeholder="Device Name Prefix"> + <button type="button" onclick="onButtonClick()">Get Bluetooth Device's Battery Level</button> + <pre id="log"></pre> + <script> + function onButtonClick() { + clear(); + var options = {filters: [{services: ['battery_service']}], optinalServices: []}; + + var filterName = document.getElementById('name').value; + if (filterName) + options.filters.push({name: filterName}); + + var filterNamePrefix = document.getElementById('namePrefix').value; + if (filterNamePrefix) + options.filters.push({namePrefix: filterNamePrefix}); + + try { + log('Requesting Bluetooth Device...'); + var bluetooth = window.navigator.bluetooth; + var device = bluetooth.requestDevice(options); + + log('Connecting to GATT Server on device...'); + var server = device.gatt.connect(); + + log('Getting Battery Service...'); + var service = server.getPrimaryService('battery_service'); + + log('Getting Battery Level Characteristic...'); + var characteristic = service.getCharacteristic('battery_level'); + + log('Reading Battery Level...'); + var value = AsciiToDecimal(characteristic.readValue()); + log('> Battery Level is ' + value + '%'); + } catch(err) { + log(err); + } + } + + function clear() { + document.getElementById("log").textContent = ""; + } + + function log(line) { + document.getElementById("log").textContent += line + '\n'; + } + + function AsciiToDecimal(bytestr) { + var result = []; + for(i = 0; i < bytestr.length; i++) { + result[i] = bytestr[i].charCodeAt(0) ; + } + return result; + } + </script> +</body> +</html> diff --git a/tests/html/bluetooth_characteristic_info.html b/tests/html/bluetooth_characteristic_info.html new file mode 100644 index 00000000000..84cebd83014 --- /dev/null +++ b/tests/html/bluetooth_characteristic_info.html @@ -0,0 +1,69 @@ +<!DOCTYPE html> +<html> +<title>Characteristic info</title> +<body> + <input id="service" type="text" autofocus placeholder="Bluetooth Service"> + <input id="characteristic" type="text" autofocus placeholder="Bluetooth Characteristic"> + <button type="button" onclick="onButtonClick()">Get Characteristic Info</button> + <pre id="log"></pre> + <script> + function onButtonClick() { + clear(); + var serviceUuid = document.getElementById('service').value; + if (serviceUuid.startsWith('0x')) + serviceUuid = parseInt(serviceUuid, 16); + + var characteristicUuid = document.getElementById('characteristic').value; + if (characteristicUuid.startsWith('0x')) + characteristicUuid = parseInt(characteristicUuid, 16); + + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service...'); + var primaryService = server.getPrimaryService(serviceUuid); + + log('Getting Characteristic...'); + var characteristic = primaryService.getCharacteristic(characteristicUuid); + + log('Characteristic found!'); + log('> Characteristic service: ' + characteristic.service.uuid); + log('> Characteristic UUID: ' + characteristic.uuid); + log('> Broadcast: ' + characteristic.properties.broadcast); + log('> Read: ' + characteristic.properties.read); + log('> Write w/o response: ' + characteristic.properties.writeWithoutResponse); + log('> Write: ' + characteristic.properties.write); + log('> Notify: ' + characteristic.properties.notify); + log('> Indicate: ' + characteristic.properties.indicate); + log('> Signed Write: ' + characteristic.properties.authenticatedSignedWrites); + log('> Queued Write: ' + characteristic.properties.reliableWrite); + log('> Writable Auxiliaries: ' + characteristic.properties.writableAuxiliaries); + characteristic.readValue(); + log('> Characteristic value: ' + AsciiToDecimal(characteristic.value)); + } catch(err) { + log(err); + } + } + + function clear() { + document.getElementById("log").textContent = ""; + } + + function log(line) { + document.getElementById("log").textContent += line + '\n'; + } + + function AsciiToDecimal(bytestr) { + var result = []; + for(i = 0; i < bytestr.length; i++) { + result[i] = bytestr[i].charCodeAt(0) ; + } + return result; + } + </script> +</body> +</html> diff --git a/tests/html/bluetooth_descriptor_info.html b/tests/html/bluetooth_descriptor_info.html new file mode 100644 index 00000000000..c657d217697 --- /dev/null +++ b/tests/html/bluetooth_descriptor_info.html @@ -0,0 +1,68 @@ +<!DOCTYPE html> +<html> +<title>Descriptor info</title> +<body> + <input id="service" type="text" autofocus placeholder="Bluetooth Service"> + <input id="characteristic" type="text" autofocus placeholder="Bluetooth Characteristic"> + <input id="descriptor" type="text" autofocus placeholder="Bluetooth Descriptor"> + <button type="button" onclick="onButtonClick()">Get Descriptor Info</button> + <pre id="log"></pre> + <script> + function onButtonClick() { + clear(); + var serviceUuid = document.getElementById('service').value; + if (serviceUuid.startsWith('0x')) + serviceUuid = parseInt(serviceUuid, 16); + + var characteristicUuid = document.getElementById('characteristic').value; + if (characteristicUuid.startsWith('0x')) + characteristicUuid = parseInt(characteristicUuid, 16); + + var descriptorUuid = document.getElementById('descriptor').value; + if (descriptorUuid.startsWith('0x')) + descriptorUuid = parseInt(descriptorUuid, 16); + + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]}); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service...'); + var primaryService = server.getPrimaryService(serviceUuid); + + log('Getting Characteristic...'); + var characteristic = primaryService.getCharacteristic(characteristicUuid); + + log('Getting Descriptor...'); + var descriptor = characteristic.getDescriptor(descriptorUuid); + + log('Descriptor found!'); + log('> Descriptor characteristic: ' + descriptor.characteristic.uuid); + log('> Descriptor UUID: ' + descriptor.uuid); + descriptor.readValue(); + log('> Descriptor value: ' + AsciiToDecimal(descriptor.value)); + } catch(err) { + log(err); + } + } + + function clear() { + document.getElementById("log").textContent = ""; + } + + function log(line) { + document.getElementById("log").textContent += line + '\n'; + } + + function AsciiToDecimal(bytestr) { + var result = []; + for(i = 0; i < bytestr.length; i++) { + result[i] = bytestr[i].charCodeAt(0) ; + } + return result; + } + </script> +</body> +</html> diff --git a/tests/html/bluetooth_device_disconnect.html b/tests/html/bluetooth_device_disconnect.html new file mode 100644 index 00000000000..715d3d16a24 --- /dev/null +++ b/tests/html/bluetooth_device_disconnect.html @@ -0,0 +1,94 @@ +<!DOCTYPE html> +<html> +<title>Device Disconnect</title> +<body> + <input id="service" type="text" autofocus placeholder="Bluetooth Service"> + <input id="name" type="text" placeholder="Device Name"> + <input id="namePrefix" type="text" placeholder="Device Name Prefix"> + <button type="button" onclick="onScanButtonClick()">Scan()</button> + <button type="button" onclick="onDisconnectButtonClick()">Disconnect()</button> + <button type="button" onclick="onReconnectButtonClick()">Reconnect()</button> + <pre id="log"></pre> + <script> + var bluetoothDevice; + + function onScanButtonClick() { + clear(); + var options = {filters: []}; + + var filterService = document.getElementById('service').value; + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); + + if (filterService) + options.filters.push({services: [filterService]}); + + var filterName = document.getElementById('name').value; + if (filterName) + options.filters.push({name: filterName}); + + var filterNamePrefix = document.getElementById('namePrefix').value; + if (filterNamePrefix) + options.filters.push({namePrefix: filterNamePrefix}); + + bluetoothDevice = null; + + try { + log('Requesting Bluetooth Device...'); + bluetoothDevice = window.navigator.bluetooth.requestDevice(options); + connect(); + } catch(err) { + log(err); + } + } + + function onDisconnectButtonClick() { + clear(); + if (!bluetoothDevice) + return; + + try { + log('Disconnecting from Bluetooth Device...'); + if (bluetoothDevice.gatt.connected) { + bluetoothDevice.gatt.disconnect(); + log('> Bluetooth Device connected: ' + bluetoothDevice.gatt.connected); + } else { + log('> Bluetooth Device is already disconnected'); + } + } catch(err) { + log(err); + } + } + + function onReconnectButtonClick() { + clear(); + if (!bluetoothDevice) + log('> There is no connected Bluetooth Device instance') + if (bluetoothDevice.gatt.connected) { + log('> Bluetooth Device is already connected'); + return; + } else { + connect(); + } + } + + function connect() { + try { + log('Connecting to Bluetooth Device...'); + bluetoothDevice.gatt.connect(); + log('> Bluetooth Device connected: ' + bluetoothDevice.gatt.connected); + } catch(err) { + log(err); + } + } + + function clear() { + document.getElementById("log").textContent = ""; + } + + function log(line) { + document.getElementById("log").textContent += line + '\n'; + } + </script> +</body> +</html> diff --git a/tests/html/bluetooth_device_info.html b/tests/html/bluetooth_device_info.html new file mode 100644 index 00000000000..0cdc09a95ab --- /dev/null +++ b/tests/html/bluetooth_device_info.html @@ -0,0 +1,59 @@ +<!DOCTYPE html> +<html> +<title>Device Info</title> +<body> + <input id="service" type="text" autofocus placeholder="Bluetooth Service"> + <input id="name" type="text" placeholder="Device Name"> + <input id="namePrefix" type="text" placeholder="Device Name Prefix"> + <button type="button" onclick="onButtonClick()">Get Bluetooth Device Info</button> + <pre id="log"></pre> + <script> + function onButtonClick() { + clear(); + var options = {filters: [], optinalServices: []}; + + var filterService = document.getElementById('service').value; + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); + + if (filterService) + options.filters.push({services: [filterService]}); + + var filterName = document.getElementById('name').value; + if (filterName) + options.filters.push({name: filterName}); + + var filterNamePrefix = document.getElementById('namePrefix').value; + if (filterNamePrefix) + options.filters.push({namePrefix: filterNamePrefix}); + + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(options); + + log('Found a device!'); + log('> Name: ' + device.name); + log('> Id: ' + device.id); + log('> Device Class: ' + device.deviceClass); + log('> Vendor Id Source: ' + device.vendorIDSource); + log('> Vendor Id: ' + device.vendorID); + log('> Product Id: ' + device.productID); + log('> Product Version: ' + device.productVersion); + log('> Appearance: ' + device.adData.appearance); + log('> Tx Power: ' + device.adData.txPower + ' dBm'); + log('> RSSI: ' + device.adData.rssi + ' dBm'); + } catch(err) { + log(err); + } + } + + function clear() { + document.getElementById("log").textContent = ""; + } + + function log(line) { + document.getElementById("log").textContent += line + '\n'; + } + </script> +</body> +</html> diff --git a/tests/html/bluetooth_primary_service_info.html b/tests/html/bluetooth_primary_service_info.html new file mode 100644 index 00000000000..606d342c85d --- /dev/null +++ b/tests/html/bluetooth_primary_service_info.html @@ -0,0 +1,57 @@ +<!DOCTYPE html> +<html> +<title>Primary Service info</title> +<body> + <input id="service" type="text" autofocus placeholder="Bluetooth Service"> + <input id="name" type="text" placeholder="Device Name"> + <input id="namePrefix" type="text" placeholder="Device Name Prefix"> + <button type="button" onclick="onButtonClick()">Get Primary Service Info</button> + <pre id="log"></pre> + <script> + function onButtonClick() { + clear(); + var options = {filters: [], optinalServices: []}; + + var filterService = document.getElementById('service').value; + if (filterService.startsWith('0x')) + filterService = parseInt(filterService, 16); + + if (filterService) + options.filters.push({services: [filterService]}); + + var filterName = document.getElementById('name').value; + if (filterName) + options.filters.push({name: filterName}); + + var filterNamePrefix = document.getElementById('namePrefix').value; + if (filterNamePrefix) + options.filters.push({namePrefix: filterNamePrefix}); + + try { + log('Requesting Bluetooth Device...'); + var device = window.navigator.bluetooth.requestDevice(options); + + log('Connecting to GATTserver on device...'); + var server = device.gatt.connect(); + + log('Getting Primary Service...'); + var primaryService = server.getPrimaryService(filterService); + + log('Primary Service found on device: ' + primaryService.device.name); + log('> UUID: ' + primaryService.uuid); + log('> Is primary: ' + primaryService.isPrimary); + } catch(err) { + log(err); + } + } + + function clear() { + document.getElementById("log").textContent = ""; + } + + function log(line) { + document.getElementById("log").textContent += line + '\n'; + } + </script> +</body> +</html> |