WICED Sense


開発キットなので、計測した結果を見せてくれるだけ。例えば、気圧が下がったらアラートを出すとか、計測結果を記録してグラフ化するといった機能はない。あくまでも開発キットなので、後からアプリを開発する環境は用意されている。


スマホ用アプリのソースコードも公開されている

Beaconやワイヤレス充電に対応し、セキュリティ保護されたワイヤレス・ダウンロードでファームウエアを更新することも可能だ。Bluetooth Smartの通信でiPhoneとセンサータグをペアリングする設定も、数回のタップ操作のみで完了し、センサーを早速読み取ることができる。






edisonから利用
$ npm install -g cylon cylon-ble cylon-wiced-sense

[root@edison1_pepper:~/workspace_outan]$ npm install -g cylon cylon-ble cylon-wiced-sense
npm ERR! fetch failed https://registry.npmjs.org/cylon/-/cylon-1.3.0.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 400
npm WARN optional dep failed, continuing xpc-connection@0.1.4
npm WARN optional dep failed, continuing xpc-connection@0.1.4
npm WARN engine usb@1.2.0: wanted: {"node":">=0.12.x"} (current: {"node":"0.10.44","npm":"2.15.0"})
npm WARN engine usb@1.2.0: wanted: {"node":">=0.12.x"} (current: {"node":"0.10.44","npm":"2.15.0"})

> usb@1.2.0 install /home/root/.ndenv/versions/v0.10.44/lib/node_modules/cylon-ble/node_modules/noble/node_modules/bluetooth-hci-socket/node_modules/usb
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download: https://github.com/tessel/node-usb/releases/download/1.2.0/usb_bindings-v1.2.0-node-v11-linux-ia32.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for usb@1.2.0 and node@0.10.44 (node-v11 ABI) (falling back to source compile with node-gyp)
make: Entering directory '/home/root/.ndenv/versions/v0.10.44/lib/node_modules/cylon-ble/node_modules/noble/node_modules/bluetooth-hci-socket/node_modules/usb/build'
CC(target) Release/obj.target/libusb/libusb/libusb/core.o
CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
CC(target) Release/obj.target/libusb/libusb/libusb/io.o
CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o
CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o
../libusb/libusb/os/linux_udev.c:40:21: fatal error: libudev.h: No such file or directory
#include
^
compilation terminated.
libusb.target.mk:126: recipe for target 'Release/obj.target/libusb/libusb/libusb/os/linux_udev.o' failed
make: *** [Release/obj.target/libusb/libusb/libusb/os/linux_udev.o] Error 1
make: Leaving directory '/home/root/.ndenv/versions/v0.10.44/lib/node_modules/cylon-ble/node_modules/noble/node_modules/bluetooth-hci-socket/node_modules/usb/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/root/.ndenv/versions/v0.10.44/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Linux 3.10.17-poky-edison+

いろいろエラーが出たけど、ちんとインストールできたようです。
[root@edison1_pepper:~/.ndenv/versions/v0.10.44/lib/node_modules]$ lsal
47041 drwxr-xr-x 3 nobody root 4.0K Sep 9 15:04 cylon/
47042 drwxr-xr-x 7 nobody root 4.0K Sep 9 15:04 cylon-ble/
47040 drwxr-xr-x 6 nobody root 4.0K Sep 9 15:04 cylon-wiced-sense/
21743 drwxr-xr-x 4 nobody root 4.0K Sep 6 14:40 express/
36382 drwxr-xr-x 9 root root 4.0K May 1 19:13 npm/

var Cylon = require('cylon');

Cylon.robot({
connections: {
bluetooth: { adaptor: 'ble', uuid: '207377654321' }
},

devices: {
wiced: { driver: 'wiced-sense' }
},

work: function(my) {
my.wiced.getData(function(err, data) {
if (!!err) {
console.log("Error: ", err);
return;
}

console.log("Data: ", data);
});
}
}).start();

