iam使用带有Arduino Uno的itead sim908 Gsm / Gps / Gprs模块,iam尝试通过Sms消息和gprs向互联网服务器发送Gps坐标,但是无法同时运行它,虽然它可以单独工作。
当我尝试通过短信发送GPS坐标并通过gprs发送数据到同一时间我有这个错误:
错误:SIM900无法接听。检查GSM.cpp中的电源和串行引脚
这是我的代码,任何人都有解决方案吗?
#include "SIM900.h"
#include
#include "inetGSM.h"
#include "sms.h"
//#include "call.h"
#include "gps.h"
char smsbuffer2[150];
char id[]="12";
char httpbuffer[160];
InetGSM inet;
//CallGSM call;
SMSGSM sms;
GPSGSM gps;
char msg[50];
int numdata;
char lon[15];
char lat[15];
char alt[15];
char time[20];
char vel[15];
char msg1[5];
char msg2[5];
char Mobile[]="0595285486";
char stat;
char inSerial[50];
int i=0;
boolean started=false;
void setup(){
get_gps();
delay(1000);
send_server();
delay(1000);
send_sms();
}
void loop(){
}
void get_gps(){
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600)) {
Serial.println("\nstatus=READY");
started=true;
gsm.forceON();
} else Serial.println("\nstatus=IDLE");
if(started) {
//GPS attach
if (gps.attachGPS())
Serial.println("status=GPSREADY");
else Serial.println("status=ERROR");
delay(20000); //Time for fixing
stat=gps.getStat();
if(stat==1)
Serial.println("NOT FIXED");
else if(stat==0)
Serial.println("GPS OFF");
else if(stat==2)
Serial.println("2D FIXED");
else if(stat==3)
Serial.println("3D FIXED");
delay(5000);
//Get data from GPS
gps.getPar(lon,lat,alt,time,vel);
Serial.println(lon);
Serial.println(lat);
Serial.println(alt);
Serial.println(time);
Serial.println(vel);
convert2Degrees(lat);
convert2Degrees(lon);
}
}
void send_server(){
if (gsm.begin(9600)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
//GPRS attach, put in order APN, username and password.
//If no needed auth let them blank.
if (inet.attachGPRS("internet", "", ""))
Serial.println("status=ATTACHED");
else Serial.println("status=ERROR");
delay(1000);
//Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
//Read until serial buffer is empty.
gsm.WhileSimpleRead();
//TCP Client GET, send a GET request to the server and
//save the reply.
/*
httpbuffer[0]='\0';
strcat(httpbuffer,"/GetData.aspx?lat=");
strcat(httpbuffer,lat);
strcat(httpbuffer,"&&lon=");
strcat(httpbuffer,lon);
strcat(httpbuffer,"&&id");
strcat(httpbuffer,id);
Serial.println(httpbuffer);
*/
numdata=inet.httpPOST("qou.azurewebsites.net", 80,"httpbuffer", msg, msg,12);
//Print the results.
Serial.println("\nNumber of data received:");
Serial.println(numdata);
Serial.println("\nData received:");
Serial.println(msg);
}
}
void send_sms(){
if (gsm.begin(9600)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started){
smsbuffer2[0]='\0';
strcat(smsbuffer2,"Vehicle Accident Occurs to Vehicle which Have ");
strcat(smsbuffer2,"ID number");
strcat(smsbuffer2,id);
strcat(smsbuffer2,"in Location :");
strcat(smsbuffer2,lat);
strcat(smsbuffer2,lon);
strcat(smsbuffer2,"Owner Name:Ayman Abd Albasit Sadq Daqah");
strcat(smsbuffer2,"Mobile :");
strcat(smsbuffer2,Mobile);
if (sms.SendSMS(Mobile, "smsbuffer2"))
Serial.println("\nSMS sent OK");
}
}