Slide 1

Slide 1 text

Streaming camera for Hamster - Using Raspberry Pi and PHP’s Swoole - 04/24/2019 PHP study meetup at Tokyo In Japan memory (@m3m0r7)

Slide 2

Slide 2 text

Who am I?

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

What am I making recently?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Hamster is…

Slide 8

Slide 8 text

Lily Sex: female Birthday: 11/01/2018 Likes: biscuits and apple-tree branches Dislikes: pear-tree branches Hobby: biting at a waterer

Slide 9

Slide 9 text

Have you ever used Swoole?

Slide 10

Slide 10 text

And have you ever used Raspberry Pi?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Camera for daytime Camera for nighttime

Slide 13

Slide 13 text

These cameras are installed in my home.

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

It is Lily’s rack.

Slide 16

Slide 16 text

In the red frame is a Raspberry Pi

Slide 17

Slide 17 text

Technologies

Slide 18

Slide 18 text

- Raspbian (Raspberry Pi) - PHP 7.3 - Swoole v4 - Python 3 - React.js (+ Gulp) Mainly five technologies

Slide 19

Slide 19 text

How much are they?

Slide 20

Slide 20 text

- 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).

Slide 21

Slide 21 text

A little expensive here.

Slide 22

Slide 22 text

How about a latency?

Slide 23

Slide 23 text

No more than 0.5 sec.

Slide 24

Slide 24 text

The server’s architecture is…

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

What is happening in My Home LAN side?

Slide 27

Slide 27 text

- 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

Slide 28

Slide 28 text

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.

Slide 29

Slide 29 text

What is happening in the VPS side?

Slide 30

Slide 30 text

- 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.

Slide 31

Slide 31 text

* Some part of codes

Slide 32

Slide 32 text

Production screen is…

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Test for streaming plays

Slide 35

Slide 35 text

How did I do this?

Slide 36

Slide 36 text

Wave hands beneath the cameras.

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

- 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.

Slide 39

Slide 39 text

My impressions for Swoole

Slide 40

Slide 40 text

- 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.

Slide 41

Slide 41 text

Problems are…

Slide 42

Slide 42 text

The script crashes 2 days later.

Slide 43

Slide 43 text

I don’t know how to resolve it:
 I don’t record any logs ʗ(^o^)ʘ

Slide 44

Slide 44 text

Finish

Slide 45

Slide 45 text

THANK YOU FOR YOUR LISTENING!!