Network connection failure R4X - Sodaq Sara SFF


I am using Sodaq Sara SFF R412M board with the Sodaq R4X library to connect to the network for some socket, http and mqtt based communications. What happens is that every time I try to connect the board to network it fails to do so. I am using the R4X http example code as reference in my application, here is the code.

I have already checked if my device firmware is new version or an old version, here is it.



Please let me know what is it that I am doing wrong.

Hi Authority,

Please go into the R4X library (you can control+click on the r4x.connect() function) and look for the DEBUG toggle in the top of the file. Enable this and let us know what information you get.


Hey, thanks for the response. I found the debug option in cpp file and I was able to connect to network successfully. Currently, I am stuck here. I tried using IP and DNS both and its not working.

8:02:00.057 → >> AT+CGATT?
18:02:00.057 →
<< +CGATT: 1
18:02:00.057 → << OK
18:02:00.057 → >> AT+CSQ
18:02:00.057 →
<< +CSQ: 9,99
18:02:00.057 → << OK
18:02:00.057 → >> AT+CGDCONT?
18:02:00.057 →
<< +CGDCONT: 1,“IP”,“wm”,“”,0,0,0,0
18:02:00.092 → << OK
18:02:00.092 → >> AT+USOCO=1,“”,80
18:02:00.092 →
<< +CME ERROR: Operation not supported
18:02:00.092 → Failed to connect to server!
18:02:00.092 →

Here is the code for review.

Hi Authority,

You must create a socket before opening it.
See int Sodaq_R4X::socketCreate(uint16_t localPort, Protocols protocol).


I don’t what was the problem but it was resolved without having to change anything in the code. Just to let others know.

CGATT was continuously 0, previously but it went 1 automatically. Took me some time to do some changes and try it, but current version looks like this.

See int Sodaq_R4X::socketCreate(uint16_t localPort, Protocols protocol) .

Thanks for that… I thought it was for creating server sockets, rather than client on TCP mode.

I’ll try this out.

Thanks for all the help.

Network communication is working perfectly now. You can close the thread.

Hey Thom,

Interestingly during field tests today, I found out that the socket communication is only happening once. I mean that after it creates the socket then connect to server, it sends data and read the response from server only once and after that it just enters into a timeout loop. Would you guide me what is wrong here?

This is correct response:

7:41:24.579 → << OK
17:41:24.579 → HTTP/1.1 200 OK
17:41:24.579 → Server: nginx
17:41:24.579 → Date: Thu, 25 Feb 2021 16:41:24 GMT
17:41:24.579 → Content-Type: application/json
17:41:24.579 → Transfer-Encoding: chunked
17:41:24.579 → Connection: close
17:41:24.579 → Allow: GET, POST, HEAD, OPTIONS
17:41:24.579 → Vary: Origin, Cookie

17:41:24.579 → {“dip”: [{“status_code”: 201}], “diq”: [{“status_code”: 201}], “position”: [{“status_code”:201}], “sat”: [{“status_code”: 201}], “spp”: [{“status_code”: 201}], “spq”: [{“status_code”:201}]}
17:41:24.579 → 0
17:41:24.579 →
17:41:24.579 →
17:41:24.579 → >> AT
17:41:24.579 → << OK
17:41:24.579 → >> AT+USOCTL=0,11
17:41:24.579 → << +USOCTL: 0,11,1
17:41:24.579 → << OK
17:41:24.865 → >> AT
17:41:24.865 → << OK
17:41:24.903 → >> AT+USOCTL=0,11
17:41:24.903 → << +USOCTL: 0,11,1
17:41:24.903 → << OK
17:41:25.183 → >> AT
17:41:25.183 → << +UUSOCL: 0
17:41:25.183 → Unsolicited: Socket 0
17:41:25.183 → << OK
17:41:25.183 → >> AT+USOCL=0
17:41:25.183 → << +CME ERROR: Operation not allowed
17:41:25.217 → >> AT
17:41:25.217 → << OK
17:41:55.201 → Getting GPS fix.

Then these are the responses i get.

17:42:00.036 → Sending data to ubidots server.
17:42:00.036 → >> AT+USOCR=6,80
17:42:00.036 → << +CME ERROR: No connection to phone

17:44:12.044 → >> AT+USOCR=6,80
17:44:12.044 → << timed out
17:46:26.291 → >> AT+USOCR=6,80
17:46:26.291 → << timed out

and this continues every time i try to send data.

Hi Authority,

I should start by noting that the local port does not care about the remote port. You can set this to 0, it will randomize a local port.

It seems that you try to close the socket before checking for any further URC’s, or, well, we are.
Add this line after socketFlush(socketID); @ line 698.
if(_socketClosedBit[socketID]) return true;

This is a minor annoyance, I’ll flag it internally.

You should also check the return value of socketCreate, if it is SOCKET_FAIL or -1 you should not continue.

As to why your AT+USOCR keeps failing, this is likely because you try to create a socket without having a connection. Your sendViaSocket() should only be called if r4x.isConnected(), not after creating a socket.


