Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
IoT made easy @ SITCON x HK
Search
Jeremy Yen
October 22, 2016
Technology
0
100
IoT made easy @ SITCON x HK
IoT made easy: RPi, Sensortag, Websocket with Node.js
Jeremy Yen
October 22, 2016
Tweet
Share
More Decks by Jeremy Yen
See All by Jeremy Yen
dEXonation
jeremy5189
0
110
A day of full stack developer @ NFU
jeremy5189
0
210
Club Mate and Hacker - 34C3 @ SITCON
jeremy5189
2
680
SITCON 2017 論壇系統開發分享 @ SITCON 2017 Summer
jeremy5189
0
220
poManeuver: Poland into space
jeremy5189
0
420
How we hacked a forum
jeremy5189
0
440
Bdecisive - Booking.com Taipei Hack 2nd Prize
jeremy5189
0
550
Social Intelligence Smart-device project
jeremy5189
0
62
遺失的學校 - SITCON 2014 Lightning Talk
jeremy5189
0
560
Other Decks in Technology
See All in Technology
型情報を用いたLintでコード品質を向上させる
sansantech
PRO
2
150
事業貢献を考えるための技術改善の目標設計と改善実績 / Targeted design of technical improvements to consider business contribution and improvement performance
oomatomo
0
170
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
120
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
210
pg_bigmをRustで実装する(第50回PostgreSQLアンカンファレンス@オンライン 発表資料)
shinyakato_
0
120
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
510
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
140
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
190
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
150
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
410
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
120
.NET 9 のパフォーマンス改善
nenonaninu
0
1.6k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.3k
Docker and Python
trallard
42
3.2k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Automating Front-end Workflow
addyosmani
1366
200k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Fireside Chat
paigeccino
34
3.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
Designing for Performance
lara
604
68k
Transcript
*P5NBEFFBTZVTJOH 3BTQCFSSZ1JBOE4FOTPSUBH +FSFNZ!4*5$0/Y),
QBUSJDLTUXTMJEFT "CPVU+FSFNZ ˙ #BDLFOE%FWFMPQFS ˙ 4*5$0/UX%FQVUZ%JSFDUPSPG"HFOEB$PNNJUUFF ˙ ,1.(5BJXBO*5"EWJTPSZ*OUFSO ˙ 5BJXBO5FDI
/5645 ˙ IUUQQBUSJDLTUX 2
QBUSJDLTUXTMJEFT 0VUMJOF ˙ $PNNVOJDBUJPOXJUI#-&EFWJDF ˙ 8SBQQJOHVQXJUI/PEFKT ˙ 'FFEJUUP8FCTPDLFU ˙ $POOFDUJOHUP.VMUJQMF%FWJDF
˙ 5SPVCMFTIPPUJOH ˙ "EEJUJPOBM*OTUBMMJOHPO.BD049 ˙ "EEJUJPOBM3FBEJOH23$PEFXJUI[CBS 3
QBUSJDLTUXTMJEFT 8IZ#-& ˙ *UJUDVSSFOUMZUSFOEJOHJO5BJXBO ˙ :PVSQSPGFTTPSMJLFTJU 4
QBUSJDLTUXTMJEFT 8IZ#-& ˙ *UJUDVSSFOUMZUSFOEJOHJO5BJXBO ˙ :PVSQSPGFTTPSMJLFTJU ˙ )FMJLFTCJHEBUBNPSF 5
QBUSJDLTUXTMJ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hcitool lescan gatttool -b [Address] -I 15
Communication with BLE device
QBUSJDLTUXTMJEFT ("551SPUPDPM [78:A5:04:19:59:B9][LE]> connect Attempting to connect to 78:A5:04:19:59:B9 Connection
successful 17
QBUSJDLTUXTMJEFT ("551SPUPDPM # Enable Humidity Sensor Service [78:A5:04:19:59:B9][LE]> char-write-cmd 0x3f
01 # Enable Notification [78:A5:04:19:59:B9][LE]> char-write-cmd 0x3c 01:00 Notification handle = 0x003b value: 38 6c be 84 Notification handle = 0x003b value: 38 6c be 84 ... http://processors.wiki.ti.com/images/a/a8/BLE_SensorTag_GATT_Server.pdf 18
QBUSJDLTUXTMJEFT 1SPDFTTJOH7BMVF var buffer = new Buffer([0x38, 0x6c, 0xbe, 0x84]);
var temperature = -46.85 + 175.72 / 65536.0 * buffer.readUInt16LE(0); var humidity = -6.0 + 125.0 / 65536.0 * (buffer.readUInt16LE(2) & ~0x0003); 19
QBUSJDLTUXTMJEFT 1SPDFTTJOH7BMVF ˙ 4BNQMF+4$PEF ˙ IUUQTHJUIVCDPNTBOEFFQNJTUSZOPEF TFOTPSUBHCMPCNBTUFSMJCDDKT ˙ 4QFDTBOE%PDVNFOUBUJPO ˙
IUUQQSPDFTTPSTXJLJUJDPNJOEFYQIQ 4FOTPS5BH@6TFS@(VJEF 20
Wrapping up with Node.js
QBUSJDLTUXTMJEFT *OTUBMM1BDLBHF sudo apt-get install nodejs npm sudo npm -g
install npm node-gyp npm install sensortag IUUQTHJUIVCDPNTBOEFFQNJTUSZOPEFTFOTPSUBH 22
QBUSJDLTUXTMJEFT OPEFTFOTPSUBH ˙ %FQFOETPOOPCMF /PEFKT#-& ˙ 8SBQVQBMMGFBUVSFTGPSBNPSFDMFBSDPEF 23
QBUSJDLTUXTMJEFT 3VO5FTU node test.js node test-cc2650-io.js 24
QBUSJDLTUXTMJEFT 1SPDFEVSF sensortag.discover(function(tag) { tag.connectAndSetUp(function(error) { tag.enableHumidity(function() { tag.notifyHumidity(); });
}); }); 4BZOPUPDBMMCBDLIFMM IUUQTHJUIVCDPNTBOEFFQNJTUSZOPEFTFOTPSUBH 25
QBUSJDLTUXTMJEFT 3FDFJWJOH%BUB tag.on('humidityChange', function (temperature, humidity) { }); 26
Feed it to Websocket
QBUSJDLTUXTMJEFT .BQUBHUPHMPCBM var _tag = {}; function enableService(error) { _tag[tag.uuid]
= tag; 28
QBUSJDLTUXTMJEFT XTGVODUJPO router.ws('/humidity/:uuid', function(ws, req) { _tag[uuid].on('humidityChange', function (temperature, humidity)
{ var obj = {}; obj[uuid] = { temperature: temperature, humidity: humidity }; ws.send(JSON.stringify(obj));; 29
QBUSJDLTUXTMJEFT OPUJGZEFWJDFTUBUVT function tagDiscovery(tag) { tag.on('disconnect', function() { // Remove
Property delete device_info[tag.uuid]; // Emit Disconnected Event events.emit('device_disconnect'); 30
QBUSJDLTUXTMJEFT OPUJGZEFWJDFTUBUVT var EventEmitter = require('events').EventEmitter, events = new EventEmitter();
router.ws('/connected', function(ws, req) { events.on('device_disconnect', function() { ws.send(JSON.stringify(device_info)); 31
Connecting to Multiple Device
QBUSJDLTUXTMJEFT 3VOUIFFYBNQMFDPEF 33
QBUSJDLTUXTMJEFT "OEJUXJMMOPUXPSL 34
QBUSJDLTUXTMJEFT 5SJDL ˙ %JTDPWFSUBH ˙ 4UPQEJTDPWFSXIJMFDPOOFDUJOH ˙ 3FTVNFEJTDPWFSZPODPOOFDUFEBOE EJTDPOOFDUFE 35
QBUSJDLTUXTMJEFT 4BNQMF$PEF ˙ IUUQTHJUIVCDPNKFSFNZ4FOTPSUBH 8FCTPDLFU 36
QBUSJDLTUXTMJEFT -JWF%FNP 37
Troubleshooting
QBUSJDLTUXTMJEFT 5SPVCMF*OEFY ˙ 31*EJTDPOOFDUFWFOUDBVTFTIBOH ˙ OPCMFXBSOJOHEVSJOHDPOOFDUJPOQSPDFTT ˙ $BOOPUFOBCMFEFWJDFTFSWJDF ˙ #-&"EESFTTVOLOPXOPO049
˙ .BYJNVNEFWJDF 39
Q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