【问题标题】:Connecting to an iOS device using the chrome.bluetoothLowEnergy API使用 chrome.bluetoothLowEnergy API 连接到 iOS 设备
【发布时间】:2014-09-12 21:19:54
【问题描述】:

我一直在尝试使用 chrome.bluetoothLowEnergy API 通过 BLE 将 iPhone 5 连接到 OSX Chrome(版本 38.0.2096.0 dev)。

我在我的 iPhone 上使用BLE Utility 来模拟电池服务。我可以使用其他手机或OSX utility 发现该服务并连接到它,但我在使用 chrome 时遇到了问题。我可以看到我的设备已列出,但未发现任何服务,当我尝试连接到该设备时,连接失败并显示以下消息:

操作失败

如果有任何帮助,我将不胜感激。

这是我的代码:

ma​​nifest.json

{
  "name": "BLE Test",
  "description": "Chrome BLE Test",
  "version": "1",
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "bluetooth": {
    "low_energy": true,
    "uuids": ["180f"]
  }
}

index.html

<!DOCTYPE HTML>
<html>
  <head>
    <title>Chrome BLE Test</title> 
    <script type="text/javascript" src="script.js"></script>
  </head>
  <body>
  </body>
</html>

script.js

function main() {
  var onGetServicesCallback = function(services) {
    if (chrome.runtime.lastError) {
      console.log(chrome.runtime.lastError.message);
      return;
    }

    console.log('Services:', services.length);

    if (!services) {
      console.log('No services');
      return;
    }

    services.forEach(function(service) {
      console.log(service);
    });
  }

  chrome.bluetooth.getDevices(function(devices) {
    if (chrome.runtime.lastError) {
      console.log(chrome.runtime.lastError.message);
      return;
    }
    console.log('Found devices:', devices.length);

    if (devices) {
      devices.forEach(function(device) {
        console.log('Device name:', device.name);
        chrome.bluetoothLowEnergy.getServices(device.address, onGetServicesCallback);

        chrome.bluetoothLowEnergy.connect(device.address, function() {
          if (chrome.runtime.lastError) {
            console.log('Connection failed:', chrome.runtime.lastError.message);
            return;
          }
          console.log('Connected!');
        });
      });
    }
  });
}

document.addEventListener('DOMContentLoaded', main);

【问题讨论】:

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


    【解决方案1】:

    据我所知,Mac 的 BLE 实施尚未完成。跟踪 API 开发的一个好地方是 Chrome 问题跟踪器。 This is a link 专门针对与 Mac 相关的问题。要查看所有蓝牙更改,只需在未解决的问题下搜索蓝牙即可。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 2013-11-08
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多