Your sendViaSocket() should only be called if r4x.isConnected() , not after creating a socket.

I tried that but in this case all I get is: CGATT? timed out every time instead of sending the data to server even once.

I did notice the socketFlush() and didn’t use it cuz it was redundant while using socketClose() i’ll flag it as you have suggested, or should i wait for library updates.

I will also remove the port while creating socket. I thought that since i was communicating on port 80 with server i needed that there.

Thanks for your time again.

Hi Authority,

You don’t need to add it, it’s more of a minor annoyance.

I tried that but in this case all I get is: CGATT? timed out every time instead of sending the data to server even once.

This should not happen. r4x.connect() checks for CGATT to be 1 before considering it a success. Does it work the first time if you do what I suggested?

Could be that the device is entering PSM.


Well i did try with a minor change. I have a global flag isReady = r4x.connect() while connecting to network. I used that flag instead of using r4x.isConnected(). In this it worked once and then it started timeout again. Otherwise if i use r4x.isConnected() it doesnt even work once and just timeout every time i try calling the function. Also this is when i put the socketCreate inside the r4x.isConnected()

Also i did not find any function call for sleep mode or wake up … Is it done automatically without notifying on terminal??

Hi Authority,

No such thing. You can see everything.
Run the following commands:

See if this improves your program.


These 3 command worked wonders… Every thing is in order now. One more thing, does the modem drops network when it is in GPS grab mode. I am using Sodaq Ublox GPS library for gps updates and I found during test that after 3 or 4 successful communication it does not create or connect to socket and after few failures it works normally again…

Hi Authority,

Definitely not. These use separate protocols over different pins (I2C & UART) and do not share the same antenna.
Do be mindful that GPS + Modem may cause the consumption to go too high, but if you use a battery this should be of no concern.

Are you sure the GPS is the cause for this? Think this is happenstance…


I saw the available schematics and yeah confirmed that its completely different protocol. I’ll confirm if it was issue caused by power spikes. Still the operation is only happening after every 30 secs so it should not happen though. I thought GPS is causing this problem because after reviewing my debug messages i found that it only occurs after grabbing the GPS. If I disable the GPS get function then this issue never occurs…

Also should I make these three commands a part of r4x.init() routine?

Hi Authority,

You should make it part of the r4x.init() routine. These settings used to be default off but apparently your provider is pushing power saving to the R412.


Had a discussion with whereversim;

Normally they don’t push such settings but they have a look if for any reason they do for this sim and call back and found they do not send such settings to put module to sleep or power saving mode. But he had two other ideas… 1. He saw that modem is connecting every round about 30 seconds to another operator (Telekom, Vodafone etc.) and when it connected to all of them once, it gets this error; “no connection to phone”. So he suggested to try to connect to only one operator to check whether connections stays stable. 2. Even after terminal displays “no connection to phone” it s connected with 2G and sends some data (between 4 and 8 kb). He is monitoring the traffic for the next 24 hours to see where these data is going.

As far as I know that I am only setting up the APN for one operator and connecting only to it once during the init process. After that it is never called, instead on the existing operator it tries to open a socket comm. Had a try by blacklisting all provider except for Telekom - connection was a bit longer active but after a few minutes same error “no connection to phone”. When checking the WM dashboard SIM is displayed as attached to GPRSM and sending data. Lets see results of traffic monitoring.

After a few minutes with the error it reconnected with network by itself and started posting data to server again… without reboot…

I don’t know if SARA SFF module is itself resetting and connecting to various operators not such thing is seen on the terminal during debugging though. Here I am confused as to why sim is dropping network and saying “no connection to phone” after every few min intervals.

Any input would be appreciated.


I see you have multiple issues.
I have a couple of suggestion:

  1. Update your firmware.
    We just got a new firmware version from ublox. I didn’t look at the change log yet myself. I think you may want to try it out to see if it also fixes some of your bugs. Send an email to support at to get the files.

  2. Check for an IP address

When you are connected, you may not have an IP address. When you get try to open a socket you will get the error no connection to phone.

  1. Compare with our Tracker connect checklist to see if it matches yours.
    bool R4xNetwork::setActive(bool on, bool needCheckConnection) in
    Sodaq_Universal_Tracker/R4xNetwork.cpp at master · SodaqMoja/Sodaq_Universal_Tracker (
    bool Sodaq_R4X::connect(const char* apn, const char* urat, MNOProfile mnoProfile,
    const char* opr, const char* bandMaskLTE, const char* bandMaskNB)
    Sodaq_Universal_Tracker/Sodaq_R4X.cpp at master · SodaqMoja/Sodaq_Universal_Tracker (

Best regards,

Thanks for the feedback. I have sent an email to support waiting for the reply. I saw the method you have suggested, I will apply accordingly using that as reference.

I have another question, the sim I am using is multi network should it effect the module in any case. For e.g. as I mentioned above it tries to connect to each network once and send the data successfully, but as soon as it tries to do so again it fails and after some time it automatically starts sending without having to reboot the module. This is interesting as my application need the module to connect to which ever network is available in nearby vicinity and send data to server. Does it require to call connect function again and again?