⇒上記のサンプルを実行しても下記のようにうまく接続できていないようです。
[root@edison1_pepper:~/workspace_outan/nodejs_edison/cylon]$ node get_info_wiced_sens.js
2016-09-09T07:19:42.512Z : [Robot 1] - Starting connections.
2016-09-09T07:19:42.541Z : [Robot 1] - Starting connection 'bluetooth'.


[root@edison1_pepper:~/.ndenv/versions/v0.10.44/lib/node_modules]$ rfkill list
0: phy0: wlan
Soft blocked: no
Hard blocked: no
1: brcmfmac-wifi: wlan
Soft blocked: no
Hard blocked: no
2: bcm43xx Bluetooth: bluetooth
Soft blocked: yes
Hard blocked: no
[root@edison1_pepper:~/.ndenv/versions/v0.10.44/lib/node_modules]$ rfkill unblock bluetooth
[root@edison1_pepper:~/.ndenv/versions/v0.10.44/lib/node_modules]$ rfkill list
0: phy0: wlan
Soft blocked: no
Hard blocked: no
1: brcmfmac-wifi: wlan
Soft blocked: no
Hard blocked: no
2: bcm43xx Bluetooth: bluetooth
Soft blocked: no
Hard blocked: no
3: hci0: bluetooth
Soft blocked: no
Hard blocked: no

bluetoothはまだ無効の状態だ。だから接続できないんだ。

が、bluetoothを有効にしてもまだ接続できないようです。
[root@edison1_pepper:~/workspace_outan/nodejs_edison/cylon]$ node get_info_wiced_sens.js
2016-09-09T07:19:42.512Z : [Robot 1] - Starting connections.
2016-09-09T07:19:42.541Z : [Robot 1] - Starting connection 'bluetooth'.

[root@edison1_pepper:~/.ndenv/versions/v0.10.44/lib/node_modules/cylon-ble/bin]$ lsal
47067 -rwxr-xr-x 1 nobody root 4.5K Nov 18 2015 bleinfo.js*
47073 -rwxr-xr-x 1 nobody root 507 Nov 18 2015 blescan.js*
^C[root@edison1_pepper:~/.ndenv/versions/v0.10.44/lib/node_modules/cylon-ble/bin]$ cat blescan.js
#!/usr/bin/env node

var noble = require('noble');

noble.on('stateChange', function(state) {
if (state === 'poweredOn') {
console.log("Starting scan.");
noble.startScanning();
} else {
console.log("Stopping scan.");
noble.stopScanning();
}
});

noble.on('discover', function(peripheral) {
console.log("Peripheral discovered!")
console.log(" Name: " + peripheral.advertisement.localName)
console.log(" UUID: " + peripheral.id);
console.log(" rssi: " + peripheral.rssi);
});

[root@edison1_pepper:~/.ndenv/versions/v0.10.44/lib/node_modules/cylon-ble/bin]$ node blescan.js
Starting scan.
Peripheral discovered!
Name: WICED Sense2 Kit
UUID: 00101801919b
rssi: -54
⇒やはWICED Senseもの毎にUUIDが違うらしい。
cylonコードのUUIDを変更してみて、実行


