Module1. DoorWatcher - GachonCapstoneDesign/DoorWatcher GitHub Wiki
Do Streaming for the scene taken by Raspberry Pi camera through Mobile application.
You can download the source code in github
- Github. hyper-link to github repository
Do streaming for the scene of the front door from Raspberry Pi camera on mobile application. Can watch the scene on real-time streaming.
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.
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.
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.
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
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:" "`
.
If you run app.py from Raspberry Pie and install the project on your smartphone and run it, you can stream it.
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.
๋ผ์ฆ๋ฒ ๋ฆฌํ์ด์ ์นด๋ฉ๋ผ๋ฅผ ์ด์ฉํด์ ์คํธ๋ฆฌ๋ฐํ๋ ์ฅ๋ฉด์ ์ค๋งํธํฐ์ผ๋ก ์คํธ๋ฆฌ๋ฐ ํฉ๋๋ค.
์ด ์ฝ๋๋ ํ์ฌ ๊นํ๋ธ์ ์ฌ๋ ค๋จ์ต๋๋ค.
- Github. ํ์ดํผ๋งํฌ๋ฅผ ํด๋ฆญํ์๋ฉด ๊นํ๋ธ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
๋ผ์ฆ๋ฒ ๋ฆฌํ์ด ์นด๋ฉ๋ผ๋ฅผ ํตํด์ ํ๊ด๋ฌธ ์์ ์ํฉ์ ์คํธ๋ฆฌ๋ฐ ํฉ๋๋ค. ์ค์๊ฐ์ผ๋ก ์คํธ๋ฆฌ๋ฐ ํ๋ ์ฅ๋ฉด์ ์ค๋งํธํฐ์ผ๋ก ์ง์ผ๋ณผ ์ ์์ต๋๋ค.
๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด ์นด๋ฉ๋ผ์์ ํ๊ด๋ฌธ์ ๋ณด๋ ๋์ค์ ์์ง์์ด ๊ฐ์ง๋๋ฉด ์นด์ดํธ๋ฅผ ์ธ๊ธฐ ์์ํฉ๋๋ค. ๊ณ์๋๋ ์์ง์์ ๋ณํ๊ฐ ์๊ณ ์ ํฌ๊ฐ ์ค์ ๋ก ์ ๋ง์ ํ ์คํธ๋ฅผ ๊ฑฐ์ณ์ ๊ฒฐ์ ํ ์นด์ดํธ๋ฅผ ๋์ด๊ฐ๋ฉด ์์ํ ์ฌ๋์ด๋ผ๊ณ ํ๋จํ๊ฒ ๋ฉ๋๋ค.
์์ํ ์ฌ๋์ด๋ผ๊ณ ํ๋จํ๊ฒ ๋๋ฉด ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด ์นด๋ฉ๋ผ์์ ์๋ฒ๋ก message๋ฅผ ๋ณด๋ ๋๋ค. ์ด๋ ์๋ฒ์์ ๋ฉ์์ง๋ฅผ ๋ฐ์ผ๋ฉด ์๋ฒ์ ๊ธฐ๋กํด๋์ ํ ํฐ๋ฒํธ๋ก ใ ใ PushMessage๋ฅผ ๋ณด๋ด๊ฒ ๋ฉ๋๋ค. ์ด๋ฅผ App์์ Broadcast ๋ก ์ก์๋ด์ด ์ ์ ์๊ฒ ํ์ ์ ๋์์ค๋๋ค.
์ธ๋ถ๋ง์์ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด์ ์ ๊ทผํ๊ธฐ์ํด์ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด์ ์ฐ๊ฒฐ๋ ์ธํฐ๋ท์ IP address๋ฅผ ์ธ๋ถ๋ง์์ ์ ์ํ ์ ์๊ฒ ์ค์ ํด ๋์ต๋๋ค.
์ธ๋ถ๋ง์์ ์ ์ ๊ฐ๋ฅํ๊ฒ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ์๋ URL์ ํด๋ฆญํ์๋ฉด ์์ธํ๊ฒ ์ค๋ช
๋์ด ์์ต๋๋ค.
- ์ค๋ช ์ ๋ณด๊ณ ์ถ์ผ์๋ฉด URL์ ํด๋ฆญํด ์ฃผ์ธ์.
์ด ํ์ผ์ ์คํํ๊ฒ๋๋ฉด ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด ์์ฒด์ ์ผ๋ก ์น์๋ฒ๋ฅผ ์ด๊ฒ๋ฉ๋๋ค.
์ด์ด๋์ ์น์๋ฒ์ ์ ๊ทผ ์์ฒญ์ด ์ค๋ฉด ์์ฒญ์์๊ฒ templates ํด๋์์ index.html์ ๋์์ค๋๋ค.
๋ํ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด ์นด๋ฉ๋ผ ๋ชจ๋์ด ์ฐ๋ frame์ index.html์ ๋์์ค๋๋ค.
๊ณ์ํด์ ์นด๋ฉ๋ผ ๋ชจ๋์์ ์ฐ๋ ํ๋ฉด์ index.html์ ๋์์ฃผ๋๊ฑธ ์ ์ ๊ฐ ๋ด์ผ๋ก์จ ์คํธ๋ฆฌ๋ฐ์ด ์ด๋ฃจ์ด์ง๋๋ค.
์ด๋ ์น์ Access ์์ฒญ์ด ์ค๋ฉด ์คํธ๋ฆฌ๋ฐ์ด ๋๋ฏ๋ก ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด์ ๋ถํ๋ฅผ ์ค์ฌ์ค๋๋ค.
์น์ ์ ๊ทผ์ ์๋์ ๊ฐ์ ์ฃผ์๋ก ์ ๊ทผํฉ๋๋ค.
[๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด IP์ฃผ์]:5000
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 : ""
์ผ๋ก ์ค์ ๋์ด ์์ต๋๋ค.
๋ผ์ฆ๋ฒ ๋ฆฌํ์ด์์ app.py๋ฅผ ์คํํ ์ํ์์ ํ๋ก์ ํธ๋ฅผ ์ค๋งํธํฐ์ ์ค์นํ๊ณ ์คํํ๊ฒ ์คํธ๋ฆฌ๋ฐ์ด ๊ฐ๋ฅํฉ๋๋ค.
์์ ์ ์๋ฒ์ฃผ์๋ฅผ urlopen์์ ์๋ ์ฃผ์์ ๋์ฒดํฉ๋๋ค. (94 line)
urllib2.urlopen("http://pesang72.cafe24.com/push/GCMSender.php").read()
๊ทธ๋ฆฌ๊ณ GCMSender.php ์์์
$devices = array()
()์์ ์์ ์ ์๋๋ก์ด๋ ํ ํฐ๋ฒํธ๋ฅผ ๋ฃ์ด ๋์ต๋๋ค.
์์ ์ ์๋ฒ์ GCMSender.php , GCMPushMessage.php ์ ์
๋ก๋ ํฉ๋๋ค.
์ด ์ค์ ์ ๋ง์น๋ฉด ์ง์์์ ์์ํ ์ฌ๋์ด ๊ฐ์ง๋๋ฉด ๋ฉ์์ง๋ฅผ ๋ฐ๊ฒ ๋ฉ๋๋ค.