Shield SIM908 e Arduino UNO mandar mensagem com as coordenadas
Página 1 de 1
Shield SIM908 e Arduino UNO mandar mensagem com as coordenadas
os codigos funcionam separados mas nao estou conseguindo juntar os codigos para mandar mensagem com as coordenadas
quem puder me ajudar eu agradeço vlw.
esse é o codigo de mandar a mensagem para o celular:
byte gsmDriverPin[3] = {3,4,5};//The default digital driver pins for the GSM and GPS mode
//If you want to change the digital driver pins
//or you have a conflict with D3~D5 on Arduino board,
//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!
void setup()
{
//Init the driver pins for GSM function
for(int i = 0 ; i < 3; i++){
pinMode(gsmDriverPin[i],OUTPUT);
}
digitalWrite(5,HIGH);//Output GSM Timing
delay(1500);
digitalWrite(5,LOW);
digitalWrite(3,LOW);//Enable the GSM mode
digitalWrite(4,HIGH);//Disable the GPS mode
delay(2000);
Serial.begin(9600); //set the baud rate
delay(5000);//call ready
delay(5000);
delay(5000);
}
void loop()
{
Serial.println("AT"); //Send AT command
delay(2000);
Serial.println("AT");
delay(2000);
//Send message
Serial.println("AT+CMGF=1");
delay(1000);
Serial.println("AT+CMGS=\"92860481\"");//Change the receiver phone number
delay(1000);
Serial.print("TEX ARDUINO TESTE.");//the message you want to send
delay(1000);
Serial.write(26);
while(1);
}
e esse aqui serve para obter as coordenadas pelo serial minitor do arduino uno
double Datatransfer(char *data_buf,char num)//convert the data to the float type
{ //*data_buf:the data array
double temp=0.0; //the number of the right of a decimal point
unsigned char i,j;
if(data_buf[0]=='-')
{
i=1;
//process the data array
while(data_buf[i]!='.')
temp=temp*10+(data_buf[i++]-0x30);
for(j=0;j temp=temp*10+(data_buf[++i]-0x30);
//convert the int type to the float type
for(j=0;j temp=temp/10;
//convert to the negative numbe
temp=0-temp;
}
else//for the positive number
{
i=0;
while(data_buf[i]!='.')
temp=temp*10+(data_buf[i++]-0x30);
for(j=0;j temp=temp*10+(data_buf[++i]-0x30);
for(j=0;j temp=temp/10 ;
}
return temp;
}
char ID()//Match the ID commands
{
char i=0;
char value[6]={
'$','G','P','G','G','A' };//match the gps protocol
char val[6]={
'0','0','0','0','0','0' };
while(1)
{
if(Serial.available())
{
val[i] = Serial.read();//get the data from the serial interface
if(val[i]==value[i]) //Match the protocol
{
i++;
if(i==6)
{
i=0;
return 1;//break out after get the command
}
}
else
i=0;
}
}
}
void comma(char num)//get ','
{
char val;
char count=0;//count the number of ','
while(1)
{
if(Serial.available())
{
val = Serial.read();
if(val==',')
count++;
}
if(count==num)//if the command is right, run return
return;
}
}
void UTC()//get the UTC data -- the time
{
char i;
char time[9]={
'0','0','0','0','0','0','0','0','0'
};
double t=0.0;
if( ID())//check ID
{
comma(1);//remove 1 ','
//get the datas after headers
while(1)
{
if(Serial.available())
{
time[i] = Serial.read();
i++;
}
if(i==9)
{
i=0;
t=Datatransfer(time,2);//convert data
t=t-30000.00;//convert to the chinese time GMT+8 Time zone
long time=t;
int h=time/10000;
int m=(time/100)%100;
int s=time%100;
// if(h>=24) //UTC+
// {
// h-=24;
// }
if (h<0) //UTC-
{
h+=24;
}
Serial.print(h);
Serial.print("h");
Serial.print(m);
Serial.print("m");
Serial.print(s);
Serial.println("s");
http://Serial.println(t);//Print data
return;
}
}
}
}
void latitude()//get latitude
{
char i;
char lat[10]={
'0','0','0','0','0','0','0','0','0','0'
};
if( ID())
{
comma(2);
while(1)
{
if(Serial.available())
{
lat[i] = Serial.read();
i++;
}
if(i==10)
{
i=0;
Serial.println(Datatransfer(lat,5)/100.0,7);//print latitude
return;
}
}
}
}
void lat_dir()//get dimensions
{
char i=0,val;
if( ID())
{
comma(3);
while(1)
{
if(Serial.available())
{
val = Serial.read();
Serial.write(val);
Serial.println();
i++;
}
if(i==1)
{
i=0;
return;
}
}
}
}
void longitude()//get longitude
{
char i;
char lon[11]={
'0','0','0','0','0','0','0','0','0','0','0'
};
if( ID())
{
comma(4);
while(1)
{
if(Serial.available())
{
lon[i] = Serial.read();
i++;
}
if(i==11)
{
i=0;
Serial.println(Datatransfer(lon,5)/100.0,7);
return;
}
}
}
}
void lon_dir()//get direction data
{
char i=0,val;
if( ID())
{
comma(5);
while(1)
{
if(Serial.available())
{
val = Serial.read();
Serial.write(val); http://Serial.println(val,BYTE);
Serial.println();
i++;
}
if(i==1)
{
i=0;
return;
}
}
}
}
void altitude()//get altitude data
{
char i,flag=0;
char alt[8]={
'0','0','0','0','0','0','0','0'
};
if( ID())
{
comma(9);
while(1)
{
if(Serial.available())
{
alt[i] = Serial.read();
if(alt[i]==',')
flag=1;
else
i++;
}
if(flag)
{
i=0;
Serial.println(Datatransfer(alt,1),1);//print altitude data
return;
}
}
}
}
void setup()
{
pinMode(3,OUTPUT);//The default digital driver pins for the GSM and GPS mode
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
digitalWrite(5,HIGH);
delay(1500);
digitalWrite(5,LOW);
digitalWrite(3,LOW);//Enable GSM mode
digitalWrite(4,HIGH);//Disable GPS mode
delay(2000);
Serial.begin(9600);
delay(5000);//GPS ready
Serial.println("AT");
delay(2000);
//turn on GPS power supply
Serial.println("AT+CGPSPWR=1");
delay(1000);
//reset GPS in autonomy mode
Serial.println("AT+CGPSRST=1");
delay(1000);
digitalWrite(4,LOW);//Enable GPS mode
digitalWrite(3,HIGH);//Disable GSM mode
delay(2000);
Serial.println("$GPGGA statement information: ");
}
void loop()
{
while(1)
{
Serial.print("UTC:");
UTC();
Serial.print("Lat:");
latitude();
Serial.print("Dir:");
lat_dir();
Serial.print("Lon:");
longitude();
Serial.print("Dir:");
lon_dir();
Serial.print("Alt:");
altitude();
Serial.println(' ');
Serial.println(' ');
}
}
quem puder me ajudar eu agradeço vlw.
esse é o codigo de mandar a mensagem para o celular:
byte gsmDriverPin[3] = {3,4,5};//The default digital driver pins for the GSM and GPS mode
//If you want to change the digital driver pins
//or you have a conflict with D3~D5 on Arduino board,
//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!
void setup()
{
//Init the driver pins for GSM function
for(int i = 0 ; i < 3; i++){
pinMode(gsmDriverPin[i],OUTPUT);
}
digitalWrite(5,HIGH);//Output GSM Timing
delay(1500);
digitalWrite(5,LOW);
digitalWrite(3,LOW);//Enable the GSM mode
digitalWrite(4,HIGH);//Disable the GPS mode
delay(2000);
Serial.begin(9600); //set the baud rate
delay(5000);//call ready
delay(5000);
delay(5000);
}
void loop()
{
Serial.println("AT"); //Send AT command
delay(2000);
Serial.println("AT");
delay(2000);
//Send message
Serial.println("AT+CMGF=1");
delay(1000);
Serial.println("AT+CMGS=\"92860481\"");//Change the receiver phone number
delay(1000);
Serial.print("TEX ARDUINO TESTE.");//the message you want to send
delay(1000);
Serial.write(26);
while(1);
}
e esse aqui serve para obter as coordenadas pelo serial minitor do arduino uno
double Datatransfer(char *data_buf,char num)//convert the data to the float type
{ //*data_buf:the data array
double temp=0.0; //the number of the right of a decimal point
unsigned char i,j;
if(data_buf[0]=='-')
{
i=1;
//process the data array
while(data_buf[i]!='.')
temp=temp*10+(data_buf[i++]-0x30);
for(j=0;j
//convert the int type to the float type
for(j=0;j
//convert to the negative numbe
temp=0-temp;
}
else//for the positive number
{
i=0;
while(data_buf[i]!='.')
temp=temp*10+(data_buf[i++]-0x30);
for(j=0;j
for(j=0;j
}
return temp;
}
char ID()//Match the ID commands
{
char i=0;
char value[6]={
'$','G','P','G','G','A' };//match the gps protocol
char val[6]={
'0','0','0','0','0','0' };
while(1)
{
if(Serial.available())
{
val[i] = Serial.read();//get the data from the serial interface
if(val[i]==value[i]) //Match the protocol
{
i++;
if(i==6)
{
i=0;
return 1;//break out after get the command
}
}
else
i=0;
}
}
}
void comma(char num)//get ','
{
char val;
char count=0;//count the number of ','
while(1)
{
if(Serial.available())
{
val = Serial.read();
if(val==',')
count++;
}
if(count==num)//if the command is right, run return
return;
}
}
void UTC()//get the UTC data -- the time
{
char i;
char time[9]={
'0','0','0','0','0','0','0','0','0'
};
double t=0.0;
if( ID())//check ID
{
comma(1);//remove 1 ','
//get the datas after headers
while(1)
{
if(Serial.available())
{
time[i] = Serial.read();
i++;
}
if(i==9)
{
i=0;
t=Datatransfer(time,2);//convert data
t=t-30000.00;//convert to the chinese time GMT+8 Time zone
long time=t;
int h=time/10000;
int m=(time/100)%100;
int s=time%100;
// if(h>=24) //UTC+
// {
// h-=24;
// }
if (h<0) //UTC-
{
h+=24;
}
Serial.print(h);
Serial.print("h");
Serial.print(m);
Serial.print("m");
Serial.print(s);
Serial.println("s");
http://Serial.println(t);//Print data
return;
}
}
}
}
void latitude()//get latitude
{
char i;
char lat[10]={
'0','0','0','0','0','0','0','0','0','0'
};
if( ID())
{
comma(2);
while(1)
{
if(Serial.available())
{
lat[i] = Serial.read();
i++;
}
if(i==10)
{
i=0;
Serial.println(Datatransfer(lat,5)/100.0,7);//print latitude
return;
}
}
}
}
void lat_dir()//get dimensions
{
char i=0,val;
if( ID())
{
comma(3);
while(1)
{
if(Serial.available())
{
val = Serial.read();
Serial.write(val);
Serial.println();
i++;
}
if(i==1)
{
i=0;
return;
}
}
}
}
void longitude()//get longitude
{
char i;
char lon[11]={
'0','0','0','0','0','0','0','0','0','0','0'
};
if( ID())
{
comma(4);
while(1)
{
if(Serial.available())
{
lon[i] = Serial.read();
i++;
}
if(i==11)
{
i=0;
Serial.println(Datatransfer(lon,5)/100.0,7);
return;
}
}
}
}
void lon_dir()//get direction data
{
char i=0,val;
if( ID())
{
comma(5);
while(1)
{
if(Serial.available())
{
val = Serial.read();
Serial.write(val); http://Serial.println(val,BYTE);
Serial.println();
i++;
}
if(i==1)
{
i=0;
return;
}
}
}
}
void altitude()//get altitude data
{
char i,flag=0;
char alt[8]={
'0','0','0','0','0','0','0','0'
};
if( ID())
{
comma(9);
while(1)
{
if(Serial.available())
{
alt[i] = Serial.read();
if(alt[i]==',')
flag=1;
else
i++;
}
if(flag)
{
i=0;
Serial.println(Datatransfer(alt,1),1);//print altitude data
return;
}
}
}
}
void setup()
{
pinMode(3,OUTPUT);//The default digital driver pins for the GSM and GPS mode
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
digitalWrite(5,HIGH);
delay(1500);
digitalWrite(5,LOW);
digitalWrite(3,LOW);//Enable GSM mode
digitalWrite(4,HIGH);//Disable GPS mode
delay(2000);
Serial.begin(9600);
delay(5000);//GPS ready
Serial.println("AT");
delay(2000);
//turn on GPS power supply
Serial.println("AT+CGPSPWR=1");
delay(1000);
//reset GPS in autonomy mode
Serial.println("AT+CGPSRST=1");
delay(1000);
digitalWrite(4,LOW);//Enable GPS mode
digitalWrite(3,HIGH);//Disable GSM mode
delay(2000);
Serial.println("$GPGGA statement information: ");
}
void loop()
{
while(1)
{
Serial.print("UTC:");
UTC();
Serial.print("Lat:");
latitude();
Serial.print("Dir:");
lat_dir();
Serial.print("Lon:");
longitude();
Serial.print("Dir:");
lon_dir();
Serial.print("Alt:");
altitude();
Serial.println(' ');
Serial.println(' ');
}
}
marcostuber- Mensagens : 2
Data de inscrição : 05/11/2014
Tópicos semelhantes
» Shield sim908 com o Arduino IDE 1.0.1
» FONTE 9V/1A SHIELD SIM908 ARDUINO
» SIM908 SHIELD
» Enviar SMS pelo Arduino Mega2560 + shield sim908 na IDE 1.5.5
» Mandar Variavel da Coordenada para o Celular SHIELD SIM 908
» FONTE 9V/1A SHIELD SIM908 ARDUINO
» SIM908 SHIELD
» Enviar SMS pelo Arduino Mega2560 + shield sim908 na IDE 1.5.5
» Mandar Variavel da Coordenada para o Celular SHIELD SIM 908
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos
|
|