LoginSignup
1
1

More than 5 years have passed since last update.

Web ブラウザで Bluetooth デバイスをスキャンする

Posted at
  • Web Bluetooth を実装しているブラウザであれば、次のような非常に簡単なコードで Bluetooth デバイスをスキャンすることができます。
  • 注意点として、ユーザのアクション(ボタンのクリック等)により、コードを実行する必要があります。(セキュリティの観点から、そのように仕様が定義されています。
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>WebBleTest</title>
</head>
<body>

    <button onclick="scan()">scan</button>

    <script type="text/javascript">
    function scan() {
        navigator.bluetooth.requestDevice({
        acceptAllDevices: true
        })
        .catch(error => console.log(error))
    }
    </script>

</body>
</html>

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1