我正在使用带有Arduino Uno的itead sim908 Gsm / Gps / Gprs模块,我试图通过Sms消息和gprs将Gps坐标发送到互联网服务器,但不能同时运行它,虽然它是分开工作的。
当我尝试通过 SMS 消息发送 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");
}
}