6,7d5 < var pref=''; < 18c16 < async function oldonButtonClick() { --- > async function onButtonClick() { 121,282d118 < < async function newestonButtonClick() { < const controlServiceUUID = 0xfff0; // Full UUID < const commandCharacteristicUUID = 0xfff4; // < var myCharacteristic; < navigator.bluetooth.requestDevice({ < acceptAllDevices: true, < optionalServices: [controlServiceUUID] < < }) < < .then(device => { < console.log("Got device name: ", device.name); < console.log("id: ", device.id); < return device.gatt.connect(); < console.log("Here"); < }) < < .then(server => { < < serverInstance = server; < console.log("Getting PrimaryService"); < return server.getPrimaryService(controlServiceUUID); < }) < < .then(service => { < console.log("Getting Characteristic"); < return service.getCharacteristic(commandCharacteristicUUID); < }) < < .then(characteristic => { < // 0x01,3,0x02,0x03,0x01 < myCharacteristic = characteristic; < return myCharacteristic.startNotifications().then(_ => { < log('Notifications started'); < < myCharacteristic.addEventListener('characteristicvaluechanged', test); < }); < }) < .catch(function(error) { < console.log("Something went wrong. " + error); < }); < } < < function consolelog(incis) { < pref=incis + ' ... '; < document.getElementById('result').innerHTML+=incis + ''; < return console.log(incis); < } < < < async function onButtonClick() { < try { < consolelog('Requesting any Bluetooth Device...'); < const device = await navigator.bluetooth.requestDevice({ < // filters: [...] <- Prefer filters to save energy & show relevant devices. < acceptAllDevices: true, < optionalServices: ['device_information']}); < < < consolelog('Connecting to GATT Server...'); < const server = await device.gatt.connect(); < < consolelog('Getting Device Information Service...'); < const service = await server.getPrimaryService('device_information'); < < consolelog('Getting Device Information Characteristics...'); < const characteristics = await service.getCharacteristics(); < < const decoder = new TextDecoder('utf-8'); < for (const characteristic of characteristics) { < switch (characteristic.uuid) { < < case BluetoothUUID.getCharacteristic('manufacturer_name_string'): < await characteristic.readValue().then(value => { < consolelog('> Manufacturer Name String: ' + decoder.decode(value)); < }); < break; < < case BluetoothUUID.getCharacteristic('model_number_string'): < await characteristic.readValue().then(value => { < consolelog('> Model Number String: ' + decoder.decode(value)); < }); < break; < < case BluetoothUUID.getCharacteristic('hardware_revision_string'): < await characteristic.readValue().then(value => { < consolelog('> Hardware Revision String: ' + decoder.decode(value)); < }); < break; < < case BluetoothUUID.getCharacteristic('firmware_revision_string'): < await characteristic.readValue().then(value => { < consolelog('> Firmware Revision String: ' + decoder.decode(value)); < }); < break; < < case BluetoothUUID.getCharacteristic('software_revision_string'): < await characteristic.readValue().then(value => { < consolelog('> Software Revision String: ' + decoder.decode(value)); < }); < break; < < case BluetoothUUID.getCharacteristic('system_id'): < await characteristic.readValue().then(value => { < consolelog('> System ID: '); < consolelog(' > Manufacturer Identifier: ' + < padHex(value.getUint8(4)) + padHex(value.getUint8(3)) + < padHex(value.getUint8(2)) + padHex(value.getUint8(1)) + < padHex(value.getUint8(0))); < consolelog(' > Organizationally Unique Identifier: ' + < padHex(value.getUint8(7)) + padHex(value.getUint8(6)) + < padHex(value.getUint8(5))); < }); < break; < < case BluetoothUUID.getCharacteristic('ieee_11073-20601_regulatory_certification_data_list'): < await characteristic.readValue().then(value => { < consolelog('> IEEE 11073-20601 Regulatory Certification Data List: ' + < decoder.decode(value)); < }); < break; < < case BluetoothUUID.getCharacteristic('pnp_id'): < await characteristic.readValue().then(value => { < consolelog('> PnP ID:'); < consolelog(' > Vendor ID Source: ' + < (value.getUint8(0) === 1 ? 'Bluetooth' : 'USB')); < if (value.getUint8(0) === 1) { < consolelog(' > Vendor ID: ' + < (value.getUint8(1) | value.getUint8(2) << 8)); < } else { < consolelog(' > Vendor ID: ' + < getUsbVendorName(value.getUint8(1) | value.getUint8(2) << 8)); < } < consolelog(' > Product ID: ' + < (value.getUint8(3) | value.getUint8(4) << 8)); < consolelog(' > Product Version: ' + < (value.getUint8(5) | value.getUint8(6) << 8)); < }); < break; < < default: consolelog('> Unknown Characteristic: ' + characteristic.uuid); < } < } < } catch(error) { < document.getElementById('result').innerHTML+='Argh! ' + pref + error + ''; < console.log('Argh! ' + pref + error); < } < } < < /* Utils */ < < function padHex(value) { < return ('00' + value.toString(16).toUpperCase()).slice(-2); < } < < function getUsbVendorName(value) { < // Check out page source to see what valueToUsbVendorName object is. < return value + < (value in valueToUsbVendorName ? ' (' + valueToUsbVendorName[value] + ')' : ''); < } 286,293c122,123 <