html5 如何读写蓝牙? |
您所在的位置:网站首页 › h5调用蓝牙 › html5 如何读写蓝牙? |
浏览器和蓝牙设备对接的标准Web-Bluetooth API已经发布了。 这是起草的团队: Web Bluetooth Community Group这是介绍: https://dev.opera.com/articles/web-bluetooth-intro/以下是以上链接介绍的简单列子Here is a very simple example, showing a button: Try it…and the following JavaScript: const button = document.querySelector('#the-button'); button.addEventListener('click', function() { navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] }).then(device => { console.log('Got device:', device.name); console.log('id:', device.id); }); });As mentioned earlier, the method navigator.bluetooth.requestDevice() can only be called in response to a user action like a button click. This method calls up a dialog box showing the list of available BLE devices matching the query filter. In our case, the filter we have set pertains to BLE devices which expose a so-called “GATT service” called battery_service. We’ll find out more about GATT services in the next section. 大家可以实验下。我想利用他在微信浏览器里面控制蓝牙设备,目前还是设想,下一步去运行下他们的例子。可行的话,我觉得这个标准实现的功能前景将相当远大~ |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |