Module1. DoorWatcher - GachonCapstoneDesign/DoorWatcher GitHub Wiki

Summary:

Do Streaming for the scene taken by Raspberry Pi camera through Mobile application.

function

You can download the source code in github

  • Github. hyper-link to github repository

Streaming

Do streaming for the scene of the front door from Raspberry Pi camera on mobile application. Can watch the scene on real-time streaming.


Unsuspected_Person_Detection

Raspberry Pi starts counting when motion is detected while viewing the front door from the camera. If there is a change of motion and we actually go through the threshold, which is calculated after lots of tests to get, we are judged to be suspicious.


PushMessage

If it is judged to be a suspicious person, the Raspberry pie camera sends a message to the server. At this time, when the server receives the message, it sends PushMessage to the token number recorded in the server. It will be broadcast in the App and pop up to the user.


DefaultSetting

1. External network configuration

In order to access Raspberry Pi from external network, we set the IP address of Internet connected to Raspberry Pi to connect from external network. How to set up connection from external network is explained in detail by clicking URL below.

  • If you want to see an explanation, please click URL.

2. Run 'app.py' from the raspberry pi

When you run this file, Raspberry Pi will open its own web server. When an access request is made to the opened web server, the requestor displays index.html in the templates folder. It also displays the frame that the Raspberry pi camera module takes on index.html. The streaming is doing by the user to show the screen shot by the camera on the index.html. At this time, Access requests to the web streaming will reduce the load of Raspberry pi. Access to the web is addressed to:

[Raspberry Pi IP address]:5000

3. Enter the Android project and open 'StreamingActivity.java'

browser = (WebView) findViewById(R.id.webview1);
browser.getSettings().setJavaScriptEnabled(true);
browser.loadUrl("http:/192.168.0.12:5000/");

In the upper part, change the IP Address to your Raspberry IP Address. You can also set password and id after login activity. The default is `id:" ", pwd:" "`.

4. Turn on the application and check the streaming

If you run app.py from Raspberry Pie and install the project on your smartphone and run it, you can stream it.

5. Sets the path for the Push Message

Replace your server address with the address inside urlopen. (94 line)

 urllib2.urlopen("http://pesang72.cafe24.com/push/GCMSender.php").read()

and inside of 'GCMSender.php'

$devices = array() 

Put your Android token number in (). Upload 'GCMSender.php', 'GCMPushMessage.php' to your server. When you are done with this setting, you will receive a message if you detect someone suspicious at home.





[ ํ•œ๊ธ€ ์œ„ํ‚ค ]

Summary:

๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์˜ ์นด๋ฉ”๋ผ๋ฅผ ์ด์šฉํ•ด์„œ ์ŠคํŠธ๋ฆฌ๋ฐํ•˜๋Š” ์žฅ๋ฉด์„ ์Šค๋งˆํŠธํฐ์œผ๋กœ ์ŠคํŠธ๋ฆฌ๋ฐ ํ•ฉ๋‹ˆ๋‹ค.

function

์ด ์ฝ”๋“œ๋Š” ํ˜„์žฌ ๊นƒํ—ˆ๋ธŒ์— ์˜ฌ๋ ค๋†จ์Šต๋‹ˆ๋‹ค.

  • Github. ํ•˜์ดํผ๋งํฌ๋ฅผ ํด๋ฆญํ•˜์‹œ๋ฉด ๊นƒํ—ˆ๋ธŒ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

Streaming

๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด ์นด๋ฉ”๋ผ๋ฅผ ํ†ตํ•ด์„œ ํ˜„๊ด€๋ฌธ ์•ž์˜ ์ƒํ™ฉ์„ ์ŠคํŠธ๋ฆฌ๋ฐ ํ•ฉ๋‹ˆ๋‹ค. ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ŠคํŠธ๋ฆฌ๋ฐ ํ•˜๋Š” ์žฅ๋ฉด์„ ์Šค๋งˆํŠธํฐ์œผ๋กœ ์ง€์ผœ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


Unsuspected_Person_Detection

๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด ์นด๋ฉ”๋ผ์—์„œ ํ˜„๊ด€๋ฌธ์„ ๋ณด๋Š” ๋„์ค‘์— ์›€์ง์ž„์ด ๊ฐ์ง€๋˜๋ฉด ์นด์šดํŠธ๋ฅผ ์„ธ๊ธฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๊ณ„์†๋˜๋Š” ์›€์ง์ž„์˜ ๋ณ€ํ™”๊ฐ€ ์žˆ๊ณ  ์ €ํฌ๊ฐ€ ์‹ค์ œ๋กœ ์ˆ˜ ๋งŽ์€ ํ…Œ์ŠคํŠธ๋ฅผ ๊ฑฐ์ณ์„œ ๊ฒฐ์ •ํ•œ ์นด์šดํŠธ๋ฅผ ๋„˜์–ด๊ฐ€๋ฉด ์ˆ˜์ƒํ•œ ์‚ฌ๋žŒ์ด๋ผ๊ณ  ํŒ๋‹จํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.


PushMessage

์ˆ˜์ƒํ•œ ์‚ฌ๋žŒ์ด๋ผ๊ณ  ํŒ๋‹จํ•˜๊ฒŒ ๋˜๋ฉด ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด ์นด๋ฉ”๋ผ์—์„œ ์„œ๋ฒ„๋กœ message๋ฅผ ๋ณด๋ƒ…๋‹ˆ๋‹ค. ์ด๋•Œ ์„œ๋ฒ„์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›์œผ๋ฉด ์„œ๋ฒ„์— ๊ธฐ๋กํ•ด๋†“์€ ํ† ํฐ๋ฒˆํ˜ธ๋กœ ใ…”ใ…”PushMessage๋ฅผ ๋ณด๋‚ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ App์—์„œ Broadcast ๋กœ ์žก์•„๋‚ด์–ด ์œ ์ €์—๊ฒŒ ํŒ์—…์„ ๋„์›Œ์ค๋‹ˆ๋‹ค.


