Javascript 如何实现有效的UUID?
我一直在为一个项目使用Chrome的蓝牙API,但自从上周使用它以来,我似乎遇到了一个问题 我能够扫描附近的设备,并在列表中显示这些设备。当涉及到实际连接时,我会遇到以下错误:“连接失败:UUID无效” 所述UUID fa87c0d0-afac-11de-8a39-0800200c9a66似乎有效。它与我在Android应用程序中使用的UUID相同 文档似乎没有帮助。到底是什么导致了这个错误,我该如何解决它?下面是我的舱单Javascript 如何实现有效的UUID?,javascript,google-chrome,bluetooth,google-chrome-app,Javascript,Google Chrome,Bluetooth,Google Chrome App,我一直在为一个项目使用Chrome的蓝牙API,但自从上周使用它以来,我似乎遇到了一个问题 我能够扫描附近的设备,并在列表中显示这些设备。当涉及到实际连接时,我会遇到以下错误:“连接失败:UUID无效” 所述UUID fa87c0d0-afac-11de-8a39-0800200c9a66似乎有效。它与我在Android应用程序中使用的UUID相同 文档似乎没有帮助。到底是什么导致了这个错误,我该如何解决它?下面是我的舱单 { "manifest_version": 2, "name"
{
"manifest_version": 2,
"name": "Bluetooth Bridge",
"version": "1.1",
"icons": {
"16": "icon.png",
"128": "icon.png"
},
"app": {
"background": {
"scripts": ["main.js"]
}
},
"permissions": [
{"fileSystem": ["directory"]},
{
"bluetooth": [
{
"socket": true,
"uuids": ["fa87c0d0-afac-11de-8a39-0800200c9a66", "8ce255c0-200a-11e0-ac64-0800200c9a66"],
"low_energy": true
}
]
}
],
"bluetooth": {
"socket": true,
"uuids": ["fa87c0d0-afac-11de-8a39-0800200c9a66", "8ce255c0-200a-11e0-ac64-0800200c9a66"],
"low_energy": true
}
}
这是我的代码:
function connectTo(address) {
app.getElementById("bluetoothconnect").innerHTML = "Trying to establish connection to "+device_names[address];
var uuid = '8ce255c0-200a-11e0-ac64-0800200c9a66';
console.log(uuid);
var onConnectedCallback = function() {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError);
console.log("Connection failed: " + chrome.runtime.lastError.message);
app.getElementById("bluetoothconnect").innerHTML = "Could not connect. "+chrome.runtime.lastError.message+".";
} else {
// Profile implementation here.
console.log("Profile Implementation");
app.getElementById('bluetoothconnect').innerHTML = "Successfully connected to "+device_names[address];
app.getElementById('service').disabled = false;
app.getElementById('devicenames').setAttribute('class', 'disabled');
app.getElementById('service').addEventListener('click', function() {
console.log("click");
startService();
});
app.getElementById('disconnect').addEventListener('click', function() {
chrome.bluetoothSocket.disconnect(window.socketId);
app.getElementById('bluetoothstatus').innerHTML = "Nothing doing";
app.getElementById('bluetoothconnect').innerHTML = "Not connected";
app.getElementById('service').disabled = false;
app.getElementById('disconnect').disabled = true;
});
}
};
chrome.bluetoothSocket.create(function(createInfo) {
window.socketId = createInfo.socketId;
chrome.bluetoothSocket.connect(createInfo.socketId,
address, uuid, onConnectedCallback);
});
}