我正在使用Arduino UNO R3微控制器和GSM-900a SIM模块。我想激活SIM卡的数据连接,并希望将某些数据发送到特定服务器或点击上传到服务器中的特定.php文件。我已尝试此代码但无法在服务器中发送数据。但我已经测试了SMS,它正在工作,但基于数据连接的工作却什么也没做。除了误解之外,没有任何例外。我已经完成了这段代码。
#include <avr/io.h>
#include <avr/interrupt.h>
#include <SoftwareSerial.h>
SoftwareSerial GPS(12,13); //RX,TX
SoftwareSerial GSMM(10,11); //RX,TX
#define SIZE 64
//volatile word seconds = 0;
//byte state = 1;
//long lati = 0;
//long longi = 0;
//long lati_temp;
//long longi_temp;
//const unsigned char UBX_HEADER[] = { 0xB5, 0x62 };
unsigned char buffer[SIZE]= "";
int count=0;
void setup()
{
Serial.begin(9600);
delay(500);
GSMM.begin(9600);
delay(20000);
delay(20000);
delay(20000);
}
void gsm_read()
{
if (GSMM.available()){ // if date is comming from softwareserial port ==> data is comming from gprs shield
while(GSMM.available()){ // reading data into char array
buffer[count++]=GSMM.read(); // writing data into array
if(count == SIZE)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
count = 0;
}
}
void SendData(String a,String b)
{
GSMM.println("AT");
delay(1000);
GSMM.println("AT+CREG?");
delay(1000);
GSMM.println("AT+SAPBR=1,1");
delay(2000);
GSMM.println("AT+SAPBR=2,1");
delay(2000);
GSMM.println("AT+HTTPINIT");
delay(1000);
GSMM.println("AT+HTTPPARA=\"URL\",\"ehealthmonitor.comli.com/pritam.php?lat=20.0&lon=55.66\"");
delay(1000);
GSMM.println("AT+HTTPPARA=\"CID\",1[[|]]");
delay(1000);
GSMM.println("AT+HTTPACTION=0");
delay(10000);
GSMM.println("AT+HTTPREAD");
delay(300);
GSMM.println("AT+HTTPTERM");
delay(1000);
}
void loop() {
Serial.println("Sending");
SendData("a","b");
delay (5000);
count=0;
Serial.println("Sent");
}