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

Streaming camera for Hamster - Using Raspberry Pi and PHP’s Swoole -

218473ff7abad0fcd72865da2b23bb5b?s=47 memory
April 24, 2019

Streaming camera for Hamster - Using Raspberry Pi and PHP’s Swoole -



April 24, 2019


  1. Streaming camera for Hamster - Using Raspberry Pi and PHP’s

    Swoole - 04/24/2019 PHP study meetup at Tokyo In Japan memory (@m3m0r7)
  2. Who am I?

  3. memory (@m3m0r7) I’m a server-side and front-end engineer. I like

    PHP and React.js. And I’m working at an IT company in Japan.
  4. What am I making recently?

  5. https://github.com/php-java/php-java

  6. None
  7. Hamster is…

  8. Lily Sex: female Birthday: 11/01/2018 Likes: biscuits and apple-tree branches

    Dislikes: pear-tree branches Hobby: biting at a waterer
  9. Have you ever used Swoole?

  10. And have you ever used Raspberry Pi?

  11. None
  12. Camera for daytime Camera for nighttime

  13. These cameras are installed in my home.

  14. None
  15. It is Lily’s rack.

  16. In the red frame is a Raspberry Pi

  17. Technologies

  18. - Raspbian (Raspberry Pi) - PHP 7.3 - Swoole v4

    - Python 3 - React.js (+ Gulp) Mainly five technologies
  19. How much are they?

  20. - Raspberry Pi 3 Model B * 2 ≒ 5,200

    * 2 ≒ 10,000 JPY - Camera modules * 2 ≒ 5,000 * 2 ≒ 10,000 JPY - VPS (ConoHa[1]) ≒ 2,500/mo JPY - Router ≒ 15,000 JPY Initial costs ≒ 37,500 JPY Running costs ≒ 2,500 JPY [1] ConoHa is a VPS service provided by GMO (Japanese IT company).
  21. A little expensive here.

  22. How about a latency?

  23. No more than 0.5 sec.

  24. The server’s architecture is…

  25. My Home LAN VPS (ConoHa) PiCamera Module Four-byte size data

    in unsigned long + picamera.start_recording (mjpeg) Sends image data from daytime camera through TCP connections Sends Image data from night camera through TCP connections
  26. What is happening in My Home LAN side?

  27. - I didn’t want to expose any ports from my

    home - Intermediate server definitely solved this! I chose ConoHa this time. - Bought a router brand new, which is super cool :) - Sending to VPS (ConoHa) using picamera on Python 3
  28. Built with high speed and stability. Supported A Wi-Fi Router

    Equipped with MU-MIMO Technologies High speed connections for multiple devices. Concentrated connections to destination devices by “AiRader” Technology. This Wi-Fi router is capable of delivering electromagnetic wave to the entire home because its covering area is very large.
  29. What is happening in the VPS side?

  30. - By using Coroutines on PHP's Swoole, I made an

    inbound server for Raspberry Pi, and an outbound server for sending to ConoHa - That’s it! Simple is best.
  31. * Some part of codes

  32. Production screen is…

  33. None
  34. Test for streaming plays

  35. How did I do this?

  36. Wave hands beneath the cameras.

  37. None
  38. - mjpeg stands for Motion JPEG. - I have also

    investigated H.264 but its latency increases by 5 sec via ffmpeg. Thus, I chose mjpeg. - Keeps connected in MIME type multipart/x-mixed-replace. - (The browser continuously indicates the page is being loaded) - Latency appears to be roughly 0.5 sec - Renders smoothly.
  39. My impressions for Swoole

  40. - Amazing async processing in PHP! - Relatively easy to

    install because of unnecessity of --enable-maintainer- zts when building. - I pray to Swoole so Atomic can accept at least serializable values. - I’m using Channel instead of Atomic.
  41. Problems are…

  42. The script crashes 2 days later.

  43. I don’t know how to resolve it:
 I don’t record

    any logs ʗ(^o^)ʘ
  44. Finish