MetaWearC + Web Bluetooth
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>
This discussion has been closed.
Comments
MetaWear uses characteristic notifications not reads to send data. I suggest looking through the initialization code of one of the APIs to see a typical setup flow:
https://github.com/mbientlab/MetaWear-SDK-CSharp/blob/1.0.15/MetaWear/Impl/MetaWearBoard.cs#L756