2

我正在使用 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");
}
4

0 回答 0