4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ESP32 での BLEScan メモ

Posted at

ESP32での BLEScan メモ

BlueToothデバイスのスキャンを行う時に、 BLEScanクラスを使いますが、パラメータ等で不明な部分があったので調査とその結果のメモです。

setInterval()と setWindows()と start()の関係

スキャンを行うパラメータとして、Intervalと Windowと、startに与えるスキャン時間がありますが、その関係を実際にプログラムを動かしてその挙動から調査しました。

  • Window = 実際のスキャンを行う時間(ミリ秒)
  • Intercal = スキャン間隔(ミリ秒)
  • start(時間) = スキャン全体の時間(秒)

少しわかりにくいので図示するとこのような関係になります。
image.png

  • Window ≧ Inteval ≧ start時間*1000
    の関係になります。

start()時間が残っている限り、スキャンが繰り返されるようです。interval途中でもstart時間がすぎるとスキャンは打ち切られるようです。

(interval - window) で生まれる間隔に意味があるか

長さを変えても、実験の範囲では有意な変化は見られませんでした

start時間の長さに意味があるか

実験上は、60秒のstart処理よりも1秒のstart処理を60回行ったほうが、検出回数がはるかに多くなりました。(同じデバイスの重複検出を含む)
仕組みは不明ながら、startでの検出イベントの発生は、時間が経つほどどんどん少なくなります。

ストラテジ

実験の結果から、 interlval = window = start時間で、 値は1,2秒、これをループで回すというのが一番スキャナとしては使いやすいと感じました。
Scanのコールバックの中で処理を行うのであればいいですが、コールバックでは検出のみを記録し、Scan後に処理を行うなどの場合は、Scan時間を短くしたいという事情もあります。

4
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?