7
2

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 3 years have passed since last update.

Raspberry Pi で iPhoneを探す(iBeacon)

Last updated at Posted at 2020-06-16

やりたいこと

  1. iPhoneでibeaconを発信して、Raspberry Piでそれを受信する
  2. 信号強度から距離を計算する

iBeacon発信

iPhoneのアプリ(Beacon入門, 無料)を使用

発信方法

「ビーコン発信」の画面でこの矢印をタップするだけ
iOS の画像 (1).png
これで発信できます
iOS の画像 (3).png

iBeacon受信

Raspberry Pi 3B+を使用
受信用のプログラムを作成

実行用コード

scan.js

var Log4js = require('log4js');

Log4js.configure("log_config.json");

var logger = Log4js.getLogger('system');


Bleacon = require('bleacon');
Bleacon.startScanning();

Bleacon.on('discover', function(bleacon) {
   console.dir(bleacon);
   logger.info(JSON.stringify(bleacon));
});

ログ設定ファイル

log_config.json
{
    "appenders": {
        "default_appenders":{
            "type":     "file",
            "filename": "./logs/system.log",
            "pattern":  "-yyyy-MM-dd",
            "maxLogSize": 10000000,
            "backups": 100
        }
    },
    "categories": {
        "default":{
            "appenders":["default_appenders"],
            "level": "INFO"
        }
    }
}

あとはこれを実行するだけ
ログはこんな感じ

[2020-05-21T23:19:54.235] [INFO] system - {"uuid":"485344424c45414480c01800ffffffff","major":100,"minor":1,"measuredPower":-59,"rssi":-69,"accuracy":1.8809104243859365,"proximity":"near"}
[2020-05-21T23:19:54.299] [INFO] system - {"uuid":"485344424c45414480c01800ffffffff","major":100,"minor":1,"measuredPower":-59,"rssi":-61,"accuracy":1.1346805817813888,"proximity":"near"}

距離計算

発信信号強度(TxPower)と受信信号強度(RSSI)を使って距離が求められる

RSSI = TxPower - 20 * lg(d)
d=10^\frac{TxPower-RSSI}{20}

(参考)テスト

iPhoneを持ってRaspberry Piの前を通り過ぎてみる
bluetooth_log.png

7
2
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
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?