Socket disconnection issue

Hi,
We have SODAQ SARA R412M Board and we are using DU NBIOT sim and established stable connection for NB-IOT. For this project we are using https://www.allthingstalk.com/ platform for sending our sample readings from sensors. The issue is after sending data for once, the socket creation is keeps on failing. Only after reset button pressed it is working fine. Below is code we used for socket creation.

void sendMessageThroughUDP()
{
    DEBUG_STREAM.println();
    DEBUG_STREAM.println("sending message through UDP to ATT");

 //int localPort = 16666; // my addition
    int localPort = 17777;
    int socketID = r4x.socketCreate(localPort);
    DEBUG_STREAM.println(socketID);

    if (socketID >= 7 || socketID < 0) {
        DEBUG_STREAM.println("failed to create socket");
        DEBUG_STREAM.println("the value of failed socket id is");
        DEBUG_STREAM.println(socketID);
        RED();
        delay(1000);
        return;
    }

    DEBUG_STREAM.println("socket created in the device!");

And this is serial monitor output

failed to create socket
the value of failed socket id is
 -1

Please guide us to resolve this problem.

Thanks,
Pratibha

Hi @Priti,

Do you use the latest version of our library? v2.1.0
Can you check that after sending the first message you turn off the modem?
When you want to send a new message, do you check the modem is on?
Do you check you still have an ip address before sending a message?
Sometimes when you check the network if you are attached you need to wait a second more to obtain an ip address before you are able to create a new socket.

Best regards,
Jan

Hi Jan,

We used latest version of library.

Can you check that after sending the first message you turn off the modem?
When you want to send a new message, do you check the modem is on?

Yes, Modem is in ON position. It sends messages for four consecutive days and then stops sending message after four days. There is an error of

failed to create socket
the value of failed socket id is
 -1

Do you check you still have an ip address before sending a message?

Yes.

Thanks,
Pratibha.

Hi @Priti,

It seems you run out of sockets to open.
Can you close all sockets before opening a new one?

Best regards,
Jan

Hi @Jan,

I closed all the possible sockets with help of AT Commands, but still the same issue. The module stops sending the message after 4 days.

Thanks,
Pratibha.

Hi @Priti,

With manually closing the ports you only solve the issue probably temporary.
Can you add inside your code to close all sockets before opening a new one?
You can also turn off the modem completely to force close the sockets and restart the modem to create a new session.

Best regards,
Jan