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
200
Club Mate and Hacker - 34C3 @ SITCON
jeremy5189
2
670
SITCON 2017 論壇系統開發分享 @ SITCON 2017 Summer
jeremy5189
0
220
poManeuver: Poland into space
jeremy5189
0
410
How we hacked a forum
jeremy5189
0
430
Bdecisive - Booking.com Taipei Hack 2nd Prize
jeremy5189
0
540
Social Intelligence Smart-device project
jeremy5189
0
62
遺失的學校 - SITCON 2014 Lightning Talk
jeremy5189
0
560
Other Decks in Technology
See All in Technology
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
Taming you application's environments
salaboy
0
200
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
540
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.5k
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
The Rise of LLMOps
asei
8
1.7k
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
150
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
670
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
190
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.2k
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Building an army of robots
kneath
302
43k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Practical Orchestrator
shlominoach
186
10k
Speed Design
sergeychernyshev
25
620
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Building Applications with DynamoDB
mza
90
6.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Faster Mobile Websites
deanohume
305
30k
Being A Developer After 40
akosma
87
590k
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
QBUSJDLTUXTMJEFT 0CKFDUJWFT ˙ 6OEFSTUBOEJOH#-&QSPUPDPMGBTUFS ˙ #VJMEZPVSQSPKFDURVJDLMZ ˙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empting 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
QBUSJDLTUXTMJEFT 31*EJTDPOOFDUFWFOUDBVTFTIBOH ˙ ,OPXOJTTVF VOTPMWFE ˙ IUUQTHJUIV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