$30 off During Our Annual Pro Sale. View Details »
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
310
大高生へのメッセージ(令和6年度「大高未来塾」) / Messages to Current Students
kentaro
0
220
「始め方」の始め方 / How to Start Starting Things
kentaro
5
830
Dynamic IoT Applications and Isomorphic IoT Systems Using WebAssembly
kentaro
1
1.2k
わたしがこのところハマっている「ライセンスフリー無線」のご紹介 / An Invitation to License-Free Radio
kentaro
1
470
先行きの見えなさを楽しさに変える ーVUCA時代のキャリア論と絶対他力主義ー / How to develop your career in the VUCA era
kentaro
7
5k
組織の生産性を高める意思決定の構造と方法 / 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.5k
Other Decks in Technology
See All in Technology
次のコンテナセキュリティの時代 - User Namespace With a Pod / CloudNative Days Winter 2024
pfn
PRO
5
450
asumikamというカンファレンスオーガナイザの凄さを語る / The Brilliance of Asumikam
tomzoh
1
170
高品質と高スピードを両立させるソフトウェアQA/Software QA that Supports Agility and Quality
goyoki
5
560
深層学習のリペア技術の最新動向と実際 / DNN Repair Techniques for AI Performance Alignment for Safety Requirements
ishikawafyu
0
140
TimeTreeが経た3つの転換点 ー プロダクト成長過程でその時、その瞬間、何を考えてたか
ysmtysts
0
280
Empowering Customer Decisions with Elasticsearch: From Search to Answer Generation
hinatades
PRO
0
180
サービスの拡大に伴うオペレーション課題に立ち向かう / 20241128_cloudsign_pdm
bengo4com
0
810
最強DB講義 #35 大規模言語モデルに基づく検索モデル
mpkato
1
120
Raspberry Pi 秋の新製品をチェックしてみよう / 20231202-rpi-jam-tokyo
akkiesoft
0
220
MediaPipe と ML Kit ってどう ちがうの? / What is the difference between MediaPipe and ML Kit?
yanzm
0
260
そろそろOn-Callの通知音について考えてみよう (PagerDuty編)
tk3fftk
1
290
偶有的複雑性と戦うためのアーキテクチャとチームトポロジー
knih
7
6.1k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Become a Pro
speakerdeck
PRO
25
5k
How STYLIGHT went responsive
nonsquared
95
5.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
17k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Rails Girls Zürich Keynote
gr2m
94
13k
KATA
mclloyd
29
14k
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