赞
踩
HTML 定义触发按钮
www/index.html
Web BluetoothSend And Receive!
navigator.bluetooth.requestDevice 必须在某个用户触发的回调内执行,例如在 button 元素的 onclick 事件中调用。在其它环境下调用将产生错误:
Must be handling a user gesture to show a permission request
JS 操作 Web Bluetooth
www/js/web-bluetooth.js
async function sendAndReceive() {
let device = await navigator.bluetooth.requestDevice({
filters: [
{services: [0xffe0]},
]
});
let server = await device.gatt.connect();
let service = await server.getPrimaryService(0xffe0);
let characteristic = await service.getCharacteristic(0xffe1);
characteristic.addEventListener(
'characteristicvaluechanged', e => {
console.log(e.target.value);
}
);
characteristic.startNotifications();
await characte
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。