[root@edison1_pepper:~/workspace_outan/nodejs_edison/cylon]$ node get_info_wiced_sense2.js
2016-09-09T08:44:53.014Z : [Robot 1] - Starting connections.
2016-09-09T08:44:53.043Z : [Robot 1] - Starting connection 'bluetooth'.
2016-09-09T08:45:10.353Z : [Robot 1] - Starting devices.
2016-09-09T08:45:10.354Z : [Robot 1] - Starting device 'wiced'.
2016-09-09T08:45:10.355Z : [Robot 1] - Working.
Data: { accelerometer: { x: 102, y: 215, z: 261 },
gyroscope: { x: -5180, y: -12320, z: 26126 },
magnetometer: { x: 1910, y: 178, z: -1737 } }
Data: { accelerometer: { x: -59, y: -59, z: 326 },
gyroscope: { x: 17430, y: 30046, z: -10500 },
magnetometer: { x: 1976, y: 133, z: -1719 } }
Data: { accelerometer: { x: -72, y: -309, z: 285 },


MACからWICED Senseデータ取得
outan@outan ~/Dropbox/web/node.jstest
%npm install -g cylon cylon-ble cylon-wiced-sense ruby:[2.1.3]
> xpc-connection@0.1.4 install /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-ble/node_modules/noble/node_modules/xpc-connection
> node-gyp rebuild

CXX(target) Release/obj.target/binding/src/XpcConnection.o
In file included from ../src/XpcConnection.cpp:7:
In file included from ../src/XpcConnection.h:10:
../node_modules/nan/nan.h:455:32: error: no member named 'SetCounterFunction' in 'v8::Isolate'
v8::Isolate::GetCurrent()->SetCounterFunction(cb);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:460:32: error: no member named 'SetCreateHistogramFunction' in
'v8::Isolate'
v8::Isolate::GetCurrent()->SetCreateHistogramFunction(cb);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:465:32: error: no member named 'SetAddHistogramSampleFunction' in
'v8::Isolate'
v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:476:39: error: no member named 'IdleNotification' in 'v8::Isolate'
return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:481:32: error: no member named 'LowMemoryNotification' in 'v8::Isolate'
v8::Isolate::GetCurrent()->LowMemoryNotification();
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:485:32: error: no member named 'ContextDisposedNotification' in
'v8::Isolate'
v8::Isolate::GetCurrent()->ContextDisposedNotification();
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
6 errors generated.
make: *** [Release/obj.target/binding/src/XpcConnection.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/outan/.nvm/v0.11.13/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1046:12)
gyp ERR! System Darwin 15.5.0
gyp ERR! command "node" "/Users/outan/.nvm/v0.11.13/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-ble/node_modules/noble/node_modules/xpc-connection
gyp ERR! node -v v0.11.13
gyp ERR! node-gyp -v v0.13.0
gyp ERR! not ok
npm http 200 https://registry.npmjs.org/ms/-/ms-0.7.1.tgz

> xpc-connection@0.1.4 install /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-wiced-sense/node_modules/cylon-ble/node_modules/noble/node_modules/xpc-connection
> node-gyp rebuild

/Users/outan/.nvm/v0.11.13/bin/cylon-ble-info -> /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-ble/bin/bleinfo.js
/Users/outan/.nvm/v0.11.13/bin/cylon-ble-scan -> /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-ble/bin/blescan.js
CXX(target) Release/obj.target/binding/src/XpcConnection.o
In file included from ../src/XpcConnection.cpp:7:
In file included from ../src/XpcConnection.h:10:
../node_modules/nan/nan.h:455:32: error: no member named 'SetCounterFunction' in 'v8::Isolate'
v8::Isolate::GetCurrent()->SetCounterFunction(cb);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:460:32: error: no member named 'SetCreateHistogramFunction' in
'v8::Isolate'
v8::Isolate::GetCurrent()->SetCreateHistogramFunction(cb);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:465:32: error: no member named 'SetAddHistogramSampleFunction' in
'v8::Isolate'
v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:476:39: error: no member named 'IdleNotification' in 'v8::Isolate'
return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:481:32: error: no member named 'LowMemoryNotification' in 'v8::Isolate'
v8::Isolate::GetCurrent()->LowMemoryNotification();
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
../node_modules/nan/nan.h:485:32: error: no member named 'ContextDisposedNotification' in
'v8::Isolate'
v8::Isolate::GetCurrent()->ContextDisposedNotification();
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
6 errors generated.
make: *** [Release/obj.target/binding/src/XpcConnection.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/outan/.nvm/v0.11.13/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1046:12)
gyp ERR! System Darwin 15.5.0
gyp ERR! command "node" "/Users/outan/.nvm/v0.11.13/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-wiced-sense/node_modules/cylon-ble/node_modules/noble/node_modules/xpc-connection
gyp ERR! node -v v0.11.13
gyp ERR! node-gyp -v v0.13.0
gyp ERR! not ok
npm WARN optional dep failed, continuing xpc-connection@0.1.4
npm WARN optional dep failed, continuing xpc-connection@0.1.4
cylon@1.3.0 /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon

cylon-ble@0.10.1 /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-ble
├── async@1.5.2
└── noble@1.6.0 (bplist-parser@0.0.6, debug@2.2.0)

cylon-wiced-sense@0.7.0 /Users/outan/.nvm/v0.11.13/lib/node_modules/cylon-wiced-sense
├── cylon@1.2.0
└── cylon-ble@0.8.0 (async@1.5.2, noble@1.6.0)


いろいろエラーが出た。 nodeのバージョンをv0.10.31に下げる。
outan@outan ~/Dropbox/web/node.jstest [develop]¹
%npm install -g cylon cylon-ble cylon-wiced-sense ruby:[2.1.3]
npm WARN optional dep failed, continuing bluetooth-hci-socket@0.4.4
npm WARN optional dep failed, continuing bluetooth-hci-socket@0.4.4
-
> xpc-connection@0.1.4 install /Users/outan/.nvm/v0.10.31/lib/node_modules/cylon-ble/node_modules/noble/node_modules/xpc-connection
> node-gyp rebuild

CXX(target) Release/obj.target/binding/src/XpcConnection.o
SOLINK_MODULE(target) Release/binding.node
SOLINK_MODULE(target) Release/binding.node: Finished

> xpc-connection@0.1.4 install /Users/outan/.nvm/v0.10.31/lib/node_modules/cylon-wiced-sense/node_modules/cylon-ble/node_modules/noble/node_modules/xpc-connection
> node-gyp rebuild

/Users/outan/.nvm/v0.10.31/bin/cylon-ble-scan -> /Users/outan/.nvm/v0.10.31/lib/node_modules/cylon-ble/bin/blescan.js
/Users/outan/.nvm/v0.10.31/bin/cylon-ble-info -> /Users/outan/.nvm/v0.10.31/lib/node_modules/cylon-ble/bin/bleinfo.js
CXX(target) Release/obj.target/binding/src/XpcConnection.o
SOLINK_MODULE(target) Release/binding.node
SOLINK_MODULE(target) Release/binding.node: Finished
cylon@1.3.0 /Users/outan/.nvm/v0.10.31/lib/node_modules/cylon

cylon-ble@0.10.1 /Users/outan/.nvm/v0.10.31/lib/node_modules/cylon-ble
├── async@1.5.2
└── noble@1.6.0 (bplist-parser@0.0.6, debug@2.2.0, xpc-connection@0.1.4)

cylon-wiced-sense@0.7.0 /Users/outan/.nvm/v0.10.31/lib/node_modules/cylon-wiced-sense
├── cylon@1.2.0
└── cylon-ble@0.8.0 (async@1.5.2, noble@1.6.0)


outan@outan ~/.nvm/v0.10.31/lib/node_modules/cylon-ble/bin
%node blescan.js ruby:[2.1.3]
Starting scan.
Peripheral discovered!
Name: undefined
UUID: 577edbe9d265435f8047a714f044ae2c
rssi: -54
⇒iPhoneの"beacon manager"からの信号だと思うけど、そうしてもuuidは一致していないようで、原因不明です。


WICED Sense2をオンにしたら、検知できた。
%node blescan.js ruby:[2.1.3]
Starting scan.
Peripheral discovered!
Name: undefined
UUID: 577edbe9d265435f8047a714f044ae2c
rssi: -54
Peripheral discovered!
Name: WICED Sense2 Kit
UUID: e99ba800d3be400380b722220d1ec07c
rssi: -66

outan@outan ~/.nvm/v0.10.31/lib/node_modules/cylon-wiced-sense/examples/wiced-sense
%lsal
total 8
133585541 -rw-r--r-- 1 outan staff - 936B 9 10 12:47:53 2016 wiced-sense.js
デフォルトのサンプル中のUUIDをWICED Sense2のUUIDに変更(再起動したら、UUIDが勝手に変更されるようです。昨日のUUIDとは全然別物になったようです。)






MQTTで送ってみる
mqttcli:Go言語で書かれているCLI ベースのツール ライブラリは Paho を使用されております。

https://github.com/shirou/mqttcliから辿れるdrone.ioに各種アーキテクチャ用のバイナリが置いてありますので、ダウンロードします。

~/binに配備します。

コマンド(例)
mv ~/Downloads/mqttcli ~/bin/
chmod +x ~/bin/mqttcli

%mqttcli -v ruby:[2.1.3]
mqttcli version 0.0.2-18-g71d5437

そして、 ~/.mqttcli.cfg に MQTT as a Service:sango で得た情報を記載しておきます。

{
"host": "sango.mqtt.example.jp",
"port": 1883,
"username": "shirou@github",
"password": "oAKL5jAZ1FUf5A82"
}

sangoはgithubのアカウントからしかアクセスできないようです。
しかもログインアカウントは変更できる場所はなさそうです。
上記のmqttcli.cfgファイルに設定するパスワードはsangoのログインパスワードではないようです。

%cat ~/.mqttcli.cfg ruby:[2.1.3]
{
"host": "lite.mqtt.shiguredo.jp",
"port": 1883,
"username": "outan@github",
"password": "oAKL5jAZ1FUf5A82"
}

%mqttcli sub -t "outan@github/#" -d ruby:[2.1.3]
INFO[0000] Broker URI: tcp://lite.mqtt.shiguredo.jp:1883
INFO[0000] Topic: outan@github/#
INFO[0000] connecting...
INFO[0000] client connected


outan@outan ~/.nvm/v0.10.31/lib/node_modules/cylon-wiced-sense/examples/wiced-sense
%node wiced-sense.js | mqttcli pub -t "outan@github/wiced" -s

%mqttcli sub -t "outan@github/#" ruby:[2.1.3]
2016-09-10T06:16:17.447Z : [Robot 1] - Starting devices.
2016-09-10T06:16:17.448Z : [Robot 1] - Starting device 'battery'.
2016-09-10T06:16:17.448Z : [Robot 1] - Starting device 'deviceInfo'.
2016-09-10T06:16:17.448Z : [Robot 1] - Starting device 'generic'.
2016-09-10T06:16:17.448Z : [Robot 1] - Starting device 'wiced'.
2016-09-10T06:16:17.449Z : [Robot 1] - Working.
error: Service not found
error: Service not found
data: Broadcom
data: { accelerometer: { x: 4, y: 26, z: 61 },
gyroscope: { x: 3850, y: -13020, z: -7280 },
magnetometer: { x: 1390, y: -22, z: 226 } }
data: { accelerometer: { x: 22, y: 22, z: 38 },
gyroscope: { x: -1470, y: -10780, z: -6580 },
magnetometer: { x: 1396, y: -23, z: 246 } }



特定の条件を満たす時のみデータをMTQQブロかー送るするにはどうすればいいか?
cylonの詳細を調査

センサーの場合、何を目的にするかにもよりますが、
ジャイロなどの動き系であれば、動いたことを検知してデータを送るのが良さそうです。
気温等のデータの場合は一定間隔で送る必要がありますが、例えば5分単位のデータがあれば十分なのではないかと思います。 ジャイロ・加速度センサーはしばらくいろいろと動かしてみて検証し、しきい値を決めて送る送らないを判定するロジックを入れようと思います。