lundi 30 janvier 2017

chrome and bluetooth - connecting, discovering - how to make it working?

I am working on project that would discover nearby bluetooth devices via webpage.

Here are my limitations: - development under windows 7 or 10, android 5 on phone - peripheral is bluetooth beacon - central is phone with android 6

First of all i made a page looking like this:

<html>
<head>
  <script src="jquery-3.1.1.js"></script>
</head>
<body>

<div id="target" style="width: 100px; height: 100px; border: 1px solid red"></div>

<script>
$('#target').click(function() { 
  chrome.bluetooth.startDiscovery(function () { 
  navigator.bluetooth.requestDevice({ filters: [{ services:['battery_service'] }] })
  .then(device => {

    console.log(device);
  return device.gatt.connect();
  }).then(server => { console.log(server)}).catch(error  => { console.log(error); });
})
</script>
</body>
</html>

This piece of code lets me to pair bluetooth device with service called "battery_service" with webpage. And it is working (morover) - it opens "chrome system" window for searching nearby devices and finds one if only i have already paired it in windows. If it wasnt paired earlier it will find nothing. Chrome says that gatt server doesnt exist so i can not connect it, and object has gatt property that has gatt property that has gatt property (and so on to the infinity)

Anyways it returns device object containing device.name and device.id property. Other properties are undefined.

None of any examples i found on internet have been working for me.

So here are questions:

  1. is it possible to use windows as development platform?
  2. is it possible to use android 5 to be bluetooth perpiheral?
  3. what is the difference between chrome.bluetooth object and navigator.bluetooth object? Every tutorial uses chrome.bluetooth however it is undefined object in my chrome browser. Navigator.bluetooth works as mentioned before.
  4. i've found chrome.bluetooth.startDiscovery but navigator.bluetooth doesnt have such method, and chrome.bluetooth is empty object i can not discover it at all. Because i do not want even to connect to devices, but only know its presence is it possible not to pair the devices each time it comes into the bluetooth range?
  5. are there any working examples?
  6. should be windows pairing enough? Do we need for security reasons pair devices in chrome that are already paired by operating system?

I use CHROME 56.0.2924.76 64bit.

Thanks for any help! Kalreg




Aucun commentaire:

Enregistrer un commentaire