Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Submitted By
Sagar Kumar & Marsha Nawal
2019
Smart Surveillance System for Parked Cars
By
Sagar Kumar and Marsha Nawal
February 2019
Signature of Author
Certified by:
Accepted by:
Dr. Ahmed Waqas
Head,
Department of Computer Science
EXORDIUM
First of all, we would like to thanks Allah Almighty for giving us this opportunity to
complete this project and thesis. We are indebted to many people for their help and
guidance throughout this project.
We would like to give bundle of thanks to our beloved supervisor, Dr. Abdul
Rehman Gilal who has always supported us with ideas, suggestions and identifying
problems and their subsequent solutions.
iii
DEDICATION
We are especially thankful to our parents whose prayers, love and support have
always been a constant source of strength for us. We also thankful to our teachers,
who gave the knowledge, support and inspire us in all aspects.
iv
Table of Contents
EXORDIUM ........................................................................................................................................... iii
DEDICATION ........................................................................................................................................ iv
LIST OF FIGURES ............................................................................................................................... viii
LIST OF TABLES .................................................................................................................................. ix
ACRONYMS AND ABBRIVIATIONS .................................................................................................. x
ABSTRACT ............................................................................................................................................ xi
CHAPTER 1............................................................................................................................................. 1
INTRODUCTION .................................................................................................................................... 1
1.1. Overview ..................................................................................................................................... 1
1.2. Background ................................................................................................................................. 1
1.3. Introduction ................................................................................................................................. 1
1.4. Problem Statement ...................................................................................................................... 2
1.5. Research Question ....................................................................................................................... 2
1.6. Scope Of FYP Report .................................................................................................................. 2
1.7. Chapter Summary........................................................................................................................ 3
CHAPTER 2............................................................................................................................................. 4
METHODOLOGY ................................................................................................................................... 4
2.1. Overview ..................................................................................................................................... 4
2.2. Study Design ............................................................................................................................... 4
2.1.1. Product Design Phases ............................................................................................................ 4
2.3. Agile Methodology ..................................................................................................................... 4
2.3.1. Design ..................................................................................................................................... 5
2.3.1.2 Tools and Techniques ......................................................................................................... 5
2.3.1.3 Procedure ............................................................................................................................ 5
2.3.2. Development ........................................................................................................................... 5
2.3.2.1. Prototype Development ...................................................................................................... 5
2.3.2.2. Mobile Application ............................................................................................................. 6
2.3.2.3 Language/Editor ................................................................................................................. 7
2.3.3. Testing/ Inspection .................................................................................................................. 7
2.3.4.1. Functional Testing Types ................................................................................................... 7
2.3.4.2. Unit Testing ........................................................................................................................ 7
2.3.4.3. Integration Testing.............................................................................................................. 7
2.3.4.4. System Testing ................................................................................................................... 7
2.3.4.5. Interface Testing ................................................................................................................. 8
2.3.4.1. Non-Functional Testing Types ........................................................................................... 8
2.3.4.2. Performance Testing ........................................................................................................... 8
2.3.4.3. Security Testing .................................................................................................................. 8
2.3.4.4. Compatibility Testing ......................................................................................................... 8
2.4. Chapter Summary........................................................................................................................ 8
CHAPTER 3........................................................................................................................................... 10
SOFTWARE REQUIREMENT SPECIFICATIONS (SRS) .................................................................. 10
v
3.1. Introduction ............................................................................................................................... 10
3.1.1. Purpose ................................................................................................................................. 10
3.1.2. Document Conventions ......................................................................................................... 10
3.1.3. Intended Audience and Reading Suggestions ....................................................................... 10
3.1.4. Product Scope ....................................................................................................................... 10
3.1.5. References............................................................................................................................. 10
3.2. Overall System Description/Functional Requirements ............................................................. 11
3.2.1. Prototype Perspective ........................................................................................................... 11
3.2.2. Prototype Functions .............................................................................................................. 11
3.2.3. Application Functions ........................................................................................................... 12
3.2.4. User Classes and Characteristics........................................................................................... 12
3.2.5. Operating Environment ......................................................................................................... 12
3.2.6. Design and Implementation Constraints ............................................................................... 12
3.2.7. Assumptions and Dependencies............................................................................................ 12
3.3. External Interface Requirements ............................................................................................... 13
3.3.1. Hardware Interfaces .............................................................................................................. 13
3.3.2. Software Interfaces ............................................................................................................... 13
3.3.3. Communications Interfaces .................................................................................................. 13
3.4. Prototype Features ..................................................................................................................... 13
3.4.1. Identifying an object ............................................................................................................. 13
3.4.2. Notification ........................................................................................................................... 13
3.4.3. Record ................................................................................................................................... 13
3.5. Other Non-Functional Requirements ........................................................................................ 14
3.5.1. Performance Requirements ................................................................................................... 14
3.5.2. Security Requirements .......................................................................................................... 14
CHAPTER 4........................................................................................................................................... 15
SYSTEM DESIGN SPECIFICATION (SDS) ....................................................................................... 15
4.1. Purpose Of This Document ....................................................................................................... 15
4.2. Scope Of The Development Project .......................................................................................... 15
4.3. Definitions, And Acronyms ...................................................................................................... 15
4.4. Assumptions .............................................................................................................................. 15
4.5. Constraints ................................................................................................................................ 15
4.6. Architecture ............................................................................................................................... 16
4.7. Overview ................................................................................................................................... 16
4.8. Detailed Software Design .......................................................................................................... 17
4.9. Domain Model .......................................................................................................................... 18
4.10. Use Case Diagrams ................................................................................................................... 19
4.11. Sequence Diagrams ................................................................................................................... 20
4.12. System Sequence Diagram ........................................................................................................ 22
4.13. Activity Diagram ....................................................................................................................... 22
4.16.2 Deployment Diagram ............................................................................................................ 25
CHAPTER 5........................................................................................................................................... 26
vi
RESULTS .............................................................................................................................................. 26
5.1. INTRODUCTION..................................................................................................................... 26
5.2. RESULTS ................................................................................................................................. 26
5.3. Screenshots ................................................................................................................................ 29
CHAPTER 6........................................................................................................................................... 34
CONCLUSION AND FUTURE WORK ............................................................................................... 34
BIBLIOGRAPHY/REFERENCE .......................................................................................................... 35
APPENDIX ............................................................................................................................................ 36
Application Code.................................................................................................................................... 36
Prototype Code ....................................................................................................................................... 46
vii
LIST OF FIGURES
viii
LIST OF TABLES
ix
ACRONYMS AND ABBRIVIATIONS
Hz: Hertz
x
ABSTRACT
xi
CHAPTER 1
INTRODUCTION
1.1. Overview
In this chapter, we will describe the project background, problems and scope of
the overall system. The study is being undertaken because to bring the
technological solution and implementation of modern sensory technology in the
system that may reduce the human efforts. Smart Surveillance System for parked
cars (3SPC) is a system with sensory technology which notifies the owner of the
parked car, when his/her car is hit with another object. This study is carried out to
use the resources very efficiently to save the storage capacity and cost of
surveillance systems that are implemented in different places.
1.2. Background
The industrial growth of the world is reflected by the increase in the number of
automobiles on the streets throughout the world, which has caused a lot of parking
related problems. The slow paced city planning has increased the problem even
more. The current unmanaged car parks and transportation facilities have made it
difficult to accommodate the increasing number of vehicles in a proper,
convenient manner so it is necessary to have a secure, intelligent, reliable and
efficient system especially in Pakistan.
Human errors are the major source of traffic accidents, therefore building in-car
technologies for checking the parking lot, avoiding accidents and guidance to the
parking facility is turning out to be an integral area for research. Currently used
parking system is not an efficient one; as the drivers are allowed to park without
any restriction, which cause damage to others cars.
1.3. Introduction
It is very common to have crowds in place like mega shopping malls, and
stadiums during peak periods. In shopping malls, discounts and season sales
offered by merchants can attract thousands of customers of to come during the
sales periods. Most of the customers travel to the shopping malls with their own
vehicles and it is not surprising to see the car parks are always full during this
periods. In addition, sometimes, when a driver parks his car in an uncontrolled
area or a tiny spot, there is a risk that the vehicle gets scratched or damaged
without that the driver gets notified. Therefore, modern parking systems for
meeting driver parking needs are required. Using modern electronic technologies,
smart oriented assistance parking, and wireless connections in the vehicle help
improving the driver parking skills and reduce the risk for car damages.
3SPC is an innovative system which notify the owner of the car, when his/her car
hits with another object. The system will be integrated in to car. This System uses
the automated sensory technology. The 3SPC provide its user a portable
1
accessibility at every place. If an incident occurs the 3SPC generates a
notification and send to user with proof of video of incident that will be
generated by system via email.
A hardware device is integrated in car with sensors (shock, vibration) and mobile
application is installed on the user smart phone, through which he can switch
on/off the System. When an event occurs the 3SPC will turn on the camera and
start recording the current situation and recorded video will be send to the owner
of car using Wi-Fi connection. The SMS alert will be provided by system using
WhatsApp in which user can be notified at runtime when an incident occurs.
With the high percentage of vehicle ownership, car monitoring in a parking has
become a confusing situation for a number of people at uncontrolled zone.
Whether at an airport, bus station and shopping centers, problems with parking
are an everyday occurrence. Lack of accessible parking may cause several
accidents while parking in a tiny area. It may causes damage to your vehicle.
Q1: How to develop a Smart Surveillance System for Parked Cars (3SPC)?
Answer: For the development of Smart Surveillance System for Parked Cars
(3SPC) we have surpass three phases that are enlisted below:
1. Designing
2. Development
3. Testing/Validating
In designing phase we had designed the system sketches on paper and then use
some tools to model it. That designed model shows the working of the system.
Then we started the development of project, the development is divided into two
phases:
1. Mobile Application Development
2. Prototype Development
These both above phases are explained in detailed in Chapter 2.
At the last we tested system and then validate from different users such as car
drivers of Sukkur IBA University, students and other officials.
2
1.7. Chapter Summary
3
CHAPTER 2
METHODOLOGY
2.1. Overview
In this chapter, we will discuss the design, workflow and methodologies relevant
to the 3SPC. It investigates the approaches, procedures, concepts, theories and
techniques relevant to this project. Some of the questions are briefly explained in
this chapter:
What methods or life cycle is used while development of system?
What testing techniques are applied when system has been developed?
What tools and techniques are used, in designing of the system?
2.3.1. Design
2.3.1.3 Procedure
2.3.2. Development
2. Login
Login activity or page will be used for the authentication
of user. User may enter the username and password which
was given in the time of registration.
3. Switch On/Off
Switch On/Off activity contains two buttons.
1. On: The On button starts the prototype.
2. Off: The Off button starts the prototype.
Each button performs its functionality independently.
6
4. View Video
This activity shows the list of available videos that are
available in database provided by system or prototype.
2.3.2.3 Language/Editor
7
2.3.4.5. Interface Testing
2.4.Chapter Summary
9
CHAPTER 3
3.1. Introduction
3.1.1. Purpose
3.1.5. References
10
Yassine Salih Alj School of Science and Engineering Al
Akhawayn University, Ifrane Morocco Published in 2013
The main function that the prototype will perform that are given
below:
1. Prototype can be On/Off remotely by provided mobile application.
2. Prototype can record video of incident smartly if the given
programming conditions are satisfied.
3. Prototype can send email with attachment of video, if an incident
occurs.
4. Prototype can also send whatsApp notification to registered
mobile number, if an incident occurs.
11
3.2.3. Application Functions
The major function that the application will perform that are given
below:
1. Allow user to create an account.
2. Allow authenticate user to login.
3. Allow user to switch on/off the prototype.
4. Allow user to check the incidental videos that the prototype
recorded.
1. System Constraints
i. Software Constraints
Application can only run on Android Mobile
Phone.
ii. Hardware Constraints
Just Create Prototype
Internet Availability
iii. User Constraints
Project is developed for car owners.
1. Twilio API
i. For Sending Text Messages via WhatsApp.
2. MIME Packages such as SMTP
i. For sending email with attachment using Gmail.
3. Http URL Connection
i. For connecting mobile application with given URL, it
get the required data such user information for login
and the list of videos in JSON format and then convert
into string.
12
3.3. External Interface Requirements
The prototype can identify the object when it come closure to the car
with the help of integrated sensors in it.
3.4.2. Notification
3.4.3. Record
The prototype will start recording if the integrated sensors send signal
and it will send to the user via email as well as on application if an
object hit to the car.
13
3.5. Other Non-Functional Requirements
The performance requirement of this system is that the sensors get the
input accurately in small amount of time.
14
CHAPTER 4
The scope of this project is to provide the prototype and Mobile application that
can be installed and run on owner android based smart phone. It can be further
proceed by making the system implemented in the real car.
4.4. Assumptions
A1. It is assumed that the user of application have sufficient knowledge about
smart surveillance system for parked car.
4.5. Constraints
1. Platform
2. Operating System
a. C2. Application is compatible with android API level greater than 21.
15
4.6.Architecture
4.7.Overview
4. Database: MySQLi will be used to save the data of owner into server, and
it is also used as bridge for accessing video from raspberry pi to user
smart phone.
16
4.8.Detailed Software Design
17
4.9.Domain Model
18
4.10. Use Case Diagrams
Name System
Post-Condition N-A
19
4.11. Sequence Diagrams
20
4.12.3 Sequence Diagram for View Videos
21
4.12. System Sequence Diagram
22
4.14.2 Activity Diagram for System On/Off
23
4.14.4 Activity Diagram for View Video
Figure 4.14
24
4.16.2 Deployment Diagram
Figure 4.15
25
CHAPTER 5
RESULTS
5.1. INTRODUCTION
The Systems user interface is quite simple and designed under the consideration
of Human Computer Interaction Principles which can be used almost in all
physical condition, the interface will remain same and does not harm user
physically (such as eye-fatigue) or mentally.
5.2. RESULTS
26
From the above diagram it is shown that the first thing which we require
is the internet for connecting application with the LAMP server. Note
here that we need internet connection for connecting both, application
and 3SPC prototype.
For getting data from LAMP server we have use HttpURLConnection for
reading the data from web URL and get data in JSON format and process
result data String JSON to object JSON.
27
1. We run this system directly by using the python scripts and also
execute the python script using PHP because of connectivity
with mobile phone.
a. Ultrasonic Sensor: Initially ultrasonic sensor was
working with its default range of approximately 13 feet,
frequency is 40 Hz, Trigger input signal is 10µs TTL
Pulse. Sometime it shows the value in negative integers
because when it does not get any object. It will assign
the negative value. To get rid from it we use some logic
in code or program when it does not get any value, so it
will by default 0. And the range we have cover is
maximum 5 inches or 13 cm (for prototype). Now it is
working fine and provide the expected results.
b. Camera: Camera is the most important component of
prototype. It is also controlled by using code. We used
raspberry pi camera with 5 megapixel of resolution.
We put it on the several direction of prototype and got
the expected angles result. When it is implemented
first time system installer should enable the camera
option from configure file, so user can get the desired
results when his/her car will hit by another object.
c. Shock Sensor: After camera the shock sensor is
another most important component in 3SPC, all of the
notification system is dependent on it. It works
properly, but sometimes it create issue while sending
email and text message because of network issue, so it
transfer the data into queue. It may take approximately
45 to 80 seconds to transferring it on queue.
28
5.3. Screenshots
1. Login Screen: This page of our application allow user to login and also
signup if user is new and want to create an account. It checks the valid input
types and text format.
29
2. Signup Screen: This screen help user to create an account by providing valid
input by user and this information is stored in database when user clicks the
Register button.
30
3. Homepage Screen: This Screen displays the main screen after login in which
user can On/Off the System.
31
4. Menu Screen: This Menu Screen displays the Menu in which these options
are given:
a. In menu header the image of person would by shown which owner
has been uploaded.
b. In Home icon, Homepage will be show to the user.
c. In system on/off icon, two buttons will be shown which will help user
to on/off the system.
d. In videos icon, List of videos will be show to the user which will be
helpful to user to recognize who hits his car.
e. In Logout icon, User will be in login page.
32
5. Video Screen: This Video Screen shows the list of videos that are recorded
by system while an incident occurs.
33
CHAPTER 6
6.1. CONCLUSION
Today, as there are different Surveillance Systems that allow the owner of
vehicle to keep check and balance of their cars like camera’s placed on all four
direction of car and many more.
But still all these systems have loop holes, our system tends to fulfill these loop
holes by using Android application and real-time video streaming mechanism.
This system will provide notification by email and WhatsApp by sending video
as a proof to owner of car. Owner will just need to connect his/her system with
internet. A gallery (keep videos’ of all incident occur) can be viewed by the
owner of car if he/she was unable to check email.
34
BIBLIOGRAPHY/REFERENCE
Intelligent Parking System for Car Parking Guidance and Damage Notification, by
Sanaa Alfatihi, Soukaina Chihab and Yassine Salih Alj School of Science and
Engineering Al Akhawayn University, Ifrane Morocco Published in 2013
Kranig, J., E. Minge, and C. Jones. Field Testing of Urban Vehicle Operations
Using Non-Intrusive Technologies. Report FHWA-PL-97-018. Minnesota
Department of Transportation, St. Paul, Minn., 1997.
Surround surveillance system for mobile body, and mobile body, car, and train
using the same by Kiyoshi Kumata,Toru Shigeta.
35
APPENDIX
Application Code
1. Login:
package com.example.marshanawal.appdesign1;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
EditText txtEmail;
EditText txtPassword;
Button btnLogin;
Button btnSignup;
static String[] userEmail;
static String[] userPassword;
static String[] userName;
String getUsername ="";
String emailValue;
String passwordValue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("LogIn");
txtEmail = (EditText) findViewById(R.id.txtEmail);
txtPassword = (EditText) findViewById(R.id.txtPassword);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnSignup = (Button) findViewById(R.id.btnSignUp);
if(!new PreferenceManager(this).isUserLogout())
{
getUsername = new PreferenceManager(this).getUsername();
StartHomePageActivity(getUsername);
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
// Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
getDataFromURL(s);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(urlWebService);
String json;
return stringBuilder.toString().trim();
} catch (Exception e) {
37
return null;
}
}
}
GetJSON getJSON = new GetJSON();
getJSON.execute();
}
38
}
}
2. Signup
package com.example.marshanawal.appdesign1;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.kosalgeek.asynctask.AsyncResponse;
import com.kosalgeek.asynctask.PostResponseAsyncTask;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
EditText txtName;
EditText txtPassword;
EditText txtConfirmPassword;
EditText txtEmailReceiver;
EditText txtModelNo;
EditText txtMobileNo;
Button btnRegister;
String nameValue;
String passwordValue;
String confirmPassValue;
String modelNoValue;
String mobileNoValue;
String emailValue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
setTitle("SignUp");
txtName = (EditText) findViewById(R.id.txtUserName);
txtPassword = (EditText) findViewById(R.id.txtPassword);
txtConfirmPassword = (EditText) findViewById(R.id.txtReTypePassword);
txtMobileNo = (EditText) findViewById(R.id.txtContactNo);
txtEmailReceiver = (EditText) findViewById(R.id.txtEmail);
txtModelNo = (EditText) findViewById(R.id.txtModelNumber);
btnRegister = (Button) findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
nameValue = txtName.getText().toString();
modelNoValue = txtModelNo.getText().toString();
39
mobileNoValue= txtMobileNo.getText().toString();
passwordValue = txtPassword.getText().toString();
confirmPassValue = txtConfirmPassword.getText().toString();
emailValue = txtEmailReceiver.getText().toString();
40
e.printStackTrace();
}
}
@Override
public void processFinish(String s) {
emptyField();
Intent intent = new Intent(this, LogInPage.class);
startActivity(intent);
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.kosalgeek.asynctask.AsyncResponse;
import com.kosalgeek.asynctask.PostResponseAsyncTask;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
String status;
Button btnOn;
Button btnOff;
Context context;
public SystemOnOff() {
41
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_system_on_off, container, false);
status = "";
context = container.getContext();
btnOn = (Button)view.findViewById(R.id.btnOn);
btnOff = (Button)view.findViewById(R.id.btnOff);
btnOn.setOnClickListener(listener);
btnOff.setOnClickListener(listener);
return view;
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
}
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
// Toast.makeText(getActivity().getApplicationContext(), "inside click",
Toast.LENGTH_LONG).show();
if (view.equals(btnOn))
{
status = "On";
Toast.makeText(getActivity().getApplicationContext(), status,
Toast.LENGTH_LONG).show();
actionOnSystem(status);
}
else if(view.equals(btnOff))
{
status = "Off";
Toast.makeText(getActivity().getApplicationContext(), status,
Toast.LENGTH_LONG).show();
actionOnSystem(status);
}
}
};
42
PostResponseAsyncTask(this, hashMap);
PostResponseAsyncTask postResponseAsyncTask = new
PostResponseAsyncTask(context, hashMap, new AsyncResponse() {
@Override
public void processFinish(String s) {
Toast.makeText(getActivity().getApplicationContext(), "Success",
Toast.LENGTH_SHORT ).show();
}
});
postResponseAsyncTask.execute("http://192.168.43.188/systemOnOff.php");
}
catch (ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
}
}
@Override
public void processFinish(String s) {
Toast.makeText(getActivity().getApplicationContext(), "Success 2",
Toast.LENGTH_SHORT ).show();
}
}
4. ListOfVideos
package com.example.marshanawal.appdesign1;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.app.Fragment;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
ListView listView;
VideoView videoView;
ArrayAdapter arrayAdapter;
String path;
43
public ListOfVideo() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setTitle("List Of Videos");
/// listView = (ListView)getView().findViewById(R.id.lstVideos);
// videoView = (VideoView)getView().findViewById(R.id.videosView);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_list_of_video, container, false);
// Inflate the layout for this fragment
listView = (ListView)view.findViewById(R.id.lstVideos);
videoView = (VideoView)view.findViewById(R.id.videosView);
path ="http://192.168.43.81/listOfVideo.php/";
getJSON(path);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
{
String name = (String) adapterView.getItemAtPosition(i);
String videoName = name.split(",")[0];
String videopath = "http://192.168.43.188/Video/"+videoName;
Toast.makeText(getActivity().getApplicationContext(), videopath,
Toast.LENGTH_LONG).show();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
videoView.requestFocus();
videoView.start();
}
});
videoView.setVideoURI(Uri.parse(videopath));
}
});
return view;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
44
super.onPostExecute(s);
Toast.makeText(getActivity().getApplicationContext(), s,
Toast.LENGTH_SHORT).show();
try {
loadIntoListView(s);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(urlWebService);
String json;
return stringBuilder.toString().trim();
} catch (Exception e) {
return null;
}
}
}
GetJSON getJSON = new GetJSON();
getJSON.execute();
}
listView.setAdapter(arrayAdapter);
}
}
45
Prototype Code
except KeyboardInterrupt:
p.stop()
p2.stop()
GPIO.cleanup()
def motor2(self):
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.servo2, GPIO.OUT)
p = GPIO.PWM(self.servo2, 45) # GPIO 17 for PWM with 50Hz
p.start(2.5) # Initialization
try:
while True:
p.ChangeDutyCycle(7)
time.sleep(0.5)
p.ChangeDutyCycle(2.5)
time.sleep(0.5)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()
GPIO.setwarnings(False)
46
def __init__(self , servo1, servo2,trig1,echo1,trig2,echo2,channel,led):
self.servo1=servo1
self.servo2= servo2
self.trig1 = trig1
self.echo1 = echo1
self.trig2 = trig2
self.echo2 = echo2
self.channel = channel
self.led = led
GPIO.add_event_detect(self.channel,GPIO.FALLING,callback=self.active,bouncetime=300)
GPIO.output(self.trig1, False)
time.sleep(0.1)
GPIO.output(self.trig1, True)
time.sleep(0.1)
GPIO.output(self.trig1, False)
while GPIO.input(self.echo1)==0:
pulse_start = time.time()
while GPIO.input(self.echo1)==1:
pulse_end = time.time()
47
pulse_duration = pulse_end - pulse_start
distance = round(distance, 2)
distance = (distance*0.394)
if(distance<=5):
# print('Sensor_1 {} \n'.format(distance))
list1.append(math.floor(distance))
t1 = time.time()
t2 = t1-t0
if t2 >1:
set_a=set(list1)
for i in set_a:
dictionary[i] = list1.count(i)
maximum = max(dictionary,key = dictionary.get)
new_previous.append(maximum)
print(new_previous)
if(len(new_previous) > 1):
if((new_previous[len(new_previous)-1] > new_previous[len(new_previous)-2]) or
(new_previous[len(new_previous)-1] == new_previous[len(new_previous)-2])):
if (flag2 is True):
# with picamera.PiCamera() as camera:
# camera.stop_recording()
print("Stop Recording")
del list1[:]
del new_previous[:]
flag = True
flag2 = False
elif(new_previous[len(new_previous)-1] < new_previous[len(new_previous)-2]):
flag = True
if(flag is True):
print("Start Recording")
currentDT = datetime.datetime.now()
with picamera.PiCamera() as camera:
camera.start_recording(str(currentDT.year)+'_'+str(currentDT.month)+'_'+str(currentDT.day)+'_'+str(
currentDT.hour)+'_'+str(currentDT.minute)+'_'+str(currentDT.second)+'.h264')
sleep(5)
camera.stop_recording()
del list1[:]
flag2 = True
flag = False
del new_previous[:]
else:
if(flag is True):
print("Recording Start")
currentDT = datetime.datetime.now()
with picamera.PiCamera() as camera:
camera.start_recording(str(currentDT.year)+'_'+str(currentDT.month)+'_'+str(currentDT.day)+'_'+str(
currentDT.hour)+'_'+str(currentDT.minute)+'_'+str(currentDT.second)+'.h264')
sleep(5)
camera.stop_recording()
flag = False
flag2 = True
48
del list1[:]
del new_previous[:]
dictionary.clear()
del list1[:]
set_a.clear()
t0 = time.time()
t1=0.0
GPIO.setmode(GPIO.BCM)
while True:
GPIO.setup(self.trig2,GPIO.OUT)
GPIO.setup(self.echo2,GPIO.IN)
GPIO.output(self.trig2, False)
time.sleep(0.1)
GPIO.output(self.trig2, True)
time.sleep(0.1)
GPIO.output(self.trig2, False)
while GPIO.input(self.echo2)==0:
pulse_start = time.time()
while GPIO.input(self.echo2)==1:
pulse_end = time.time()
distance = round(distance, 2)
distance = (distance*0.394)
if(distance<=5):
# print('Sensor_2 {} \n'.format(distance))
list1.append(math.floor(distance))
t1 = time.time()
t2 = t1-t0
if t2 >1:
set_a=set(list1)
for i in set_a:
dictionary[i] = list1.count(i)
maximum = max(dictionary,key = dictionary.get)
new_previous.append(maximum)
print(new_previous)
if(len(new_previous) > 1):
49
if((new_previous[len(new_previous)-1] > new_previous[len(new_previous)-2]) or
(new_previous[len(new_previous)-1] == new_previous[len(new_previous)-2])):
if (flag2 is True):
# with picamera.PiCamera() as camera:
# camera.stop_recording()
print("Stop Recording")
flag = True
flag2 = False
del list1[:]
del new_previous[:]
else:
if(flag is True):
# with picamera.PiCamera() as camera:
# camera.start_recording('/var/www/html/Video/pythonVideo.h264')
print("Recording Start")
# sleep(5)
flag = False
flag2 = True
del list1[:]
del new_previous[:]
dictionary.clear()
del list1[:]
set_a.clear()
t0 = time.time()
t1=0.0
absolute_path=os.path.dirname(os.path.abspath(__file__))
files = glob.glob('/var/www/html/Video/*.*')
50
currentTime = datetime.datetime.now()
currenttime= ' '
if currentTime.hour <12:
currenttime='Good Morning.'
elif 12<= currentTime.hour <18:
currenttime='Good afternoon.'
else:
currenttime='Good evening.'
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(owneremail,'jamesjohn1233')
#server.sendmail('from','to',message)
server.sendmail(owneremail,owneremail,text)
server.quit()
print('connection successfully')
connection.close()
def Converter(self):
absolute_path=os.path.dirname(os.path.abspath(__file__))
files = glob.glob('*.h264')
latestfile = max(files,key=os.path.getctime)
convertablevideo = latestfile.split('.',1)
converter = os.system('ffmpeg -i ' +latestfile+ ' -codec copy Video/'+convertablevideo[0]+'.mp4')
def InsertVideo(self):
currentDT = datetime.datetime.now()
video_date = currentDT.strftime('%Y/%m/%d')
absolute_path=os.path.dirname(os.path.abspath(__file__))
files = glob.glob('*.h264')
latestfile = max(files,key=os.path.getctime)
convertablevideo = latestfile.split('.',1)
video_name = convertablevideo[0]+'.mp4'
connection = pymysql.connect(host="localhost",
user="pi",
passwd="alpha",
database="fyp",
charset='utf8mb4',
51
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = 'INSERT INTO video_information (Video_Name,Video_Date) VALUES (%s,%s)'
cursor.execute(sql,(video_name,video_date))
# print('insert')
connection.commit()
finally:
connection.close()
def WhatsAppNotification(self):
accountsid =''
accounttoken =''
whatsappnumber=''
TWILIO_NUMBER = 'whatsapp:+14155238886'
connection = pymysql.connect(host="localhost",
user="pi",
passwd="alpha",
database="fyp",
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = 'select Account_SID,Account_Token,Whatsapp_Number from whatsapp_info'
cursor.execute(sql)
result = cursor.fetchone()
accountsid = result['Account_SID']
accounttoken = result['Account_Token']
whatsappnumber = result['Whatsapp_Number']
finally:
connection.close()
TWILIO_MESSAGE_ENDPOINT = 'https://api.twilio.com/2010-04-
01/Accounts/{TWILIO_SID}/Messages.json'.format(TWILIO_SID=accountsid)
message_data = {
"To": 'whatsapp:'+whatsappnumber,
"From":TWILIO_NUMBER,
"Body":"Dear result[‘owner_Name’], This is a Dent Alert From 3SPC"
}
response = requests.post(TWILIO_MESSAGE_ENDPOINT, data=message_data,
auth=(accountsid, accounttoken))
response_json = response.json()
# print(response_json)
# servo1, servo2,trig1,echo1,trig2,echo2,vibsensor
project = SSSPC(17,18,7,8,16,21,26,19)
thread1= threading.Thread(target = project.motor1, name='motor1_Thread', args=[])
thread2= threading.Thread(target = project.motor2,name='motor2_Thread', args=[])
thread3 = threading.Thread(target = project.ping1,name='ultrasonic1_Thread', args=[])
thread4 = threading.Thread(target = project.ping2,name='ultrasonic2_Thread', args=[])
thread5 = threading.Thread(target = project.vib_Sensor,name='vibration_detector_sensor_Thread',
args=[])
thread1.start()
#thread2.start()
thread3.start()
#thread4.start()
thread5.start()
52