DefaultSetting

1. ์™ธ๋ถ€๋ง ์„ค์ •

์™ธ๋ถ€๋ง์—์„œ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์— ์ ‘๊ทผํ•˜๊ธฐ์œ„ํ•ด์„  ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์— ์—ฐ๊ฒฐ๋œ ์ธํ„ฐ๋„ท์˜ IP address๋ฅผ ์™ธ๋ถ€๋ง์—์„œ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๊ฒŒ ์„ค์ •ํ•ด ๋†“์Šต๋‹ˆ๋‹ค.
์™ธ๋ถ€๋ง์—์„œ ์ ‘์† ๊ฐ€๋Šฅํ•˜๊ฒŒ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜ URL์„ ํด๋ฆญํ•˜์‹œ๋ฉด ์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์„ค๋ช…์„ ๋ณด๊ณ ์‹ถ์œผ์‹œ๋ฉด URL์„ ํด๋ฆญํ•ด ์ฃผ์„ธ์š”.

2.๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์—์„œ app.py ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๊ฒŒ๋˜๋ฉด ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด ์ž์ฒด์ ์œผ๋กœ ์›น์„œ๋ฒ„๋ฅผ ์—ด๊ฒŒ๋ฉ๋‹ˆ๋‹ค.
์—ด์–ด๋†“์€ ์›น์„œ๋ฒ„์— ์ ‘๊ทผ ์š”์ฒญ์ด ์˜ค๋ฉด ์š”์ฒญ์ž์—๊ฒŒ templates ํด๋”์†์˜ index.html์„ ๋„์›Œ์ค๋‹ˆ๋‹ค.
๋˜ํ•œ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด ์นด๋ฉ”๋ผ ๋ชจ๋“ˆ์ด ์ฐ๋Š” frame์„ index.html์— ๋„์›Œ์ค๋‹ˆ๋‹ค. ๊ณ„์†ํ•ด์„œ ์นด๋ฉ”๋ผ ๋ชจ๋“ˆ์—์„œ ์ฐ๋Š” ํ™”๋ฉด์„ index.html์— ๋„์›Œ์ฃผ๋Š”๊ฑธ ์œ ์ €๊ฐ€ ๋ด„์œผ๋กœ์จ ์ŠคํŠธ๋ฆฌ๋ฐ์ด ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.
์ด๋•Œ ์›น์— Access ์š”์ฒญ์ด ์˜ค๋ฉด ์ŠคํŠธ๋ฆฌ๋ฐ์ด ๋˜๋ฏ€๋กœ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์˜ ๋ถ€ํ•˜๋ฅผ ์ค„์—ฌ์ค๋‹ˆ๋‹ค.
์›น์˜ ์ ‘๊ทผ์€ ์•„๋ž˜์™€ ๊ฐ™์€ ์ฃผ์†Œ๋กœ ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค.

[๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด IP์ฃผ์†Œ]:5000

3.Android project์— ๋“ค์–ด๊ฐ€์„œ StreamingActivity.java๋ฅผ ์—ฝ๋‹ˆ๋‹ค.

browser = (WebView) findViewById(R.id.webview1);
browser.getSettings().setJavaScriptEnabled(true);
browser.loadUrl("http:/192.168.0.12:5000/");

์œ„ ๋ถ€๋ถ„์— IP Address๋ฅผ ์ž์‹ ์˜ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด IP Address๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
๋˜ํ•œ Login Activity์— ๋“ค์–ด๊ฐ€๋ฉด ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ์•„์ด๋’ค ์„ค์ •์„ ํ•  ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ๋ณธ๊ฐ’์œผ๋กœ id : "", pwd : "" ์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

4.์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ผœ๊ณ  ์ŠคํŠธ๋ฆฌ๋ฐ์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์—์„œ app.py๋ฅผ ์‹คํ–‰ํ•œ ์ƒํƒœ์—์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์Šค๋งˆํŠธํฐ์— ์„ค์น˜ํ•˜๊ณ  ์‹คํ–‰ํ•˜๊ฒŒ ์ŠคํŠธ๋ฆฌ๋ฐ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

5. Push Message๋ฅผ ์œ„ํ•œ ๊ฒฝ๋กœ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

์ž์‹ ์˜ ์„œ๋ฒ„์ฃผ์†Œ๋ฅผ urlopen์•ˆ์— ์žˆ๋Š” ์ฃผ์†Œ์— ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค. (94 line)

 urllib2.urlopen("http://pesang72.cafe24.com/push/GCMSender.php").read()

๊ทธ๋ฆฌ๊ณ  GCMSender.php ์•ˆ์—์„œ

$devices = array() 

()์•ˆ์— ์ž์‹ ์˜ ์•ˆ๋“œ๋กœ์ด๋“œ ํ† ํฐ๋ฒˆํ˜ธ๋ฅผ ๋„ฃ์–ด ๋†“์Šต๋‹ˆ๋‹ค.
์ž์‹ ์˜ ์„œ๋ฒ„์— GCMSender.php , GCMPushMessage.php ์„ ์—…๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.
์ด ์„ค์ •์„ ๋งˆ์น˜๋ฉด ์ง‘์•ž์—์„œ ์ˆ˜์ƒํ•œ ์‚ฌ๋žŒ์ด ๊ฐ์ง€๋˜๋ฉด ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