brianrho / SIM800-for-TCP

This is a slimmer version of the Adafruit FONA library intended for only TCP connections using the cheap SIM800 breakout modules.
MIT License
8 stars 5 forks source link

TCPConnect timeout #1

Closed geologic closed 7 years ago

geologic commented 7 years ago

Hi First time i connect SIM800 it fails sending message, because SIM800 needs time to settle and open TCP connection. The folowing times it connects ok. I tried add a timeout on the SIM800.CPP TCPConnect() function at:

  if (! expectReply(ok_reply),5000) return false;
  if (! expectReply(F("CONNECT OK")),5000) return false;

but after that it always fails. Can you help?

Regards

brianrho commented 7 years ago

You mean that with the original code, the SIM800 fails to connect the very first time but succeeds in subsequent retries? Did you follow the modem_client example, by preceding TCPconnect() with

modem.setGPRSNetworkSettings(F("your apn"));
modem.enableGPRS(true);
geologic commented 7 years ago

Yes, i followed modem_client example. First time i power sim800 and arduino, it fails; if i reset arduino (keeping sim800 powerd on), it sends ok.

On Tue, May 16, 2017 at 8:17 PM, Brian Ejike notifications@github.com wrote:

You mean that with the original code, the SIM800 fails to connect the very first time but succeeds in subsequent retries? Did you follow the modem_client example, by preceding TCPconnect() with

modem.setGPRSNetworkSettings(F("web.gprs.mtnnigeria.net")); modem.enableGPRS(true);

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/brianrho/SIM800-for-TCP/issues/1#issuecomment-301887130, or mute the thread https://github.com/notifications/unsubscribe-auth/AGfc8vebpI_ZBpl3sE2UQSahK_ZS7OqHks5r6fZPgaJpZM4NcnRe .

geologic commented 7 years ago

Well, after playing around with your code i notice that you are not checking for success on modem.enableGPRS(), so i did this:

while  ( ! modem.enableGPRS(true)) {
     Serial.println(F("enableGPRS Retry..."));
    delay(1000);
}
brianrho commented 7 years ago

The default timeout period was good enough for me and this issue never came up. If it worked for you though, perhaps I'll edit the example.

brianrho commented 7 years ago

I think I'll leave out the check since looking through the method's code now, the timeout for each command sent is at least 10s, more than enough in most cases to get the job done and the whole point of encapsulating the commands+reasonable timeouts under one method is to prevent this kind of check from popping up everywhere in application code. Yours is a special case, I think, and I'll leave it up to the user to insert checks as necessary, like you did. It's only an example after all.