23
27

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

WxBeacon2をRaspberry Pi 3につないで部屋の状態を可視化

Last updated at Posted at 2018-01-30

#背景
ウェザーニューズのサービスの一つとしてウェザーレポートという機能があり、お天気を投稿するとポイントが貰え、2000pt貯めるとWxBeacon 2というデバイスがもらえます。気温、湿度、騒音などなどを測定してスマホで表示出来る優れもの

中身はオムロンの2JCIE-BL01です。

今回、3年がかり(サボってたのもあるけど、毎日レポート送れば半年ぐらいで貯まるかな?)で2000pt貯めてもらえたのでRaspberry Piに繋いでデータベースに蓄積してグラフを表示するとかいろいろ遊んでみます。

#Raspberry Pi 3にWxBeacon 2を接続
BLE使って通信しているので、Raspberry Pi 3ならば内蔵のBluetoothで接続できます。オムロンがサンプルのプログラム公開しているのでこちらを利用します。

##python-bluezの導入

pythonからBluetoothを使えるようにする

$ sudo apt-get install python-bluez

##CSV出力してみる

プログラムの実行

$ sudo ./envsensor_observer.py

logフォルダにcsvが出力・・・されない

Environment Sensor (2JCIE-BL01) must be configured as a beacon broadcaster (IM/EP).

どうやらセンサの設定をビーコンモードに切り替える必要があるようです.
Omron 環境センサ(2jcie-bl01)の設定をBroadcasterに変更してアドバタイズパケットから情報を取得してみるテストまで
こちらを参考に,スマホから設定をGeneral Broadcaster 2にします.

再度試したところうまく値が出力されました.

#データをinfluxDBに書き溜める
##fluentd forwarderのインストール

$ sudo pip install fluent-logger

##influxDBのインストール

公式ドキュメントを参考にインストールします

curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/os-release
test $VERSION_ID = "7" && echo "deb https://repos.influxdata.com/debian wheezy stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update && sudo apt-get install influxdb
sudo service influxdb start

##conf.pyの書き換え

設定ファイルを適宜書き換えます.FalseになってるところをTrueに,DBのIPアドレスやDBの名前を設定します.

##Grafanaの導入

今回のメイン?influxDBのデータを読み込んでカッコイイグラフをブラウザで表示出来ます.

sudo apt-get install apt-transport-https curl
curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
echo "deb https://dl.bintray.com/fg2it/deb jessie main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana
sudo service grafana-server start

localhost:3000にアクセスしてログイン画面が出ることを確認します(admin/admin)でログイン出来ます
influxDB,Grafanaと収集プログラムはsystemdで自動起動するようにしとくと便利です.

#データ収集

収集プログラムを起動します.

$ sudo ./envsensor_observer.py

5分毎にinfluxDBにデータが蓄積されていくはずです.

#Grafanaでグラフィカル表示

Grafanaにログインします.New Dashboardから新しいダッシュボードを作成します。

グラフを選びます。

作成されたグラフを選んでEdit.MetricsのSQLを以下のようにします。humidityの部分は測定値の表示したい項目を選びます。
その他グラフタイトルや単位(Unit)などを適宜設定します。

設定進めていくとこんな感じでイケてるグラフが出来上がります。

23
27
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
23
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?