我想使用 chrome 应用程序连接我的蓝牙遥控器,但我收到以下错误“不支持蓝牙 L2CAP 协议”我想在不使用 Windows 支持的情况下将我的蓝牙遥控器或移动设备与 chrome 应用程序连接。请帮助问候
var main = (function() {
// GATT Device Information Service UUIDs
var DEVICE_INFO_SERVICE_UUID = '0000180a-0000-1000-8000-00805f9b34fb';
var MANUFACTURER_NAME_STRING_UUID = '00002a29-0000-1000-8000-00805f9b34fb';
var SERIAL_NUMBER_STRING_UUID = '00002a25-0000-1000-8000-00805f9b34fb';
var HARDWARE_REVISION_STRING_UUID = '00002a27-0000-1000-8000-00805f9b34fb';
var FIRMWARE_REVISION_STRING_UUID = '00002a26-0000-1000-8000-00805f9b34fb';
var SOFTWARE_REVISION_STRING_UUID = '00002a28-0000-1000-8000-00805f9b34fb';
var PNP_ID_UUID = '00002a50-0000-1000-8000-00805f9b34fb';
function DeviceInfoDemo() {
// A mapping from device addresses to device names for found devices that
// expose a Battery service.
this.deviceMap_ = {};
// The currently selected service and its characteristics.
this.service_ = null;
this.chrcMap_ = {};
this.discovering_ = false;
}
/**
* Sets up the UI for the given service.
*/
DeviceInfoDemo.prototype.selectService = function(service) {
// Hide or show the appropriate elements based on whether or not
// |serviceId| is undefined.
UI.getInstance().resetState(!service);
this.service_ = service;
this.chrcMap_ = {};
if (!service) {
console.log('No service selected.');
return;
}
console.log('GATT service selected: ' + service.instanceId);
// Get the characteristics of the selected service.
var self = this;
chrome.bluetoothLowEnergy.getCharacteristics(service.instanceId,
function (chrcs) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
// Make sure that the same service is still selected.
if (service.instanceId != self.service_.instanceId)
return;
if (chrcs.length == 0) {
console.log('Service has no characteristics: ' + service.instanceId);
return;
}
chrcs.forEach(function (chrc) {
var fieldId;
var valueDisplayFunction = UI.getInstance().setStringValue;
if (chrc.uuid == MANUFACTURER_NAME_STRING_UUID) {
console.log('Setting Manufacturer Name String Characteristic: ' +
chrc.instanceId);
fieldId = 'manufacturer-name-string';
} else if (chrc.uuid == SERIAL_NUMBER_STRING_UUID) {
console.log('Setting Serial Number String Characteristic: ' +
chrc.instanceId);
fieldId = 'serial-number-string';
} else if (chrc.uuid == HARDWARE_REVISION_STRING_UUID) {
console.log('Setting Hardware Revision String Characteristic: ' +
chrc.instanceId);
fieldId = 'hardware-revision-string';
} else if (chrc.uuid == FIRMWARE_REVISION_STRING_UUID) {
console.log('Setting Firmware Revision String Characteristic: ' +
chrc.instanceId);
fieldId = 'firmware-revision-string';
} else if (chrc.uuid == SOFTWARE_REVISION_STRING_UUID) {
console.log('Setting Software Revision String Characteristic: ' +
chrc.instanceId);
fieldId = 'software-revision-string';
} else if (chrc.uuid == PNP_ID_UUID) {
console.log('Setting PnP ID Characteristic: ' + chrc.instanceId);
fieldId = 'pnp-id';
valueDisplayFunction = UI.getInstance().setPnpIdValue;
}
if (fieldId === undefined) {
console.log('Ignoring characteristic "' + chrc.instanceId +
'" with UUID ' + chrc.uuid);
return;
}
self.chrcMap_[fieldId] = chrc;
// Read the value of the characteristic and store it.
chrome.bluetoothLowEnergy.readCharacteristicValue(chrc.instanceId,
function (readChrc) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
// Make sure that the same characteristic is still selected.
if (!self.chrcMap_.hasOwnProperty(fieldId) ||
self.chrcMap_[fieldId].instanceId != readChrc.instanceId)
return;
self.chrcMap_[fieldId] = readChrc;
valueDisplayFunction(fieldId, readChrc.value);
});
});
});
};
DeviceInfoDemo.prototype.updateDiscoveryToggleState = function(discovering) {
if (this.discovering_ !== discovering) {
this.discovering_ = discovering;
UI.getInstance().setDiscoveryToggleState(this.discovering_);
}
};
DeviceInfoDemo.prototype.init = function() {
// Set up the UI to look like no device was initially selected.
this.selectService(null);
// Store the |this| to be used by API callbacks below.
var self = this;
// Request information about the local Bluetooth adapter to be displayed in
// the UI.
var updateAdapterState = function(adapterState) {
UI.getInstance().setAdapterState(adapterState.address, adapterState.name);
self.updateDiscoveryToggleState(adapterState.discovering);
};
chrome.bluetooth.getAdapterState(function (adapterState) {
if (chrome.runtime.lastError)
console.log(chrome.runtime.lastError.message);
self.updateDiscoveryToggleState(adapterState.discovering);
updateAdapterState(adapterState);
});
chrome.bluetooth.onAdapterStateChanged.addListener(updateAdapterState);
// Helper functions used below.
var isKnownDevice = function(deviceAddress) {
return self.deviceMap_.hasOwnProperty(deviceAddress);
};
var storeDevice = function(deviceAddress, device) {
var resetUI = false;
if (device == null) {
delete self.deviceMap_[deviceAddress];
resetUI = true;
} else {
self.deviceMap_[deviceAddress] =
(device.name ? device.name : device.address);
}
// Update the selector UI with the new device list.
UI.getInstance().updateDeviceSelector(self.deviceMap_, resetUI);
};
// Initialize the device map.
chrome.bluetooth.getDevices(function(devices) {
for (var i = 0; i < devices.length; i++) {
//console.log(devices[i].address);
//console.log(devices[i].name);
}
//-------------------------------------------------
var device_names = {};
var updateDeviceName = function(device) {
device_names[device.address] = device.name;
if(device.name == 'Advanced Touch REMOTE')
{
console.log(device.address);
var uuid = '1124';
var onConnectedCallback = function() {
if (chrome.runtime.lastError) {
console.log("Connection failed: " + chrome.runtime.lastError.message);
console.log("Socket: " + JSON.stringify(device));
} else {
console.log('Connected to Remote');
console.log("Socket: " + JSON.stringify(device));
}
};
chrome.bluetoothSocket.create(function(createInfo) {
chrome.bluetoothSocket.connect(createInfo.socketId,
device.address, uuid, onConnectedCallback);
});
}
console.log(device.address);
console.log(device.name);
storeDevice(device.address, device);
};
var removeDeviceName = function(device) {
delete device_names[device.address];
}
// Add listeners to receive newly found devices and updates
// to the previously known devices.
chrome.bluetooth.onDeviceAdded.addListener(updateDeviceName);
chrome.bluetooth.onDeviceChanged.addListener(updateDeviceName);
chrome.bluetooth.onDeviceRemoved.addListener(removeDeviceName);
// With the listeners in place, get the list of devices found in
// previous discovery sessions, or any currently active ones,
// along with paired devices.
chrome.bluetooth.getDevices(function(devices) {
for (var i = 0; i < devices.length; i++) {
updateDeviceName(devices[i]);
}
});
// Now begin the discovery process.
chrome.bluetooth.startDiscovery(function() {
// Stop discovery after 30 seconds.
setTimeout(function() {
chrome.bluetooth.stopDiscovery(function() {});
}, 25000);
});
//-------------------------------------------------
});
};
return {
DeviceInfoDemo: DeviceInfoDemo
};
})();
document.addEventListener('DOMContentLoaded', function() {
var demo = new main.DeviceInfoDemo();
demo.init();
});
body {
margin: 0;
overflow: hidden;
}
#header {
padding: 10px 15px 5px 15px;
background: #fafafa;
box-shadow: 0 0 5px #858585;
}
#header img {
width: 50px;
}
#header h1 {
font-family: 'DejaVu Sans Light', Verdana, sans-serif;
font-weight: normal;
vertical-align: top;
display: inline-block;
margin: 8px;
white-space: nowrap;
overflow: hidden;
}
#adapter-status {
float: right;
margin-top: 2px;
}
#adapter-address {
font-weight: bold;
}
ul {
padding-left: 0;
margin: inherit;
}
ul li {
list-style-type: none;
}
#device-selection-div {
margin-top: 5px;
}
#device-selector {
background: transparent;
border: 1px solid #aaa;
color: #454545;
font-style: italic;
}
#discovery-toggle-button {
background: transparent;
border: 1px solid #aaa;
color: #454545;
font-style: italic;
}
hr {
border: 0;
height: 0;
border-top: 1px solid rgba(0,0,0,0.12);
border-bottom: 1px solid rgba(255,255,255,0.3);
}
#no-devices-error {
font-size: 10pt;
text-align: center;
padding-top: 15%;
}
#info-div {
height: 245px;
box-sizing: border-box;
margin: 10px;
padding: 10px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.65);
overflow-y: scroll;
overflow-x: hidden;
word-break: break-all;
color: #333;
}
.device-info-field {
margin-bottom: 6px;
font-weight: bold;
}
div.device-info-field span {
font-style: italic;
font-weight: normal;
}
<!DOCTYPE html>
<html>
<head>
<title>Bluetooth LE Device Information Service Demo</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="ui.js"></script>
<script src="main.js"></script>
</head>
<body>
<div id="header">
<img src="bluetooth.png" alt="bluetooth icon">
<h1>BLE Device Information Service</h1>
<div id="adapter-status">
<ul>
<li><span id="adapter-name"></span></li>
<li><span id="adapter-address"></span></li>
</ul>
</div>
<hr>
<div id="device-selection-div">
Select device with Device Information Service:
<select id="device-selector">
<option id="placeholder" value="" disabled selected>
No connected devices
</option>
</select>
<button type="button" id="discovery-toggle-button">
start discovery
</button>
</div>
</div>
<div id="no-devices-error">
No device with "Device Information Service" selected.
</div>
<div id="info-div">
<div class="device-info-field">
Manufacturer Name: <span id="manufacturer-name-string">-</span>
</div>
<div class="device-info-field">
Serial Number: <span id="serial-number-string">-</span>
</div>
<div class="device-info-field">
Hardware Revision: <span id="hardware-revision-string">-</span>
</div>
<div class="device-info-field">
Firmware Revision: <span id="firmware-revision-string">-</span>
</div>
<div class="device-info-field">
Software Revision: <span id="software-revision-string">-</span>
</div>
<div class="device-info-field">
Vendor ID Source: <span id="vendor-id-source">-</span>
</div>
<div class="device-info-field">
Vendor ID: <span id="vendor-id">-</span>
</div>
<div class="device-info-field">
Product ID: <span id="product-id">-</span>
</div>
<div class="device-info-field">
Product Version: <span id="product-version">-</span>
</div>
</div>
</body>
</html>
问候