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
Nervesで拡張性の高いIoTデバイスを作る / Making Extensible IoT...
Search
Kentaro Kuribayashi
November 26, 2020
Technology
3
980
Nervesで拡張性の高いIoTデバイスを作る / Making Extensible IoT Device with Nerves
K-Ruby #25
https://k-ruby.connpass.com/event/195281/
Kentaro Kuribayashi
November 26, 2020
Tweet
Share
More Decks by Kentaro Kuribayashi
See All by Kentaro Kuribayashi
Bidirectional Quadratic Voting Leveraging Issue-Based Matching
kentaro
2
300
大高生へのメッセージ(令和6年度「大高未来塾」) / Messages to Current Students
kentaro
0
220
「始め方」の始め方 / How to Start Starting Things
kentaro
5
820
Dynamic IoT Applications and Isomorphic IoT Systems Using WebAssembly
kentaro
1
1.2k
わたしがこのところハマっている「ライセンスフリー無線」のご紹介 / An Invitation to License-Free Radio
kentaro
1
460
先行きの見えなさを楽しさに変える ーVUCA時代のキャリア論と絶対他力主義ー / How to develop your career in the VUCA era
kentaro
7
4.9k
組織の生産性を高める意思決定の構造と方法 / How to do make decision rapidly and effectively
kentaro
39
22k
キャリアを時間・空間軸で考える / Thinking about your career from both time and space viewpoints
kentaro
15
16k
WEB+DB PRESSで特集記事を書く方法 / How to Become an Author of WEB+DB PRESS
kentaro
7
1.4k
Other Decks in Technology
See All in Technology
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
AIチャットボット開発への生成AI活用
ryomrt
0
170
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
370
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
Lambdaと地方とコミュニティ
miu_crescent
2
370
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
SSMRunbook作成の勘所_20241120
koichiotomo
2
130
AGIについてChatGPTに聞いてみた
blueb
0
130
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
KATA
mclloyd
29
14k
4 Signs Your Business is Dying
shpigford
180
21k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Scaling GitHub
holman
458
140k
Typedesign – Prime Four
hannesfritz
40
2.4k
Designing for humans not robots
tammielis
250
25k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Transcript
NervesͰ֦ுੑͷߴ͍IoTσόΠεΛ࡞Δ ܀ྛ ݈ଠʢGMOϖύϘגࣜձࣾɺઌՊֶٕज़େֶӃେֶʣ ϥΠτχϯάτʔΫ@K-Ruby #25ʢ202011݄26ʣ 1
܀ྛ ݈ଠ a.k.a. ͋ΜͪΆ https://kentarokuribayashi.com GMOϖύϘגࣜձࣾऔకCTO Ұൠࣾஂ๏ਓຊCTOڠձཧࣄ ઌՊֶٕज़େֶӃେֶʢJAISTʣത࢜ લظ՝ఔࡏֶதͷࣾձਓֶੜͰ͋Δ IoTηΩϡϦςΟؔ࿈Λݚڀ͢ΔͭΓ
ࣗݾհ 2
- NervesΛ༻͍ͯRaspberry PiͰLEDΛνΧνΧͤ͞ΔʢLνΧʣ - ElixirͷGenServerͱ͍͏ΈΛ֦ͬͯுՄೳͳઃܭΛ͢Δ - PhoenixΛ༻͍ͯWeb APIܦ༝ͰLEDΛνΧνΧͤ͞ΔʢΣϒνΧʣ - ΣϒνΧΛෳσόΠεؒͷ௨৴ʹΑ࣮ͬͯݱ͢ΔలΛड़Δ
ίʔυͷৄࡉΑΓʮElixirͱNervesͩͱ͜Μͳ͜ͱ͕؆୯ʹͰ͖͍ͯ͢͝ʂʯ ͱ͍͏Λ͠·͢ʢίʔυGitHubʹΞοϓͯ͠ΔͷͰɺৄࡉͦͪΒΛࢀর ͍ͯͩ͘͠͞ʣɻ ͜ͷLTͰ͢͜ͱ 3
- ϓϥοτϑΥʔϜ - ϓϩηεͱݺΕΔܰྔεϨουʹΑΓɺεέʔϥϏϦςΟ͕ߴ͍ - ϓϩηεΛࢹ͠ো࣌ʹࣗಈ෮چͰ͖ΔͨΊɺোੑ͕ߴ͍ - ݴޠ - ؔܕݴޠͰ͋Γɺ؆ܿͰϝϯςφϯεੑͷߴ͍ίʔυΛॻ͚Δ
- ڧྗͳύλʔϯϚονϯάػೳɺϚΫϩʹΑΔݴޠͷ֦ுੑΛ༗͢Δ - πʔϧ - ϏϧυπʔϧͷMixύοέʔδϚωʔδϟʔͷHexͷπʔϧ͕ॆ࣮ - Erlang VM্Ͱಈͨ͘ΊɺErlangͷརɾࢿ࢈Λ׆༻Ͱ͖Δ Elixirͷಛ ग़ॴ: The Elixir programming language ΑΓචऀ͕·ͱΊͨ 4
- ElixirͰIoTσόΠεΛ։ൃ͢ΔͨΊͷศརͳ͘͠ΈҰࣜΛఏڙ - ϓϥοτϑΥʔϜ: BEAMʢErlang VMʣΛϒʔτ͢ΔϛχϚϧͳLinuxϑΝʔϜ ΣΞΛఏڙ - ϑϨʔϜϫʔΫ: ElixirͰIoTσόΠεΛૉૣ͘։ൃ͢ΔͨΊͷϥΠϒϥϦ܈Λఏڙ
- πʔϧνΣΠϯ: ϑΝʔϜΣΞΛϏϧυͨ͠ΓσϓϩΠͨ͠Γ͢ΔͨΊͷCLI πʔϧΛఏڙ - ͦͷଞ: ϑΝʔϜΣΞΛOTA͢ΔͨΊͷNervesHubͱ͍͏ج൫Λఏڙʢݸਓత ʹ͜͜ͷڵຯ͔ΒNervesʹϋϚΓ࢝Ίͨʣ Nervesͱ ग़ॴ: Nerves PlatformɺGetting Started — nerves v1.7.0 ΑΓචऀ͕·ͱΊͨ 5
ී௨ͷLνΧ ී௨ͷLνΧ 6
- લϖʔδͷίʔυͰɺϕλʹϧʔϓΛճͯ͠νΧνΧ͍ͤͯ͞Δ - LνΧΛ࣮͢Δ෦Λଞͷػೳͱͭͳ͍͛ͨͱࢥͬͨΒͲ͏͢Δʁ - Web API͔ΒLνΧΛݺͼग़͍ͨ͠ʢࠓճͬͨ͜ͱͱͯ͢͠༰ʣ - ෳσόΠεʹεέʔϧΞτ͍ͨ͠ʢࠓޙͷలͱͯ͢͠༰ʣ -
ElixirʹΑΔϓϩάϥϛϯάͰɺଟͷϓϩηεؒͷϝοηʔδϯά ύογϯάʹΑͬͯઃܭ͢Δ - ϋʔυΣΞͷૢ࡞ͱɺૢ࡞ґཔϦΫΤετͷॲཧͱΛΘ͚ͯઃܭ͢Δ LνΧΛ࠶ઃܭ͢Δ 7
LνΧͷॲཧΛߏ͢Δϓϩηε܈ Supervisor Worker Led supervise WorkerͱLedϓϩηεΛ supervise͠ɺϓϩηε͕མ ͪͨΒ্ཱͪ͛͢ɻ LEDΛΦϯɾΦϑͨ͠Γɺ ໓ͤͨ͞Γ͢ΔೖΓޱΛ
ఏڙ͢Δϓϩηεɻ෦Ͱ ϧʔϓॲཧ୲͍ͬͯΔɻ ҎԼͷϝοηʔδʹԠ͢ Δɻ :turn_on :turn_off :start_blinking :stop_blinking LEDͷૢ࡞Λఏڙ͢Δϓϩη εɻҎԼͷϝοηʔδʹԠ ͢Δɻ :turn_on :turn_off 8 Message
- 1. ΫϥΠΞϯτϓϩηε͔ΒϝοηʔδΛड͚औΓɺ2. ͳΜΒ͔ͷॲཧΛ͠ ͯɺ3. ݁ՌΛฦ͢ͱ͍͏ʮαʔόʔϓϩηεͷ͋Δ͋ΔύλʔϯʯΛఆٛ - αʔόʔϓϩηεεςʔτϑϧͰ͋Δʢ෦ঢ়ଶΛ͍࣋ͬͯΔʣ - ۩ମతʹɺJavaͰ͍͏InterfaceͷΑ͏ͳΈͰ͋ΔBehaviourʹΑ࣮ͬͯݱ
͍ͯ͠Δ - ΫϥΠΞϯτ͔Βͷಉظɾඇಉظݺͼग़͠ͷͲͪΒʹରԠ͍ͯ͠Δ - SupervisorͷࢹԼʹஔ͘ͱɺαʔόʔϓϩηε͕ࢮΜͰࣗಈతʹ࠶ىಈ͞Ε ΔΑ͏ʹͰ͖Δ GenServer 9
- ͲͪΒGenServerΛ༻͍࣮ͯ͞Εͨϓϩηε - Workerϓϩηε - ֎෦ϓϩηεʢREPLWeb APIͳͲʣ͔ΒͷɺϋʔυΣΞʢ͜͜ͰLEDʣͷૢ࡞Λ ґཔ͢ΔϦΫΤετΛड͚͚Δ - LEDΛνΧνΧͤ͞ΔͨΊͷϧʔϓॲཧ୲͏ʢվળͷ༨͋Γ※ʣ
- Ledϓϩηε - Workerϓϩηε͔ΒΈΔͱαʔόʔϓϩηεʹ͋ͨΔ - ϋʔυΣΞͷૢ࡞Λ୲͏ɻ۩ମతʹɺRaspberry PiͷGPIOܦ༝ͰLEDΛૢ࡞͢Δ WorkerͱLed ※ ʮ͡ΊͯNerves(6) GPIOೖྗͷΤοδΛͬͯΠϕϯτυϦϒϯͳϘλνΧΛ͢Δʯࢀরɻ 10
ElixirͷREPLʢIExʣ͔ΒLνΧ͢Δ start_blinkingͰLνΧ։ ࢝ stop_blinkingͰLνΧऴྃ ʢ͕௧͘ͳΔͷͰ……ʣ νΧνΧ͍ͯ͠Δʂ 11
ίʔυ kentaro/nerves_webchika Ͱʂ 12
- ࣍ɺWebʢAPIʣܦ༝ͰLνΧ=ʮΣϒνΧʯʢ※ʣ͍ͨ͠ - Web APIͷ࣮ɺElixirͷσϑΝΫτελϯμʔυͳWAFͰ͋Δ PhoenixΛ༻͍Δ - ࣮ʹࡍͯ͠ɺطʹݟͨLνΧΛߏ͢Δϓϩηε܈ͷϝοηʔδ ύογϯά͚ͩͰ࣮ݱ͢Δ -
ͭ·ΓɺWeb APIଆͰϋʔυΣΞͷૢ࡞Λ୲͏࣮ʹґଘ͠ͳ͍Α͏ ʹ͢Δ Web͔ΒLνΧʢΣϒνΧʣ͍ͨ͠ ※ ʮElixir_Nervesೖʂݎ࿚ͳIoT EdgeσόΠεϓϩάϥϛϯάΛ͓खܰʹʙNervesͰͭ͘ΔΣϒνΧʙʯ͕ൃʁ 13
ΣϒνΧͷॲཧΛߏ͢Δϓϩηε܈ Supervisor Worker Led supervise HTTP௨৴ ϝοηʔδૹ৴ 14 Ϣʔβ͔ΒͷWebܦ༝Ͱ ͷૢ࡞ϦΫΤετΛड͚
͚ΔAPIΛఏڙ Web API
Web APIͷίʔυʢ࣮࣭ʣ͜Ε͚ͩ nerves.local/led/... - start_blinking - stop_blinking - turn_on -
turn_off WorkerʹϝοηʔδΛૹΔ 15
ίʔυ kentaro/nerves_webchika Ͱʂ 16
- ϑΝʔϜΣΞͷىಈ࣌ʹࣗಈͰLνΧ࢝·ΔΑ͏ʹ͠ͳ͔ͬͨͷɺ։ൃ࣌ʹ͕ νΧνΧ௧͘ͳΔ͔Β - WorkerɺLedͷϓϩηεΞϓϦέʔγϣϯىಈ࣌ʹࣗಈతʹىಈ - ৄ͘͠ίʔυΛࢀরͷ͜ͱ - ࠓճ1ͷRaspberry Pi্ͰɺWeb
APIΛؚΉશͯͷϓϩηεΛ࣮ߦ͕ͨ͠ɺෳʹ ༰қʹεέʔϧΞτͰ͖Δʢ※ʣ - ܭࢉϦιʔεΛେྔʹফඅͨ͠ΓɺI/Oͷ͕ଟ͔ͬͨΓ͢ΔΑ͏ͳσόΠεΛ࡞Δ߹ʹศ ར - ͞ΒʹϝοηʔδΛPub/SubͰΓͱΓ͢ΔͱΑΓૄ݁߹ʹͳ͍͍ͬͯײ͡ ิͱٞ ※ ۩ମతʹʮ͡ΊͯNerves(8) ୯ҰϗετͰಈ͘γεςϜΛෳϗετʹࢄ͢ΔʯΛࢀরͷ͜ͱ 17
ෳͷཧϊʔυʹ֦ு͞Εͨϓϩηε܈ Supervisor Worker Led supervise Ϣʔβ͔ΒͷWebܦ༝Ͱ ͷૢ࡞ϦΫΤετΛड͚ ͚ΔAPIΛఏڙ Web API
HTTP௨৴ ϝοηʔδૹ৴ 18 ϊʔυ 1 ϊʔυ 2
- NervesΛ༻͍ͯRaspberry PiͰLEDΛνΧνΧͤͨ͞ʢLνΧʣ - ElixirͷGenServerͱ͍͏ΈΛ֦ͬͯுՄೳͳઃܭΛͨ͠ - PhoenixΛ༻͍ͯWeb APIܦ༝ͰLEDΛνΧνΧͤͨ͞ʢΣϒνΧʣ - ΣϒνΧΛෳσόΠεؒͷ௨৴ʹΑ࣮ͬͯݱ͢ΔలΛड़ͨ
ElixirͱNervesͰIoTσόΠεΛ࡞ΔͷϚδͰେ͖ͳՄೳੑΛײ͡Δɻ ·ͱΊ 19