I have been trying to connect an iPhone 5 to OSX Chrome (Version 38.0.2096.0 dev) over BLE using chrome.bluetoothLowEnergy API.
I'm using BLE Utility on my iphone to simulate battery service. I can discover the service and connect to it using other phones or OSX utility, but I'm having problems doing so with chrome. I can see my device listed, but no services discovered and when I try to connect to the device, connection fails with the following message:
Operation failed
I would greatly appreciate any help.
Here is my code:
manifest.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);