LoginSignup
0
1

More than 3 years have passed since last update.

TWELITEの無線タグアプリのログをシェルスクリプトで解析する

Last updated at Posted at 2018-06-27

TWELITEの無線タグアプリ(App_Tag)のログをシェルスクリプトで解析してみます。

データを読む

まずデータを読まないことにははじまりません。
基本的にはsttyで通信速度を設定してcatや他のコマンドへのリダイレクトで読めばいいのですが、macOSだけsttyを実行するタイミングが絶妙なので注意です。

macOSの場合

ターミナルを起動して、

$ cat /dev/cu.usbserial-MW2GON6K 

したあと、もうひとつターミナルを起動して、

$ stty -f /dev/cu.usbserial-MW2GON6K 115200

とやると、先に起動したターミナルでデータの読込がはじまります。

Linux (RaspberryPi + MONOSTICK)

(comming soon...)

Linux (RAspberryPi + TWELITE DIP UART接続)

(comming soon...)

生データの貯蔵

App_Tag自体は時刻を出力しない(TWELITE自体にRTCがついてるわけじゃないので当然)のですが、

$ cat /dev/serial0 | while read line; do printf '%s %s' `date +%s` ${line}; done > raw_data/twelite.log

みたいな感じで1メッセージごとにタイムスタンプ(UNIX秒)を頭にくっつけてデータを貯めてあります。

$ cat raw_data/twelite.log | tail -n 20
1528815094 ::ts=3023155
1528815095 ::ts=3023156
1528815096 ::rc=80000000:lq=150:ct=79B9:ed=8202093D:id=2:ba=3100:a1=0890:a2=0504:tm=6702:hu=1225:at=0998
1528815096 ::ts=3023157
1528815097 ::ts=3023158
1528815098 ::ts=3023159
1528815099 ::ts=3023160
1528815100 ::ts=3023161
1528815101 ::rc=80000000:lq=159:ct=79BA:ed=8202093D:id=2:ba=3100:a1=0885:a2=0499:tm=6676:hu=1239:at=0998
1528815101 ::ts=3023162
1528815102 ::ts=3023163
1528815103 ::ts=3023164
1528815104 ::ts=3023165
1528815105 ::ts=3023166
1528815106 ::rc=80000000:lq=165:ct=79BB:ed=8202093D:id=2:ba=3100:a1=0885:a2=0501:tm=6645:hu=1224:at=0998
1528815106 ::ts=3023167
1528815107 ::ts=3023168
1528815108 ::ts=3023169
1528815109 ::ts=3023170
1528815110 ::ts=3023171

この無線タグにはBME280が接続されているので、温度、湿度、気圧が取得できています。

値の意味はそれぞれ、

  • ba=バッテリー電圧(mV)
  • tm=温度(℃ * 100)
  • hu=湿度(% * 100)
  • at=気圧(hpa)

となっています。

タイムスタンプと温度だけ抽出する

sedでできました。

タイムスタンプと温度だけ抽出する
$ cat raw_data/twelite.log | grep '::rc=' | sed 's/^\([0-9][0-9]*\).*:tm=\([0-9][0-9]*\).*$/\1 \2/' | tail
1528815060 6895
1528815065 6869
1528815070 6832
1528815075 6804
1528815080 6769
1528815085 6745
1528815090 6725
1528815096 6702
1528815101 6676
1528815106 6645

続く・・・

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