LoginSignup
2
3

More than 5 years have passed since last update.

【メモ】BLE Nano 2 で iBeacon発信

Last updated at Posted at 2017-05-12

RedBearLabのBLE Nano 2(nRF52832)でiBeaconを発信してみた。
とりあえず規格最短の20msで発信しまくる。

開発環境

macOS Sierra 10.12.4でArduinoを使う。
ArduinoCommunityLogo.png

手順

Boards ManagerにBLE_Nano2を追加しないといけないので注意。
Preferences->Setting->Additional Boards Manager URLsにhttps://redbearlab.github.io/arduino/package_redbear_nRF5x_beta_index.json
を追加。
スクリーンショット 2017-05-09 13.04.05.png

Tools->Boards:->Boards Managerで「RedBear nRF52832 Boards」をインストール。
スクリーンショット 2017-08-01 17.28.55.png

Tools->Boards:からBLE_Nano2を選択。

BLE_Nano2を選択するとFile->ExamplesにExamples for BLE_Nano2が出現する。

詳しくはここ

ソースコード

とりあえずひたすらビーコンを出すだけのプログラム。

BLENano2_iBeacon
#include <nRF5x_BLE_API.h>
BLEDevice ble;

void setup() {
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);

  ble.init();
  ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
  ble.accumulateAdvertisingPayload(GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
  ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,(const uint8_t *)"LLLL", 4);
  ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
  ble.setAdvertisingInterval(20); 
  ble.setAdvertisingTimeout(0);
  ble.startAdvertising();
}

void loop() {
}

iPhoneで受信する際の注意

iPhoneで受信する際はCoreBluetoothを使い接続せずにScanResultだけ見ることで最短の20msで検知できる。
しかし、RSSIしか見れない。
CoreLocationだと1sに一度になってしまうがuuid, major, minorなどを見ることができる。

iPhone側の処理は気が向いたら書きます。

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