Chrome 应用蓝牙
Chrome App bluetooth
我正在尝试创建一个 chrome 应用程序,它会在某个蓝牙设备发送数据时显示。具体来说,我有 2 个蓝牙鼠标,我想确定在特定时间移动了哪一个。
我遵循了 Chrome 开发文档并取得了成功,直到我尝试在接收时添加一个侦听器以查看来自设备的数据。我收到 "Cannot read property 'addListener' of undefined" 错误。
这是我开始收到此错误的时间:
Error message
这是我正在使用的代码
chrome.bluetooth.getDevices(function(devices) {
for (var i = 0; i < devices.length; i++) {
//Displaying device names
console.log(i+": "+devices[i].name);
}
//uuid for a specific device
var uuid = "00001200-0000-1000-8000-00805f9b34fb";
// var uuid = devices[4].uuid;
var onConnectedCallback = function() {
if (chrome.runtime.lastError) {
console.log("Connection failed: " + chrome.runtime.lastError.message);
} else {
// Profile implementation here.
}
};
chrome.bluetoothSocket.create(function(createInfo) {
chrome.bluetoothSocket.connect(createInfo.socketId,
devices[4].address, uuid, onConnectedCallback);
console.log(createInfo);
chrome.bluetoothSocket.onRecieve.addListener(function(receiveInfo) {
if (receiveInfo.socketId != socketId)
return;
console.log(receiveInfo);
});
});
});
我正在尝试创建一个 chrome 应用程序,它会在某个蓝牙设备发送数据时显示。具体来说,我有 2 个蓝牙鼠标,我想确定在特定时间移动了哪一个。 我遵循了 Chrome 开发文档并取得了成功,直到我尝试在接收时添加一个侦听器以查看来自设备的数据。我收到 "Cannot read property 'addListener' of undefined" 错误。
这是我开始收到此错误的时间: Error message
这是我正在使用的代码
chrome.bluetooth.getDevices(function(devices) {
for (var i = 0; i < devices.length; i++) {
//Displaying device names
console.log(i+": "+devices[i].name);
}
//uuid for a specific device
var uuid = "00001200-0000-1000-8000-00805f9b34fb";
// var uuid = devices[4].uuid;
var onConnectedCallback = function() {
if (chrome.runtime.lastError) {
console.log("Connection failed: " + chrome.runtime.lastError.message);
} else {
// Profile implementation here.
}
};
chrome.bluetoothSocket.create(function(createInfo) {
chrome.bluetoothSocket.connect(createInfo.socketId,
devices[4].address, uuid, onConnectedCallback);
console.log(createInfo);
chrome.bluetoothSocket.onRecieve.addListener(function(receiveInfo) {
if (receiveInfo.socketId != socketId)
return;
console.log(receiveInfo);
});
});
});