You are on page 1of 25

CS595

C
Monday 12.15pm

Computer Science Capstone Course



Northwestern Polytechnic University, Fremont, CA 94539

FINAL Report

SPRING 2017

Prof. Ahmed Banafa

SMART SAFETY GRID ASSITANT USING DROIDS/DRONES



04/19/2017

Team Members:

Sneha Uike 16634
Susmita Subedi 15954
Sailakshmi Chimata 17284
Shaik Faizan 15910
Mohammed A. Adeeb 16610





1
Abstract

In developing countries with high crime rates per capita, personal safety especially for children
and women is a serious problem. The lack of 911 like all comprehensive helpline, inadequate
and inefficient police patrolling coverage, high population density, lack of stationary
infrastructure of CCTV cameras or manpower to execute it are some of the reasons the
ensuring of public safety is a big problem. This project aims to solve that problem using next
ubiquitous technology that drones are. It ensures safety by assigning the devices and tracking
the activity.

2
Introduction


This project is divided into four scenarios. User, Android App, Server and Hardware.

User: Who wants to assist Droid/Drone.

App: Register User details, get current location details and provide Droid/Drone details.

Server: checks Droid/Drone available to nearby user location.

Hardware: An Android product which will assist user.

User who wants to ensure safety register to the app and request for Droid/Drone for assistant.
The assisted droid follows the user using WIFI/BLUETOOTH link. If user meets any uncalled
situation, stress call facility is provided which tells Droid/Drone to get alert. Droid/Drone start
alarming nearby passerby using siren and contacts to the police services.

3
Block Diagram


4
Flow Diagram

5
User Side Coding Structure

Registration Page


This page is about Registration. A Sign-up form ask user to input the details, checks for
validations and save the details in database.

Field Names:

name = (EditText)findViewById(R.id.etName);

phoneNo = (EditText)findViewById(R.id.etPhone);emailId =
(EditText)findViewById(R.id.etFEmailId);password =
(EditText)findViewById(R.id.etFPassword); confrimPassword =
(EditText)findViewById(R.id.etFConfrimPassword); register = (Button)
findViewById(R.id.btRegister);

//Validations:

if(name.length() == 0){ name.requestFocus(); name.setError("Field cannot be empty");

}else if(!isValidEmail(emailIdValue)){ emailId.requestFocus(); emailId.setError("Invalid Emai


ID");

}else if(password.length() == 0){ password.requestFocus(); password.setError("Field cannot be


empty");

}else if(!confrimPassValue.equals(passwordValue)){ confrimPassword.requestFocus();


confrimPassword.setError("Confrim password is not same");

}else{//insert data
register(nameValue,phoneNoValue,emailIdValue,passwordValue,confrimPassValue);

//check for correct syntax of email id

private boolean isValidEmail(String email) {String EMAIL_PATTERN = "^[_A-Za-z0-9-


\\+]+(\\.[_A-Za-z0-9-]+)*@"

+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; Pattern pattern =


Pattern.compile(EMAIL_PATTERN); Matcher matcher = pattern.matcher(email);return
matcher.matches();

6
Login Page


This page asks user to login with registered details, check the input from database and logins.

Field Names:

emailId = (EditText) findViewById(R.id.etFEmailId);

password = (EditText) findViewById(R.id.etFPassword); forgotPassword = (TextView)


findViewById(R.id.tvForgot); signIn = (Button) findViewById(R.id.btSignIn);signUp =
(Button) findViewById(R.id.btSignUp);

Validations:

/*on click goes to location activity * check login details* check validations*/

signIn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {String usernameValue = emailId.getText().toString(); String


passwordValue = password.getText().toString(); login(usernameValue, passwordValue);

} });

/*button sign up * on click go to register activity*/

signUp.setOnClickListener(new View.OnClickListener() { @Overridepublic void


onClick(View v) {

//Intent - takes us to the requested activity. Here register is the requested activity

Intent registerIntent = new Intent(MainActivity.this, RegisterActivity.class);

startActivity(registerIntent); }

});

//forgot password click listener

forgotPassword.setOnClickListener(new View.OnClickListener() { @Overridepublic void


onClick(View v) {

Intent forgotIntent = new Intent(MainActivity.this, ForgotPasswordActivity.class);

startActivity(forgotIntent); } });

7
Forgot Password Page


This page allows user to update or change the password using email id.

Field Names:

frgtEmailId = (EditText)findViewById(R.id.etFEmailId);

frgtPassword = (EditText)findViewById(R.id.etFEmailId); frgtConfrimPassword =


(EditText)findViewById(R.id.etFEmailId); btUpdate = (Button) findViewById(R.id.btUpdate);

Validations:

if(!isValidEmail(emialIdValue)){

frgtEmailId.requestFocus();

frgtEmailId.setError("Invalid Email ID"); }else if(frgtPassword.length() == 0){

frgtPassword.requestFocus();

frgtPassword.setError("Field cannot be empty"); }else


if(!confrimPassword.equals(passwordValue)){

frgtConfrimPassword.requestFocus();

frgtConfrimPassword.setError("Confirm password is not same"); }else{

//insert data

forgotPassword(emialIdValue,passwordValue,confrimPassword); }

8

Get Location Button Code


This code gets the current user location details

if(gps.canGetLocation()){
try {
adresses = geocoder.getFromLocation(latitude,longitude,1);
address = adresses.get(0).getAddressLine(0);
city = adresses.get(0).getLocality();
state = adresses.get(0).getAdminArea();
country = adresses.get(0).getCountryName();
postalCode = adresses.get(0).getPostalCode();
knownName = adresses.get(0).getFeatureName();

/*tvLocation.setText("Longitude:" +Double.toString(longitude)+
"\nLatitude:" +Double.toString(latitude));*/

tvLocation.setText("Your Location:\n" +address+"\n"+city+"\n"+state+


"\n"+country+"\n"+postalCode+"\n"+knownName);

} catch (IOException e) {
e.printStackTrace();
}



Request Droid Button Code


Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;

try{
socket = new Socket("192.168.1.93", 5554);
dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataInputStream = new DataInputStream(socket.getInputStream());
dataOutputStream.writeUTF(String.valueOf(lng));
dataOutputStream.writeUTF(String.valueOf(lat));

tvLocation.setText("Droid "+dataInputStream.readUTF()+" has been assited to you.\n


Thanks.");
b_trackLocation.setVisibility(View.VISIBLE);

} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}



9
Track Location Button Code


This code calls the map activity to trace route

Intent adressIntent = new Intent(LocationActivity.this,MapsActivity.class);
adressIntent.putExtra("Address", address);
adressIntent.putExtra("City", city);
adressIntent.putExtra("State", state);
adressIntent.putExtra("Country", country);
startActivity(adressIntent);


Track Location Code


This code shows origin (user current location) and destination (droid location), track the route,
shows the distance and time between points.

Bundle extras = getIntent().getExtras();
if (extras != null)
{
String adressParam = extras.getString("Address");
String cityParam = extras.getString("City");
String stateParam = extras.getString("State");
String countryParam = extras.getString("Country");
etOrigin.setText(adressParam+","+cityParam+","+stateParam+","+countryParam);
}

etDestination.setText("Northwestern Polytechnic University, Fremont, CA");



//current location marker
originMarkers.add(mMap.addMarker(new MarkerOptions()
.title("Current Location")
.position(latLng)));

//origin marker
originMarkers.add(mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue))
.title(route.startAddress)
.position(route.startLocation)));
//destination marker
destinationMarkers.add(mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green))
.title(route.endAddress)
.position(route.endLocation)));

//route line
PolylineOptions polylineOptions = new PolylineOptions().
geodesic(true).
color(Color.BLUE).
width(10);

for (int i = 0; i < route.points.size(); i++)


polylineOptions.add(route.points.get(i));

10
polylinePaths.add(mMap.addPolyline(polylineOptions));


Alert Droid Arrived Code


This code shows an alert box on droid arrival to user location
dialog.setTitle("Alert");
dialog.setMessage("Droid Has Arrived to you.");
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent bluetoothIntent = new Intent(MapsActivity.this, ClientBluetooth.class);
startActivity(bluetoothIntent);

dialog.dismiss();
}
});
dialog.setCancelable(false);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
MediaPlayer mediaPlayer = MediaPlayer.create(MapsActivity.this,
R.raw.useralert);
mediaPlayer.start();

dialog.show();
}
}, 1000 * 60 * 1);

Bluetooth Client Socket Code


This code looks for droid Bluetooth and pairs to the droid

pairedDeviceArrayList = new ArrayList<BluetoothDevice>();

for (BluetoothDevice device : pairedDevices) {


pairedDeviceArrayList.add(device);
}

pairedDeviceAdapter = new ArrayAdapter<BluetoothDevice>(this,


android.R.layout.simple_list_item_1, pairedDeviceArrayList);
listViewPairedDevice.setAdapter(pairedDeviceAdapter);

listViewPairedDevice.setOnItemClickListener(new AdapterView.OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
BluetoothDevice device =
(BluetoothDevice)parent.getItemAtPosition(position);
Toast.makeText(ClientBluetooth.this,
"Name: " + device.getName() + "\n"

11
+ "Address: " + device.getAddress() + "\n"
+ "BondState: " + device.getBondState() + "\n"
+ "BluetoothClass: " + device.getBluetoothClass() + "\n"
+ "Class: " + device.getClass(),
Toast.LENGTH_LONG).show();

//textStatus.setText("start ThreadConnectBTdevice");
myThreadConnectBTdevice = new ThreadConnectBTdevice(device);
myThreadConnectBTdevice.start();
}});


if(success){
//connect successful
final String msgconnected = "\nconnect successful:\n"
+ "\nBluetoothSocket: " + bluetoothSocket + "\n"
+ "\nBluetoothDevice: " + bluetoothDevice;

runOnUiThread(new Runnable(){

@Override
public void run() {
//textStatus.setText(msgconnected);

listViewPairedDevice.setVisibility(View.GONE);
inputPane.setVisibility(View.VISIBLE);
}});

startThreadConnected(bluetoothSocket);
}else{
//fail
}



















12
Droid Side Coding Structure


Droid location and tracking is same as user part.

Droid Bluetooth socket code


This code pairs to the user device and starts capturing video of user activity

try {
bluetoothSocket = bluetoothServerSocket.accept();

BluetoothDevice remoteDevice = bluetoothSocket.getRemoteDevice();

final String strConnected = "\nConnected:\n" +


remoteDevice.getName() + "\n" +
remoteDevice.getAddress();

//connected
runOnUiThread(new Runnable(){

@Override
public void run() {
//textStatus.setText(strConnected);
inputPane.setVisibility(View.VISIBLE);
//video
Intent camera_intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File video_file = getFilePath();
Uri video_uri = Uri.fromFile(video_file);
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, video_uri);
camera_intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,1);
startActivityForResult(camera_intent, VIDEO_REQUEST_CODE);

}});

startThreadConnected(bluetoothSocket);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();










13
Police siren and call service code


MediaPlayer mediaPlayer = MediaPlayer.create(StressActivity.this, R.raw.policesiren);
mediaPlayer.start(); // no need to call prepare(); create() does that for you

//voicemail
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("6504229567", null, "sms message", null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();

Intent callIntent = new Intent(Intent.ACTION_CALL);


callIntent.setData(Uri.parse("tel:XXXXXXXXXX"));
if (ActivityCompat.checkSelfPermission(StressActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
startActivity(callIntent);






















14
Server Programming


This is about sending user location details to the grid system and checking for nearest droid to
user.

Client Side:

Socket socket = null;

DataOutputStream dataOutputStream = null; DataInputStream dataInputStream = null; try{

socket = new Socket("192.168.1.93", 5554);dataOutputStream = new


DataOutputStream(socket.getOutputStream()); dataInputStream = new
DataInputStream(socket.getInputStream()); dataOutputStream.writeUTF(String.valueOf(lng));
dataOutputStream.writeUTF(String.valueOf(lat));

} catch (UnknownHostException e) { e.printStackTrace();

} catch (IOException e) { e.printStackTrace();

Server Side:

public final static int defaultPort = 5554;//port no of the device DataOutputStream output;

DataInputStream input;Socket connection = theServer.accept(); System.out.println("Accept


Client!"); input = new DataInputStream(

connection.getInputStream()); output = new DataOutputStream(

connection.getOutputStream()); System.out.println("Client Connected and Start get I/O!!");


while (true) {

String longitude = input.readUTF(); String latitude = input.readUTF();

System.out.println("==> Input from Client: longitude " + longitude);

System.out.println("==> Input from Client: latitude " + latitude); System.out.println("Output


to Client ==> \"Connection successful\""); output.writeUTF("Connection
successful");output.flush();

15
Writing and Reading to Excel Files



This page sends user latitude and longitude details to excel file to plot a graph of user
intersection and to get nearest droid.

Write to excel:

FileInputStream inputStream = new FileInputStream(new File(excelFilePath));

HSSFWorkbook workbook = new HSSFWorkbook(inputStream); HSSFSheet sheet =


workbook.getSheetAt(0);Cell cell = null;//update the value of cell

cell = sheet.getRow(1).getCell(0);cell.setCellValue(latitude);cell =
sheet.getRow(1).getCell(1);cell.setCellValue(longitude);//Row row =
sheet.getRow(0);inputStream.close();FileOutputStream outFile = new FileOutputStream(new
File(excelFilePath)); workbook.write(outFile);

outFile.close();

Read from excel file: //read from excel file

try{FileInputStream inputStream = new FileInputStream(new File(excelFilePath));


HSSFWorkbook workbook = new HSSFWorkbook(inputStream);HSSFSheet sheet =
workbook.getSheetAt(0);Cell cell = null;//update the value of cellcell =
sheet.getRow(18).getCell(1);output.writeUTF(String.valueOf(cell));

}catch (FileNotFoundException e) { e.printStackTrace();

} catch (IOException e) { e.printStackTrace();

16
Database Files



Database:

Registration:

Login:

Forgot password:

17
App Output



Login Registration

18

Forgot Password Get Location

19
Droid Result Track Location

20
Alert Dialog Bluetooth connection

21
Stress Call

22
Droid Output



Video Calling Service

23
Plot Graph


This graph show which droid is near to user location. There are 10 droids plot in this graph. User
location is shown by intersecting lines.

24
References



https://exotel.in/blog/single-number-helpline-for-india/

https://www.quora.com/India-What-is-it-like-to-dial-100-in-India-Is-
it-as-responsive-as-dialling-911-in-USA

http://www.vogella.com/tutorials/android.html

http://www.excel-easy.com/data-analysis/charts.html

25

You might also like