I have an Arduino Mega 2560 board and using Serial 2 for communication with SIM9000A GSM Modem. I send over a HTTP get request by using appropriate AT command strings.
The GSM modem TX/RX pins are crossed with Arduino's Serial 2 port while the GSM modem card which also has DB9 pins is connected to a Hyper terminal - to see what it is receiving / rendering.
My issue is when I have to read after I get a response for my HTTP Get request.
Below is my code:
int Read(String message) { char temp = '\0'; int i=0; numbytes = 0; message= ""; int endCnt = 0; debug_println("Reading Data!"); Serial2.println("AT+HTTPREAD"); delay(200); while(endCnt < 4) { while((Serial2.available())>0) { temp = Serial2.read(); Serial.print(temp); switch(temp) { case '\r' : endCnt = 1; break; case '\n' : if(endCnt == 1) endCnt = 2; else endCnt = 0; break; case 'O' : if(endCnt == 2) endCnt = 3; else endCnt = 0; break; case 'K' : if(endCnt == 3) endCnt = 4; else endCnt = 0; break; default : endCnt = 0; break; } if(endCnt == 4) break; } } debug_println("Read Data Ret: "); return i; }
Note the Terminal shows me correctly when a HTTPREAD command is passed to GSM modem:
+HTTPACTION: 0,200,286 +HTTPREAD: 286 {"first_name":"dddddddddddddd","last_name":"dddddddddddddddd","start_date":"2000-12-31","chargeamt":"09.80","status":"ok","id":"68"} <!-- Hosting24 Analytics Code --> <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script> <!-- End Of Analytics Code --> OK
But Serial port printing shows me :
Reading Data! +HTTPREAD: 286 {"first_name":"dddddddddddddd","last_name":"ds Code --> <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script> <!-- End Of Analytics Code --> OK
So after reading 45-46 th character at Serial2 port I am loosing data. I have tried all ways but unable to understand why my data at serial port is lost / overwritten?
Please let me know how can I resolve this?