Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SARA R4 cannot detach from GPRS #118

Open
maxkraft7 opened this issue Nov 3, 2023 · 0 comments
Open

SARA R4 cannot detach from GPRS #118

maxkraft7 opened this issue Nov 3, 2023 · 0 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@maxkraft7
Copy link

maxkraft7 commented Nov 3, 2023

I want to periodically power the cellular module and then shut it down again to save energy. But when I detach it after sending data via a UDP socket, the device becomes unresponsive When it turns on for the second time (when detaching asynchronously) it returns at the AT+CPIN? command. I then get the response Not connected, retying from the function connectToNetwork(). It then indefinetly tries again to open a connection but it doesn't work.

Edit: Removed everything from the code not necessary to replicate this behaviour. Also I added a generous 1 mF of capacitors which greatly improved stability.

It now takes an unknown amount of time to disconnect from the network using gprs.detachGPRS(true); (in synchronous mode). As soon as I have sent the first bytes.

#include <MKRNB.h>
#include <RTCZero.h>


// initialize the library instance
NBClient client;
GPRS gprs;
NB nbAccess(true);
NBUDP udp;

RTCZero rtcZero;

void connectToNetwork(){

    auto connected = false;

    Serial.println(F("init..."));
    while (!connected)
    {
        if ((nbAccess.begin("", "hologram", true, true) == NB_READY) &&
            (gprs.attachGPRS() == GPRS_READY))
        {
            connected = true;
        }
        else
        {
            Serial.println(F("Not connected, retying"));
            delay(200);
        }
    }
}

void disconnectFromNetwork(){
    Serial.println(F("Disconnecting from network"));
    //////////////////////////////////////////////////////////////////////
    gprs.detachGPRS(true); // here the module stops responding indefinetly
    nbAccess.secureShutdown();
}

void setup()
{

    Serial.begin(9600);

    // set time
    connectToNetwork();
    rtcZero.setEpoch(nbAccess.getTime()); 

    disconnectFromNetwork();


    // endless event loop
    while (true)
    {
        Serial.println(F("New interation"));
     
         // do some measurements here every couple hours
        // every day connect to the network and upload them
        connectToNetwork();

        if (udp.begin(80))
        {
            Serial.println("udp socket opened");
            // make a udp request (i know this wouldn't work but for this example it is sufficient)
            udp.beginPacket("example.com", 80);
            // todo send multiple packets if one packet exceeds 300bytes
            udp.write("17 bytes of data", 17); 
            udp.endPacket();
            udp.stop();
        }
        else
        {
            // if you didn't get a connection to the server:
            Serial.println("connection failed");
        }

        disconnectFromNetwork();
        
    }
}

void loop() { }

The response of the device when debug is enabled (and detatching is async) on the second connection is:

init...
AT
OK
AT
OK
AT+CMEE=0
OK
AT+CFUN=0
OK
AT+CPIN?
+CPIN: READY

OK

and after that it just stops.

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Nov 3, 2023
@maxkraft7 maxkraft7 changed the title SARA R4 hangs when powered on again SARA R4 cannot detach from GPRS Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants