0% found this document useful (0 votes)
7 views3 pages

Project

Tt

Uploaded by

ingaminz16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Project

Tt

Uploaded by

ingaminz16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

}

void Impact()
{
time1=micros();
int oldx=xaxis;
int oldy=yaxis;
int oldz=zaxis;

xaxis=analogRead(xPin);
yaxis=analogRead(yPin);
xaxis=analogRead(xPin);

vibration--;
Serial.print("Vibration=");
Serial.println(vibration);
if(vibration<0)vibration=0;
if(vibration>0) return;
deltx=xaxis-oldx;
delty=yaxis-oldy;
deltz=zaxis-oldz;

magnitude=sqrt(sq(deltx)+sq(delty)+sq(deltz));
if(magnitude>=sensitivity)
{
updateflag=1;
vibration=devibrate;
}
else
{
magnitude=0;
}
}

void parseData(String buff) {


Serial.println(buff);

unsigned int len,index;


index=buff.indexOf("\r");
buff.remove(0,index+2);
buff.trim();
if(buff!="OK"){
index=buff.indexOf(":");
String cmd =buff.substring(0,index);
cmd.trim();

buff.remove(0,index+2);
if(cmd=="+CMTI"){
index=buff.indexOf(",");
String temp=buff.substring(index+1,buff.length());
temp="AT+CMGR="+temp+"\r";
sim800.println(temp);
}
else if(cmd=="CMGR"){
if(buff.indexOf(EMERGENCY_PHONE)>1){
buff.toLowerCase();
if(buff.indexOf("get gps")>1){
getGps();
String sms_data;
smas_data="GPS location data\r";
sms_data+="http://maps.google.com/maps?q=loc:";
sms_data+= latitude+","+longitude;
sendSms(sms_data);
}
}
}
}
else{
}
}
void getGps()
{
//can take up to 60 seconds
Boolean newData=false;
for(unsigned long start =millis();millis()-start<2000;){
while(neogps.available()){
if(gps.encode(neogps.read())){
newData=true;
break;
}
}
}
if(newData)
{
latitude=string(gps.location.lat(),6);
longitude=string(gps.location.lng(),6);
newData=false;
}
else
{
Serial.println("No GPS data is available");
latitude="";
longitude="";
}
Serial.print("latitude=");Serial.println(latitude);
Serial.print("longitude=");Serial.println(longitude);
}
void sendAlert()
{
String sms_data;
sms_data="Accident Alert!!\r";
sms_data+="http://maps.google.com/maps?q=loc;
sms_data+=latitude+","+longitude;
sengSms(sms_data);
}
void makeCall()
{
Serial.println("calling...");
sim800.println("ATD"+EMERGENCY_phone+";");
delay(20000);
sim800.println("ATH");
delay(1000);
}
void sendSms(String text)
{
sim800.print("AT+CMGF=1\r");
delay(1000);
sim800.print("AT+CMGS=\""+EMERGENCY_PHONE+"\"\r");
delay(1000);
sim800.print(text);
delay(100);
sim800.write(0x1A);
delay(1000);
Serial.println("SMS Sent Successfully.");
}
boolean SendAT(String at_command, String expected_answer,unsigned in timeout)
{
unit8_t x=0;
boolean answer=0;
String response;
unsigned long previous;
while(sim800.available()>0)sim800.read();
sim800.println(at_command);
x=0;
previous=millis();
do
{
if(sim800.available()!=0)
{
response+=sim800.read();
x++;
if(response.index0f(expected_answer)>0)
{
answer=1;
break;
}
}
}
while((answer==0)&&((millis()-previous)<timeout));
Serial.println(response);
return answer;
}

You might also like