Okei, elikkäs miten saa oikeudet omaan ruuvi tagiin nettisivun kautta ruuvitagin yhdistämiseen?
Onko tästä javascript koodi apua tiedossa tai aiheesta dokumentaatiota?
declare global {
interface Navigator {
bluetooth: {
requestDevice(options?: any): Promise<BluetoothDevice>;
};
}
}
b() {
// In your .ts file
navigator.bluetooth
.requestDevice({ acceptAllDevices: true })
.then((device) => {
console.log(device);
})
.catch((error) => {
console.log(error);
});
}
b2() {
navigator.bluetooth
.requestDevice({ acceptAllDevices: true })
.then((device: any) => {
// Add the "any" type annotation
return device.gatt.connect();
})
.then((server) => {
// Step 2: Get a reference to the service
return server.getPrimaryService('battery_service'); // Replace 'battery_service' with your service
})
.then((service) => {
// Step 3: Get a reference to the characteristic
return service.getCharacteristic('battery_level'); // Replace 'battery_level' with your characteristic
})
.then((characteristic) => {
// Step 4: Read the value
return characteristic.readValue();
})
.then((value) => {
// Log the value
console.log('Battery level is ' + value.getUint8(0) + '%');
})
.catch((error) => {
console.log(error);
});
}