|
|
|
|
@ -1,12 +1,74 @@
|
|
|
|
|
const startButton = document.getElementById("start");
|
|
|
|
|
|
|
|
|
|
console.log(navigator.bluetooth);
|
|
|
|
|
|
|
|
|
|
const devices = await navigator.bluetooth.getDevices();
|
|
|
|
|
|
|
|
|
|
devices.forEach(async (device) => {
|
|
|
|
|
const gattServer = await device.gatt.connect();
|
|
|
|
|
const primaryService = await gattServer.getPrimaryService(0x1800);
|
|
|
|
|
const MANUFACTURER_UUID = 0x2a29;
|
|
|
|
|
const MODEL_UUID = 0x2a0a;
|
|
|
|
|
const char = await primaryService.getCharacteristic(MODEL_UUID);
|
|
|
|
|
const val = await char.readValue();
|
|
|
|
|
//const char2 = await primaryService.getCharacteristic(MODEL_UUID);
|
|
|
|
|
//const val2 = await char2.readValue();
|
|
|
|
|
const decoder = new TextDecoder("utf-8");
|
|
|
|
|
const manufacturer = decoder.decode(val);
|
|
|
|
|
//const model = decoder.decode(val2);
|
|
|
|
|
console.log("Manufacturer:", manufacturer);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
startButton.addEventListener("click", async () => {
|
|
|
|
|
try {
|
|
|
|
|
const devices = await navigator.bluetooth.getDevices();
|
|
|
|
|
console.log(2, devices);
|
|
|
|
|
const device = await navigator.bluetooth.requestDevice({
|
|
|
|
|
filters: [{ services: [0x180d] }],
|
|
|
|
|
optionalServices: [
|
|
|
|
|
0x1818, // Cycling Power – watts, torque, crank torque, etc.
|
|
|
|
|
0x1816, // Cycling Speed & Cadence – speed, cadence, distance
|
|
|
|
|
0x180d, // Heart Rate – optional, if the trainer includes an HR sensor
|
|
|
|
|
0x180f, // Battery Service – trainer battery level (if battery‑powered)
|
|
|
|
|
0x180a, // Device Information – manufacturer, model, firmware version
|
|
|
|
|
0x1800,
|
|
|
|
|
// add any custom 128‑bit UUIDs as strings, e.g.
|
|
|
|
|
// '0000abcd-0000-1000-8000-00805f9b34fb'
|
|
|
|
|
],
|
|
|
|
|
acceptAllDevices: true,
|
|
|
|
|
});
|
|
|
|
|
console.log(device);
|
|
|
|
|
|
|
|
|
|
const server = await device.gatt.connect();
|
|
|
|
|
|
|
|
|
|
console.log(await server.getPrimaryServices());
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// startButton.addEventListener("click", async () => {
|
|
|
|
|
// try {
|
|
|
|
|
// const devices = await navigator.bluetooth.getDevices();
|
|
|
|
|
// console.log(2, devices);
|
|
|
|
|
// const device = await navigator.bluetooth.requestDevice({
|
|
|
|
|
// //filters: [{ services: ["heart_rate"] }],
|
|
|
|
|
// optionalServices: [
|
|
|
|
|
// 0x1818, // Cycling Power – watts, torque, crank torque, etc.
|
|
|
|
|
// 0x1816, // Cycling Speed & Cadence – speed, cadence, distance
|
|
|
|
|
// 0x180d, // Heart Rate – optional, if the trainer includes an HR sensor
|
|
|
|
|
// 0x180f, // Battery Service – trainer battery level (if battery‑powered)
|
|
|
|
|
// 0x180a, // Device Information – manufacturer, model, firmware version
|
|
|
|
|
// 0x1800,
|
|
|
|
|
// // add any custom 128‑bit UUIDs as strings, e.g.
|
|
|
|
|
// // '0000abcd-0000-1000-8000-00805f9b34fb'
|
|
|
|
|
// ],
|
|
|
|
|
// acceptAllDevices: true,
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// const server = await device.gatt.connect();
|
|
|
|
|
|
|
|
|
|
// console.log(await server.getPrimaryServices());
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.log(error);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|