arduino-libraries / MKRGSM

GNU Lesser General Public License v2.1
55 stars 51 forks source link

Add new GPRS::status() API #19

Closed sandeepmistry closed 6 years ago

sandeepmistry commented 6 years ago

This is a proposal for issue #15. Changes include:

It's still not ready, as it can't detect the scenario where you manually disconnect the antenna and the board loses signal.

cc/ @alvarolb @FrancMunoz @w3p706

FrancMunoz commented 6 years ago

Will test today and report in afew days. Thank you!

w3p706 commented 6 years ago

Thank You! I've updated my code, it's running, and will also report back after the next disconnect. (approx. 1.5 days if i can let it run.)

w3p706 commented 6 years ago

For me the code worked well. After the disconnect, I received 'ERROR' on 'AT+UPSDA=0,3' for approximately 19 minutes. After that, connection was restored and udp working again.

This is my connect function, it is called every minute (I have to rewrite it, as other tasks are currently blocked while connecting):

`void Connect() {
GSM3_NetworkStatus_t status = gprs.status(); Serial.print("Connecting… - Status: "); Serial.println(status); if (status == GPRS_READY) return;

// After starting the modem with GSM.begin() // attach the shield to the GPRS network with the APN, login and password

boolean connected = false; while (!connected) {
Serial.print("Status. "); Serial.println(gprs.status());
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { connected = true; } else { Serial.println("Not connected"); delay(1000); } }

Serial.println("\nconnected. "); }`

And this is the start of my 'sendNTPpacket' function. It checks for the socket, and creates one if none exists.

`int success = _udp->beginPacket(host, 123); //NTP requests are to port 123;

while (!success) { Serial.println("no socket, let's create one"); success = _udp->begin(2390); if (!success) return; //try later again success = _udp->beginPacket(host, 123); //NTP requests are to port 123 }`

sandeepmistry commented 6 years ago

@w3p706 thanks for the feedback. Is there any reason you didn't just call gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD); after the GPRS connection is lost?

@FrancMunoz did you get a chance to try these changes?

w3p706 commented 6 years ago

@sandeepmistry I use the same method for the first connection as for the case when the connection is lost. As I see begin will start over with READY_STATE_CHECK_SIM and PIN-Unlock and so on. I should probably investigate further, and first try attachGPRS.

FrancMunoz commented 6 years ago

@sandeepmistry, for me it's working too! After a couple of weeks it reconnects and no hangs. Also, I use gprs.attachGPRS as @w3p706 does, do you know a better alternative? (I guess I should investigate further as @w3p706 says).

Thank you!

Rocketct commented 6 years ago

Hi @sandeepmistry I have test your code and it works fine, in order to achieve a GPRS status variation i have impose in a first test a dethachGPRS and in second test simply removed the SIM, in both case the GPRS status return the state of ERROR and GMS::isAccessAlive() return a bad value. I have tested also the reconnection through the attachGPRS and it works as expected.