Coder Social home page Coder Social logo

beacon_scanner's Introduction

BLE Beacon scanner

はじめに

beacon_scanner.rb は,Apple の iBeacon 仕様の Beacon をスキャンして一覧表示するプログラムです. Ruby で書かれています.

ローカルの Redis サーバの指定したキーに Beacon の状況を書き込む機能があります. 他の Redis クライアントから Beacon の状況を非同期に読み出せます.

Beacon を見付けたら何かするといった,コールバックのようなのものありません. Redis 側で何とかしてください.

利用例

以下の通り実行すると:

bundle exec bin/beacon_scanner.rb --redis myroom

見付けた Beacon について,

2018-07-26 10:20:22 +0900/467fd32695d242f2bbbc5c8f4610b120/8/0/-55/-74 (lock:0)

のような表示が出ます.同時に,以下の key/value がローカルの Redis にセットされます.

myroom.major = major
myroom.minor = minor
myroom.power = power
myroom.rssi  = rssi
myroom.timestamp = 観測した timestamp
myroom.locked =  1/0 (デバッグ用 major が 8 のときに 1 になる)

Redis の pub/sub には,以下の key/value で publish されるので, イベントを待って処理したい場合には, これを使うといいでしょう.

myroom.updated = 観測したtimestamp

インストール

Linux の場合,関連パッケージをインストール:

sudo apt-get install bluez libbluetooth-dev
# 以下は,Redis を使うなら
sudo apt-get install redis-server

Ruby がインストールされている状態で:

git clone https://github.com/yoshinari-nomura/beacon_scanner.git
cd beacon_scanner
gem install bundler
bundle install --path vendor/bundle

Mac に Redis を入れたい人は,あまりいないと思いますが, 試したい人は,Homebrew や Docker でインストールするといいでしょう.

制限

以下の制限があります.修正したら,ぜひ PR ください.

  • どの Beacon UUID に反応するかは,コード中に直書きされているので, 適宜変更の必要があります.
  • Beacon の UUID 毎に Redis の名前空間を分けるなりするべきです.

参考

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.