More Related Content Similar to 続・Webエンジニアのためのスマートホームハック ~ Node.js で IoT プロトコルハック ~ (20) More from Futomi Hatano (12) 続・Webエンジニアのためのスマートホームハック ~ Node.js で IoT プロトコルハック ~2. 日経SYSTEMSコラム
2
• マイコンボードを使って大気圧と気温を取得
• Webブラウザーから制御 MIDIでサーボを動かす
• Node.jsで家電を操作 赤外線を利用しよう
• ECHONET Liteで家電をコントロール
• スマホから機器を制御「デバイスコネクトWebAPI」
• 電池交換が不要に 無線技術「EnOcean」に注目
• JavaScriptで車載情報を取得「OBD-II」を使う
• Node.jsで電力情報を取得スマートメータを活用しよう
• ネットワークカメラに注目 Webブラウザーで操作可能に
• WebブラウザーからBLEでセンサーにアクセス
IoTで火が付くITエンジニア魂:2016年4月号~2017年3月号
7. もくじ
• 前回のあらまし
• BLE編
• iBeacon/Eddystone
• Linking/ALPS/TI SensorTag
• サブギガ無線方式編
• ALPS
• Z-Wave
• カメラ編
• ネットワークカメラ ONVIF
• 顔認識カメラ OMRON
• 自動車編
• OBD-II
7
11. node-beacon-scanner
11
https://github.com/futomi/node-beacon-scanner
const BeaconScanner = require('node-beacon-scanner');
const scanner = new BeaconScanner();
// Set an Event handler for becons
scanner.onadvertisement = (ad) => {
console.log(JSON.stringify(ad, null, ' '));
};
// Start scanning
scanner.startScan().then(() => {
console.log('Started to scan.');
}).catch((error) => {
console.error(error);
});
{
"id": "c6debed8f549",
"address": "c6:de:be:d8:f5:49",
"localName": null,
"txPowerLevel": null,
"rssi": -59,
"beaconType": "eddystoneUrl”,
"eddystoneUrl": {
"txPower": -35,
"url": http://go.esti.be/
}
}
EddyStone URLの例
15. node-linking
15
https://github.com/futomi/node-linking
const Linking = require('node-linking’);
const linking = new Linking();
// Set a callback function called when a packet is received
linking.onadvertisement = (ad) => {
console.log(JSON.stringify(ad, null, ' '));
};
// Start to scan advertising packets from Linking devices
linking.startScan({ nameFilter: 'Tukeru' });
{
...
"localName": "Tukeru_th0164069",
"txPowerLevel": -96,
"rssi": -67,
"distance": 0.03548133892335755,
"version": 0,
"vendorId": 0,
"individualNumber": 164069,
"beaconServiceId": 1,
"beaconServiceData": {
"name": "Temperature (°C)",
"temperature": 25.875
}
}
17. ALPS センサネットワークモジュール
• アルプス電気が販売するBLEセンサータグ
• 温度/湿度/照度/気圧/UV/加速度/地磁気
• かなり細かい設定が可能
• リクエストとレスポンスが別のCharacteristic
17
http://www.alps.com/j/iotsmart-network/index.html
Service
Characteristic 3
Characteristic 2
Characteristic 1
Write
コマンド制御
Notification
センサ情報
Notification
Read応答など
18. node-alps
18
https://github.com/futomi/node-alps
const Alps = require('node-alps’);
const alps = new Alps();
let device = null;
alps.init().then(() => {
return alps.discover();
}).then((device_list) => {
device = device_list[0];
return device.connect();
}).then(() => {
return device.startMonitor({mode : 0});
}).then(() => {
device.onnotify = (data) => {
console.log(JSON.stringify(data, null, ' '));
};
});
{
"pressure": 996.4881361104754,
"humidity": 51.65625,
"temperature": 24.04,
"uv": 0.02577319587628866,
"ambient": 129.3103448275862,
"ambientLed": 222.94887039239,
"ambientFluorescent": 293.8871473354232,
"timeStamp": {...},
"dataIndex": 29
}
19. TI SimpleLink SensorTag CC2650STK
• Texas Instrumentsが販売するBLEセンサータグ
• 温度/湿度/照度/気圧/加速度/回転速度/磁気/LED/ブザー/ボタン/バッテリー
• センサータグの先駆けで、開発者の中では世界で一番有名?
• BLE接続後、Readでワンショット取得、Subscribeで通知登録、Notificationで通知
受信で、非常に分かりやすいプロファイル設計
19
20. html5-CC2650SensorTag.js
20
https://github.com/futomi/html5-CC2650SensorTag.js
const tag = new CC2650SensorTag();
tag.discover().then(() => {
return tag.connect();
}).then(() => {
let c = {temperature: {enable_ir_temperature_sensor: true}};
return tag.writeConfigurations(c);
}).then(() => {
tag.ontemperaturenotify = (data) => {
console.log(data['ambience'] + '°C’);
};
return tag.startTemperatureNotifications();
}).catch((error) => {
console.log(error.message);
});
nodeモジュールではなく Web Bluetoothを使ったJavaScriptライブラリ
23. ALPS 環境センサモジュール
• アルプス電気のセンサモジュール
• サブギガ帯 (920MHz)/プロトコルは独自
• ソーラーパネル式と電池式/送信出力1mWと10mWのモデル
• 温度/湿度/照度/気圧に対応
• USBゲートウェイは単なるシリアル通信 (COMポート)
23
http://www.alps.com/j/iotsmart-environment/index.html
24. node-alps-env
24
https://github.com/futomi/node-alps-env
const AlpsEnv = require('node-alps-env’);
AlpsEnv.connect().then(() => {
// センサー情報受信のイベントハンドラをセット
AlpsEnv.onmessage = (data) => {
// 受信データを出力
console.log(JSON.stringify(data, null, ' ‘));
};
}).catch((error) => {
console.error(error);
});
{
"no": 2,
"txid": 14746066,
"temp": 28.2,
"humi": 60.9,
"pres": 1000.29,
"light": 484,
"door": 1,
"vbat": 2.9,
"rssi": -79
}
26. Z-Wave
• 欧米/韓国ではスマートホームでメジャーな無線規格
• サブギガ帯 (日本では920MHz)/メッシュ対応
• 機器種別ごとのプロトコル (Command Class) まで規定 (一般公開)
• 低消費電力 - センサーデバイスなら単四電池2個で3年程度
• 技術評価と開発
• Dev.Kit購入およびSigma Designs社とNDA/Dev.Kitライセンス契約締結
• SDKや非公開情報の公開
• 日本国内ではユニ電子(株)が取り扱い (http://www.uni-elec.co.jp/)
• サービス提供に必要な手続き
• Z-Wave Alliance加盟
• 機器の認証
26
http://www.z-wave.com/
28. 技適取得済みデバイス例
28
VISION/ZM2201JP-5
4 in 1 Door Sensor
VISION/ZD2112JP-5
Door Sensor (Thin Magnet Type)
Goodway/WD6052
Z-Wave USB Dongle
Aeotec/ZW100
Multi sensor 6
VISION/ZP3111JP-5
4in1 PIR Sensor
Goodway/TD13320
Smart Meter Switch
29. Command Class
29
Command Classの例
• Anti-theft
• Binary Switch
• Color Switch
• Door Lock
• Energy Production
• Geographic Location
• HRV Control
• Humidity Control Mode
• Meter
• Multilevel Sensor
• Thermostat Fan Mode
• Window Covering
Command Class Structure
Fundamental Commands
• SET
• GET
• REPORT
32. ONVIF
32
• Open Network Video Interface Forum
• ネットワークカメラのプロトコルの標準
• デバイス発見、ビデオストリーミング、PTZ制
御など
• NVT発見にWS-Discovery
• UDPポート3702によるマルチキャスト
• メッセージはSOAPベース
• HTTPプロトコルでSOAPをPOST
• 今どきSOAP?
• でもONVIF策定当時はSOAPがナウい時代
http://www.onvif.org/
34. node-onvif
34
https://github.com/futomi/node-onvif
const onvif = require('node-onvif’);
const fs = require('fs’);
let device = new onvif.OnvifDevice({
xaddr: 'http://192.168.10.14:10080/onvif/device_service’,
user : 'admin’, pass : '123456’
});
device.init().then(() => {
return device.fetchSnapshot();
}).then((res) => {
fs.writeFileSync('snapshot.jpg', res.body, {encoding: 'binary’});
}).catch((error) => {
console.error(error);
});
38. node-omron-hvc-p2
38
https://github.com/futomi/node-omron-hvc-p2
const HvcP2 = require('node-omron-hvc-p2’);
const hvcp2 = new HvcP2();
hvcp2.connect().then(() => {
return hvcp2.detect({
face : 1, // Enable face detection
age : 1, // Enable age estimation
gender : 1 // Enable gender Estimation
});
}).then((res) => {
console.log(JSON.stringify(res, null, ' ‘));
}).catch((error) => {
console.error(error);
});
{"face": [{
"face": {
"x": 930,
"y": 497,
"size": 390,
"confidence": 579
},
"age": {
"age": 41,
"confidence": 500
},
"gender": {
"gender": 1,
"confidence": 1000
}
}]}
43. 昔Chrome Appsでアプリを作ってみた
• Chrome Platform APIs
• bluetooth API
• bluetoothSocket API
• serial API
• ODB-II ECU Simulator
• ISO 15765-4 (CAN)
• ODB-II Adapter
• IC: STN1100 (ELM327互換)
• Interface: USB Serial
• baud rate: 115,200 bps
48. Open Hardware Pavilion (仮)
• APPS JAPAN 2018@幕張メッセ 2018年6月13日~15日
• 新たに Open Hardware Pavilion (仮) を企画中
• オープンでアプリ開発者フレンドリーなハードウェアを一堂に集結
• ご興味があるメーカーさん、ぜひお声がけください
• ご意見、ご要望、お聞かせください