+CEREG: 0,4 and then failing to connect?

I have a simple test box running which connects and regularly sends/receives a UDP packet to an echo server.
It all works fine in my office which has a good signal. However if I move the unit to an area with no service it fails to send the udp packet so then tries a connect. This also fails after about 3 minutes.
However if I then move back to a known good signal area (ie my office) it still fails to connect. If I interrogate the module using passthrough I get +CEREG: 0,4. 4 meaning “unknown”? The only way I have found to get it to register and connect again is to issue an AT+CFUN=15 soft reset. It then works fine again.
Any ideas what is going on and how to fix it properly? (the reset means it takes a lot longer to connect).

More info on my setup…
Sara SFF (412M) module, Vodafone Uk nbiot sim with the following settings:
#define CURRENT_APN “ep.inetd.gdsp”
#define CURRENT_OPERATOR “23415”
#define NBIOT_BANDMASK “524288”

eDRX and PSM are turned off with

The code is written using the arduino ide and the Sodaq_R4X library and, to connect does a simple:


and to send the udp packet does a:

socket = r4x.socketCreate(UDP);
sentSize = r4x.socketSend((uint8_t)socket, SERVER_IP, SERVER_PORT, sendingString, sendingStringLength);
if (r4x.socketWaitForReceive(socket)) {
size_t numBytes = r4x.socketGetPendingBytes(socket);
r4x.socketReceive(socket, receivedString, numBytes);

I would recommend testing the connection status (see ::isConnected()) before attempting to send any data. If you are sending data continuously, then you can check the status at a regular interval or after detecting an issue when sending.

You should then call the connect function again if needed. While this might not be the most efficient approach, it should be more reliable.

Thanks Gabriel,
So are you saying that an attempt to open a port and send data when it is not connected is causing the module to get in a state where it does not respond correction to the connect()?
I would like to reduce on time (and battery use) so is there a minimum that is required to detect it is correctly connected? From reading the sodaq_r4x code isConnected() checks if it is attached (“AT+CGATT?”), then signal strength (“AT+CSQ” repeated for up to 10s) then if it has an IP address (“AT+CGDCONT?”). I am particularly concerned about the waitForSignalQuality() which could add a considerable delay if there is no signal?