Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ハムスターを監視するシステムを Raspberry Pi と PHP の Swoole で作った話.pdf

memory
April 24, 2019

ハムスターを監視するシステムを Raspberry Pi と PHP の Swoole で作った話.pdf

memory

April 24, 2019
Tweet

More Decks by memory

Other Decks in Programming

Transcript

  1. ϋϜελʔΛ؂ࢹ͢ΔγεςϜΛ
    Raspberry Pi ͱ PHP ͷ Swoole Ͱ࡞ͬͨ࿩
    2019/04/24

    PHPษڧձ@౦ژ

    Ί΋Γʙ

    View full-size slide

  2. Ί΋Γʙ (@m3m0r7)
    גࣜձࣾ GameWith Ͱ αʔόʔαΠυ݉ϑϩϯτΤϯυΤϯδχΞ

    ͱͯ͠ಇ͍ͯ·͢ɻ

    ϐʔΤΠνϐʔνϣοτσΩϧ

    2019 ೥ͷ 5 ݄຤ʹ΍Ί·͢ɻస৬׆ಈதͰ͢ɻ

    View full-size slide

  3. ͏ͪͷϋϜελʔͷ͝঺հ

    View full-size slide

  4. Lily (ϦϦΟ)
    ੑผɿঁͷࢠ

    ஀ੜ೔ɿ2018 ೥ 11 ݄

    ޷͖ͳ৯΂෺ɿ Ϗεέοτ, Ϧϯΰͷ͔͡Γ໦

    ݏ͍ͳ৯΂෺ɿསͷ͔͡Γ໦

    झຯɿڅਫثͷϊζϧΛΨδΨδ͢Δ͜ͱɻ૸ΔΑΓ޷͖Έ͍ͨͰ͢

    View full-size slide

  5. Έͳ͞ΜɺSwoole Λ࢖ͬͨ͜ͱ͸͋Γ·͔͢ʁ

    View full-size slide

  6. ͦͯ͠ɺRaspberry Pi Λ࢖ͬͨ͜ͱ͸͋Γ·͔͢ʁ

    View full-size slide

  7. ϊʔϚϧΧϝϥϞδϡʔϧ ໷ؒ༻ΧϝϥϞδϡʔϧ

    View full-size slide

  8. ͏ͪͷ Raspberry Pi Ͱ͢

    View full-size slide

  9. ͏ͪͷϋϜελʔઐ༻ͷϥοΫͰ͢

    View full-size slide

  10. ͜ͷ੺࿮͕ࠓճͷ Raspberry Pi Λ
    ͓͍ͯΔͱ͜ΖʹͳΓ·͢

    View full-size slide

  11. ٕज़ελοΫ

    View full-size slide

  12. - Raspbian (Raspberry Pi)
    - PHP 7.3
    - Swoole v4
    - Python 3
    - React.js (+ Gulp)
    ओʹ͜ͷ 5 ͭ

    View full-size slide

  13. අ༻͸͍͘Βͩͬͨͷ͔ʁ

    View full-size slide

  14. - Raspberry Pi 3 Model B * 2 ≒ 5,200 * 2 ≒ 10,000 ԁ
    - ΧϝϥϞδϡʔϧ * 2 ≒ 5,000 * 2 ≒ 10,000 ԁ
    - VPS (ࠓճ͸ ConoHa) ≒ 2,500/m ԁ
    - ϧʔλʔ ≒ 15,000 ԁ
    Πχγϟϧίετ ≒ 37,500 ԁ
    ϥϯχϯάίετ ≒ 2,500 ԁ

    View full-size slide

  15. ׂͱ͍͍஋ஈ͠·͢

    View full-size slide

  16. ϨΠςϯγ͸ʁ

    View full-size slide

  17. ମײ 0.5 ඵ͘Β͍

    View full-size slide

  18. αʔόʔͷߏ੒

    View full-size slide

  19. ࣗ୐ LAN VPS (ConoHa)
    PiCamera
    Ϟδϡʔϧ
    4 byte ͷunsigned long ͳαΠζσʔλ +
    picamera.start_recording (mjpeg)
    ϊʔϚϧΧϝϥ ͔Β TCP Ͱૹ৴
    φΠτΧϝϥ͔Β TCP Ͱૹ৴

    View full-size slide

  20. ࣗ୐ LAN ଆ͸Ͳ͏ͳ͍ͬͯΔͷ͔ʁ

    View full-size slide

  21. - ͦ΋ͦ΋ࣗ୐ͷωοτϫʔΫͷϙʔτ͸։͚ͨ͘ͳ͔ͬͨ
    - தܧαʔόʔ͓͚͹ສࣄղܾʂ͘͞Βͷ VPS ͷ౦ژϦʔδϣϯ͕ۭ͍ͯ
    ͳ͔ͬͨͷͰɺࠓճ͸࿩୊෸ಅͷ ConoHa ΛνϣΠε
    - ϧʔλʔΛ৽ௐͯ͠࠷ߴͷ؀ڥʹͨ͠
    - Python3 ͷ picamera Λ࢖ͬͯແݶʹ VPS (ConoHa) ʹૹΓ͚͍ͭͯ·͢

    View full-size slide

  22. VPS ଆ͸Ͳ͏ͳ͍ͬͯΔͷ͔ʁ

    View full-size slide

  23. - PHP ͷ Swoole ͷ Coroutine Λ࢖ͬͯ Raspberry Pi ͔Βͷσʔλͷड৴
    ༻αʔόʔ, ConoHa ΁σʔλΛૹΔͨΊͷૹ৴༻αʔόʔΛ༻ҙ
    - ͨͬͨ͜Ε͚ͩʂ Simple is best.

    View full-size slide

  24. ※ Ұ෦ͷίʔυ

    View full-size slide

  25. ࣮ࡍͷϓϩμΫτͷը໘

    View full-size slide

  26. ετϦʔϛϯάͷςετ

    View full-size slide

  27. Ͳ͏΍͔ͬͨʁ

    View full-size slide

  28. ΧϝϥͷԼͰखΛৼΓͭͭϐʔεΛ͢Δ

    View full-size slide

  29. - mjpeg ͸ Motion JPEG ͷུɻ
    - H.264΋ݕ౼ͨ͠ͷͰ͕͢ɺ ffmpeg Λ௨͢ͱϨΠςϯγ͕ 5 ඵ͘Β͍૿͑Δ໰୊
    ͕͋Γ, mjpeg ΛνϣΠε
    - MIME type ͸ multipart/x-mixed-replace Ͱৗ࣌ίωΫγϣϯΛషΔ
    - (ͳͷͰɺϒϥ΢βͷλϒ͸ϩʔσΟϯάதͷ··)
    - ϨΠςϯγ͸ ମײ 0.5 ඵ͘Β͍ɻͦ͜Β΁Μͷ΋ͷΑΓૣ͍
    - ΊͬͪΌ͵Δ͵Δʹಈ͘

    View full-size slide

  30. Swoole Λ࢖ͬͯΈͯͷײ૝

    View full-size slide

  31. - PHP Ͱඇಉظॲཧ࢖͑Δͷਆʂ
    - Ϗϧυ࣌ʹ —enable-maintainer-zts Λ͠ͳ͍͍ͯ͘ͷͰɺಋೖͷϋʔυ
    ϧ͕௿͍ ( phpize ͚ͩͰ͍͚Δ )
    - Atomic ͕ͤΊͯ serializable ͳ΋ͷ΋࢖͑ΔΑ͏ʹͳΔͱͳ͓خ͍͠
    - ݱঢ়Ͱ͖ͳ͍ͷͰɺ Channel Ͱແཧ΍Γ Coroutine ؒͷσʔλͷड͚౉
    ͠Λ͍ͯ͠·͢ɻ

    View full-size slide

  32. ೋ೔ޙʹεΫϦϓτ͕མͪΔ

    View full-size slide

  33. ϩάऔͬͯͳ͍ͷͰམͪͨ
    ݪҼ͕Θ͔Βͳ͍ʗ(^o^)ʘ

    View full-size slide

  34. THANK YOU FOR YOUR LISTENING !!

    View full-size slide