Seeed-Studio / GPRS_SIM900

library for GPRS shield with sim900 module.
MIT License
138 stars 96 forks source link

Longer inter-character timeout for connect #1

Closed metadaddy closed 9 years ago

metadaddy commented 9 years ago

GPRS::connect() often failed for me. I found that the SIM900 responds to the AT+CIPSTART command immediately with OK, but then takes a couple of seconds to follow up with CONNECT OK. This delay was more than the default inter-character timeout, so sim900_read_buffer() would return before it read the CONNECT OK, and GPRS::connect() would return false.

Making the inter-character timeout the same as the other timeout parameter fixes this for me.

ortegafernando commented 9 years ago

Hi,

Thanks a lot for your contribution, but it's better to do it more open for everybody, so we prefer to make the connect function declaration better.

What do you think about:

bool connect(Protocol ptl, const char * host, int port, int timeout = 2 * DEFAULT_TIMEOUT, int chartimeout = 2 * DEFAULT_INTERCHAR_TIMEOUT); bool connect(Protocol ptl, const FlashStringHelper *host, const FlashStringHelper port, int timeout = 2 * DEFAULT_TIMEOUT, int chartimeout = 2 \ DEFAULT_INTERCHAR_TIMEOUT);

And then, change all sim900_read_buffer() calls inside CONNECT functions with "chartimeout" function.

In your sketch you will call like: sim900.connect( XXX, XXX, XXX, 5, 5) or whatever you like.

We prefer that, than putting inside the function this kind of call: "timeout * 1000"

What do you think ?

Best regards

metadaddy commented 9 years ago

Yes - that makes complete sense - I'll refactor my code as you suggest, test it, and commit the changes if all is good.

metadaddy commented 9 years ago

@juan3211 Reworked my code as you suggested. Works great for me - in fact, even just using the default value you suggested for chartimeout (doubling the previous value) works much better.

xiongyihui commented 9 years ago

Thanks. Merged :)

metadaddy commented 9 years ago

Awesome - thanks!