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
1k
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
あとはAIに任せて人間は自由に生きる
kentaro
3
1.1k
社会人力と研究力ー博士号をキャリアの武器にするー
kentaro
3
180
IoTシステム開発の複雑さを低減するための統合的アーキテクチャ
kentaro
2
1.8k
Bidirectional Quadratic Voting Leveraging Issue-Based Matching
kentaro
2
540
大高生へのメッセージ(令和6年度「大高未来塾」) / Messages to Current Students
kentaro
0
310
「始め方」の始め方 / How to Start Starting Things
kentaro
5
940
Dynamic IoT Applications and Isomorphic IoT Systems Using WebAssembly
kentaro
1
1.6k
わたしがこのところハマっている「ライセンスフリー無線」のご紹介 / An Invitation to License-Free Radio
kentaro
1
650
先行きの見えなさを楽しさに変える ーVUCA時代のキャリア論と絶対他力主義ー / How to develop your career in the VUCA era
kentaro
7
6.2k
Other Decks in Technology
See All in Technology
kintone開発チームの紹介
cybozuinsideout
PRO
0
73k
帳票Vibe Coding
terurou
0
140
新卒(ほぼ)専業Kagglerという選択肢
nocchi1
1
2.2k
AIとTDDによるNext.js「隙間ツール」開発の実践
makotot
5
660
知られざるprops命名の慣習 アクション編
uhyo
10
2.4k
JOAI発表資料 @ 関東kaggler会
joai_committee
1
260
夢の印税生活 / Life on Royalties
tmtms
0
280
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
8.6k
Claude Code x Androidアプリ 開発
kgmyshin
1
570
Backboneとしてのtimm2025
yu4u
4
1.4k
第4回 関東Kaggler会 [Training LLMs with Limited VRAM]
tascj
12
1.7k
[CV勉強会@関東 CVPR2025 読み会] MegaSaM: Accurate, Fast, and Robust Structure and Motion from Casual Dynamic Videos (Li+, CVPR2025)
abemii
0
190
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
RailsConf 2023
tenderlove
30
1.2k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Site-Speed That Sticks
csswizardry
10
780
Automating Front-end Workflow
addyosmani
1370
200k
Documentation Writing (for coders)
carmenintech
73
5k
GitHub's CSS Performance
jonrohan
1031
460k
Balancing Empowerment & Direction
lara
2
590
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Music & Morning Musume
bryan
46
6.7k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
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