2015-11-26 102 views
1

我有這個簡單的代碼有問題。SIM900 gprs網絡與arduino

#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 

==>「NÚMERO德accesos:77 | Identifica」

但是,真的,輸出應該是:

結果頁數:77 | Identificador:4l02pnl828o3kctg4strc87ed1

完全一樣:HTTPREAD missing characters with Arduino and SIM900

任何意見或幫助?

謝謝!

回答

1

Numero de accesos: 77 | Identifica是34字符。這意味着sim900會返回66個正確長度的字符。

嘗試增加ShowSerialData之前的延遲或等待,直到您有66 bytes在串行緩衝區中。