如何获得有效的UUID?

时间:2014-07-07 06:08:32

标签: javascript google-chrome bluetooth google-chrome-app

我一直在为一个项目使用Chrome的蓝牙API,但自从上周玩它以来,我似乎遇到了一个问题。

我可以扫描附近的设备,并在列表中显示这些设备。当涉及到实际连接时,我收到此错误:" 连接失败:无效的UUID "

有问题的UUID,fa87c0d0-afac-11de-8a39-0800200c9a66似乎有效。它与我在Android应用程序中使用的UUID相同。

文档似乎没有帮助。究竟是什么导致了这个错误,我该如何解决?以下是我的清单。

 {
  "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);
    });   
}

0 个答案:

没有答案