SIM900 gprs网络与arduino

时间:2015-11-26 07:45:14

标签: arduino gprs sim900

我对这个简单的代码有疑问。

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7, 8); // configure software serial port

void setup() {     
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);

  SIM900.begin(19200);
  Serial.begin(19200); 
  Serial.println("power up" );
  delay(15000); 
}

void loop()
{
  Serial.println("SubmitHttpRequest - started" );
  SubmitHttpRequest();
  //callSomeone();
  Serial.println("SubmitHttpRequest - finished" );
  delay(10000);

}

void SubmitHttpRequest()
{
  SIM900.println("AT+CSQ"); // Signal quality check
  delay(100);
  ShowSerialData();

  SIM900.println("AT+CSQ"); // Signal quality check
  delay(100);
  ShowSerialData();

  SIM900.println("AT+CGATT?"); //Attach or Detach from GPRS Support
  delay(100);
  ShowSerialData();

  SIM900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);
  ShowSerialData();

  SIM900.println("AT+SAPBR=3,1,\"APN\",\"gprs-service.com\"");
  delay(1000);
  ShowSerialData();

  SIM900.println("AT+SAPBR=1,1");
  delay(1000);
  ShowSerialData();

  SIM900.println("AT+HTTPINIT"); //init the HTTP request
  delay(1000); 
  ShowSerialData();

  SIM900.print("AT+HTTPPARA=\"URL\",\"http://xxxxxx.com/master.php");
  SIM900.println("\"");
  delay(1000);
  ShowSerialData();

  SIM900.println("AT+HTTPACTION=0");//submit the request 
  delay(10000);
  ShowSerialData();

  SIM900.println("AT+HTTPREAD");// read the data from the website you access
  delay(500);
  ShowSerialData();

  SIM900.println("");
  delay(100);

  SIM900.println("AT+HTTPTERM");// read the data from the website you access
  delay(300);
  ShowSerialData();
}

void getContent()
{
  String content = "";
  while(SIM900.available() != 0)
  {
    content = content + String(char(SIM900.read()));
    Serial.write(char(SIM900.read()));
    delay(500);
    Serial.flush();
  }
}

void ShowSerialData()
{
  while(SIM900.available()!=0)
    Serial.write(char (SIM900.read()));
}

收到几个字符,输出为:

power up
SubmitHttpRequest - started
AT+CSQ

+CSQ: 25,0

OK
AT+CSQ

+CSQ: 25,0

OK
AT+CGATT?

+CGATT: 1

OK
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK
AT+SAPBR=3,1,"APN","gprs-service.com"

OK
AT+SAPBR=1,1

OK
AT+HTTPINIT

OK
AT+HTTPPARA="URL","http://xxxxxx.com/master.php"

OK
AT+HTTPACTION=0

OK

+HTTPACTION:0,200,66
AT+HTTPREAD

+HTTPREAD:66
Numero de accesos: 77 | Identifica
AT+HTTPTERM

OK
SubmitHttpRequest - finished

==&GT; “Numero de accesos:77 | Identifica”

但是,真的,输出应该是:

Numero de accesos:77 | Identificador:4l02pnl828o3kctg4strc87ed1

完全像:HTTPREAD missing characters with Arduino and SIM900

任何想法或帮助?

谢谢!

1 个答案:

答案 0 :(得分:1)

Numero de accesos: 77 | Identifica是34个字符。这意味着sim900返回66个字符,这是正确的长度。

尝试在ShowSerialData之前增加延迟或等到串行缓冲区中有66 bytes