We've been happily running an Arduino 2560 with a SIM 900 GSM shield to communicate with our server.
So far the data-transfers were very limited, small HTTP POSTs with a very limited data set being sent back and forth.
However, lately we needed to download a file over HTTP using the SIM900 and we ran into some issues.
We're sending the standard CIPSTART/CIPSEND commands to initiate a TCP connection.
AT+CIPSTART="TCP","ourserver.com","80"OKCONNECT OK
AT+CIPSEND=117
We then execute an HTTP GET, send some request headers and wait for the response
GET /endpoint/firmware/download HTTP/1.1
HOST: ourserver.com
User-Agent: Arduino
Once we receive the response, we can see from the content-length how much bytes we need to read.
We're using code like this:
while(_serial->available() > 0){
char c = _serial->read();
char hex[2];
sprintf(hex,"[%02x]", static_cast<unsigned char>(c));
Serial.print(hex);
if((bodycounter+1) % 16 == 0 )
Serial.println(String("Bytes : ") + String(bodycounter));
crc32(oldcrc32,c, len);
dataFile.print(c);
}
This results in the logging below . As you can see, we simply print out a hex representation of the bytes that we're processing, and also the number of bytes we've processed.
The issue is that somewhere in that processing, the system hangs. It simply stops processing. It stays like that and never continues / recovers.
[bb][81][c9][5c][d1][40][28][17][39][07][4a][07][5b][07][41][f4]Bytes : 37231
[00][e0][21][15][31][05][41][05][51][05][19][f0][01][e0][01][c0]Bytes : 37247
[00][e0][ce][01][86][58][9f][4f][0e][94][4d][94][c3][53][de][4f]Bytes : 37263
[a8][81][b9][81][cd][5c][d1]
The behavior is pretty random :
- It sometimes hangs very early on (after reading a couple of thousand bytes)
- it can hangs somewhere in the middle (50%)
- it can happen at 99%
- Sometimes it doesn't hang at all and it processed all 79532 bytes without an issue.
Any idea what might be causing this ? We initially thought it might be because the server was serving the file too fast and the SIM900 couldn't keep up, but even by throttling the server (customizing both the packet-size and the delays between packets) we still ran into these hangs.
Any idea what might be causing them ? We're always testing with the same file.
I did monitor the network traffic on the server using tcpmon, and got the following logging when using curl or telnet from a PC to download the file
23:15:13.083324 IP 188.188.111.100.52896 > CentOS-63-64-minimal.http: Flags [.], ack 2, win 33304, options [nop,nop,TS val 739980698 ecr 2331250456], length 0
0x0000: 4500 0034 3fb9 4000 3106 c7f5 8d86 e4d8 E..4?.@.1.......
0x0010: 904c 3f6a cea0 0050 113c 992c cd39 9a77 .L?j...P.<.,.9.w
0x0020: 8010 8218 d5c2 0000 0101 080a 2c1b 359a ............,.5.
0x0030: 8af4 0f18
With the Arduino / SIM 900 I noticed there were no TCP options in the TCP packets (no nop, TS val, ecr). But I don't know how important those are.
23:19:43.190626 IP 188.188.111.211.26348 > CentOS-63-64-minimal.http: Flags [.], ack 42900, win 2161, length 0
0x0000: 4508 0028 0034 0000 3306 8b4e bcbc 6fd3 E..(.4..3..N..o.
0x0010: 904c 3f6a 66ec 0050 002c f7f6 322e bd67 .L?jf..P.,..2..g
0x0020: 5010 0871 5c28 0000 0000 0000 0000 P..q\(........
Any ideas why the Arduino / SIM 900 would simply hang during this file download ?