BLEセンサータグのWICED Senseを試してみる
日本ではマクニカが販売しているWICED Senseのタグが手に入ったので、BLEで受信してみます。
参考にしたのは以下です。
まずはiPhoneのアプリで試してみます。アプリはAppStoreから取得できます。
アプリをiPhoneにインストールして、タグの電池を入れてアプリを起動、タグの右上のボタンを押します。
一番上のDEMOはアプリのデモです。2番目のWICED Sense Kitが実際のタグになります。複数あればここに羅列されるはずです。 この状態でRSSIの値が分かります。-55なのでわりと近いですね。
タップするとコネクトします。
ジャイロ、方位磁石、加速度、バッテリー、気温、気圧、湿度が取得できていることが分かります。 タグを動かすとジャイロや加速度、方位が動きます。いろいろと試してみたのでバッテリー残量が2.23Vとすでに少ないですね。
これだけでも十分に楽しめるのですが、せっかくなので、Node.jsでセンサー情報を取得してみます。 Qiitaの記事のようにCylonを使って取ることもできますが、まずはBLEの情報がどうなっているかを見たいと思います。
nobleのexamplesにあるperipheral-explorer.jsを少し変更して試してみます。
noble/peripheral-explorer.js at master · sandeepmistry/noble · GitHub
UUIDを指定したくないので、4行目のパラメータ(UUID)を渡しているところをコメントアウトし、14行目のif文の判定をなくします。18行目のconsole.logで出力しているperipheralUuidをperipheral.uuidに変更します。
実行した結果は以下です。
peripheral with UUID xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx found Local Name = WICED Sense Kit Manufacturer Data = 0f000202f202203a Service Data = Service UUIDs = services and characteristics: 1801 (Generic Attribute) 1800 (Generic Access) 2a00 (Device Name) properties read value 57494345442053656e7365204b697400 | 'WICED Sense Kit' 2a01 (Appearance) properties read value 0002 | '' 739298b687b64984a5dcbdc18b068985 33ef91133b55413eb553fea1eaada459 properties read, notify value 0000000000000000000000000000000000000000 | '' 180a (Device Information) 2a29 (Manufacturer Name String) properties read value 42726f6164636f6d | 'Broadcom' 2a24 (Model Number String) properties read value 3030303100000000 | '0001' 2a23 (System ID) properties read value a5dcbdc18b068985 | '%\=A ' 180f (Battery Service) 2a19 (Battery Level) properties read value 26 | '&' a86abc2dd44c442e99f780059a873e36 1bd19c14b78a4e0faeb58e0352bac382 properties write, notify 279f9dab79be4663af1d24407347af13 properties write 6aa5711b037644f1bca18647b48bdb55 properties read value 203a0103 | ' :'
UUIDは伏せています。 割としっかり情報が入っている印象です。 サービスのpropertiesにread, notifyがあります。これがセンサー情報を取得するサービスと思われます。全てゼロなのが気になりますが……。 このままnobleで実装するのも良いですが、せっかくなのでCylonを使ってセンサー情報を取りたいと思います。そのほうが簡単ですし(笑)
詳細はQiitaの記事に書いてありますので、ここでは取得したデータだけを書いておきます。
I, [2015-02-04T09:24:50.358Z] INFO -- : Initializing connections. W, [2015-02-04T09:24:50.359Z] WARN -- : Specifying a single connection with the 'connection' key is deprecated. It will be removed in 1.0.0. I, [2015-02-04T09:24:50.409Z] INFO -- : Initializing devices. W, [2015-02-04T09:24:50.409Z] WARN -- : Specifying devices as an array is deprecated. It will be removed in 1.0.0. I, [2015-02-04T09:24:50.415Z] INFO -- : Starting connections. I, [2015-02-04T09:24:56.266Z] INFO -- : Starting devices. I, [2015-02-04T09:24:56.267Z] INFO -- : Working. Data: { accelerometer: { x: 3, y: 2, z: 87 }, gyroscope: { x: -237, y: 105, z: -1018 }, magnetometer: { x: 1536, y: 229, z: -746 } } Data: { accelerometer: { x: 3, y: 2, z: 86 }, gyroscope: { x: -579, y: 257, z: -1334 }, magnetometer: { x: 1526, y: 226, z: -747 } } Data: { accelerometer: { x: 3, y: 2, z: 87 }, gyroscope: { x: -342, y: 151, z: -766 }, magnetometer: { x: 1531, y: 229, z: -740 } } Data: { accelerometer: { x: 4, y: 1, z: 86 }, gyroscope: { x: -271, y: 129, z: -586 }, magnetometer: { x: 1530, y: 230, z: -758 } } Data: { accelerometer: { x: 3, y: 1, z: 86 }, gyroscope: { x: -437, y: 199, z: -1002 }, magnetometer: { x: 1529, y: 236, z: -750 } } Data: { accelerometer: { x: 4, y: 2, z: 86 }, gyroscope: { x: -432, y: 204, z: -1002 }, magnetometer: { x: 1533, y: 228, z: -749 } } Data: { accelerometer: { x: 3, y: 1, z: 86 }, gyroscope: { x: -243, y: 135, z: -569 }, magnetometer: { x: 1530, y: 234, z: -755 } } Data: { accelerometer: { x: 4, y: 1, z: 87 }, gyroscope: { x: -252, y: 132, z: -1361 }, magnetometer: { x: 1534, y: 225, z: -745 } } Data: { accelerometer: { x: 3, y: 1, z: 86 }, gyroscope: { x: -400, y: 179, z: -907 }, magnetometer: { x: 1532, y: 233, z: -759 } } Data: { humidity: 429, pressure: 10141, temperature: 300 } Data: { accelerometer: { x: 4, y: 1, z: 86 }, gyroscope: { x: -246, y: 129, z: -513 }, magnetometer: { x: 1517, y: 236, z: -739 } } Data: { accelerometer: { x: 4, y: 2, z: 86 }, gyroscope: { x: -458, y: 213, z: -1029 }, magnetometer: { x: 1538, y: 228, z: -753 } }
notifyでデータを取得しているのだと思われますが、とても早いです。この早さだと接続しっぱなしでは電池がすぐに無くなってしまいそうで、この点が課題になりそうです。気温、気圧、湿度は間に挟まってたまに来るので1秒に一回程度の通知なのではないかと思われます。
また、この商品は技適を通っているため、日本国内で利用しても問題ありません。
電池蓋に技適を取得しているマークが付いていました。マクニカに問い合わせたところ、すぐに返答があり、このマークが技適を取得していることを記すものと知りました。
次はこのデータをMQTTに投げるところを実装してみようと思います。MQTTはsangoを利用しても良いですし、自前で立てても良いと思います。とりあえずはローカルで実行するためにApache Apolloをインストールして起動してみようと考えています。