MetaWearC + Web Bluetooth

edited June 2018 in JavaScript

Hi, I want to make a gyro controler gamepad for web game.
For connect to the MetaWearC I use Web Bluetooth API.
I need to reed data to identify the rotation, but the output of my program is always 0.

my code:

<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<button onclick="onButtonClick()">Click me</button>
<script>
function onButtonClick() {
navigator.bluetooth.requestDevice({
      acceptAllDevices: true,
      optionalServices: ['326a9000-85cb-9195-d9dd-464cfbbae75a']
})
  .then(device => {
    console.log('Connecting to GATT Server...');
    return device.gatt.connect();
  })
  .then(server => {
    console.log('Getting Device Information Service...');
    return server.getPrimaryService('326a9000-85cb-9195-d9dd-464cfbbae75a');
  })
  .then(service => {
    console.log('Getting Device Information Characteristics...');
    return service.getCharacteristics();
  })
  .then(characteristic => {
    console.log('Getting Characteristics Information Value...');
    characteristic[0].readValue().then(value => {
            console.log('> one: ' + value.getUint8(0));
          });
    characteristic[1].readValue().then(value => {
            console.log('> two: ' + value.getUint8(0));
          });
  })
  .catch(error => {
    console.log('Argh! ' + error);
  });
}
</script>
</body>
</html>

Comments

Sign In or Register to comment.