R4XX UDP receive

I noticed that there are new libraries available version 2.0.2 so I’m looking how to use these with my R412M AFF board (I was using 1.x before).
What I noticed is that some examples (nbIOT_test_udp) use:

#include “Sodaq_nbIOT.h”
#include “Sodaq_wdt.h”
Sodaq_nbIOT nbiot;

But others examples (http_test) use:

#include <Sodaq_R4X.h>
#include <Sodaq_wdt.h>
Sodaq_R4X r4x;

I tried them both and the one with R4X is working and the other one is not working.

Sending UDP packages from my device is no problem, but I’m confused how to properly receive UDP packages. This is part of my code:

void loop() {
if (MODEM_STREAM.available()) {
if (socketID != -1) {
while (r4x.socketHasPendingBytes(socketID)) {
DEBUG_STREAM.println(“I have pending bytes”);
char data[200];
while (r4x.socketReceive(socketID,(uint8_t*)data,200)) {
DEBUG_STREAM.println(“I’m reading bytes”);
DEBUG_STREAM.println(data);
}
}
}

If I send data to my device, MODEM_STREAM.available becomes true. But the r4x.socketHasPendingBytes does not detect it and remains false.
I could manually perform a MODEM_STREAM.read, but I thought it’s better to use the functions from the library?
The socketID is 0, and when I print the MODEM_STREAM I do get the USORF 0,4. Maybe a bug in the library?

The v2.0.2 of the R4X library only works with the latest version of the ublox firmware.
Do you have the latest firmware on both boards?
https://support.sodaq.com/Boards/Sara_AFF/#r4

Best regards,
Jan

I upgraded from M0.09.XX to M0.10.XX but now it’s even worse:

14:17:34.747 -> setDiag
14:17:34.747 -> r4x.init
14:22:52.723 -> FAILED TO CONNECT TO MODEM

Code:

void setup() {
sodaq_wdt_safe_delay(STARTUP_DELAY);
delay(5000);
DEBUG_STREAM.begin(DEBUG_STREAM_BAUD);
delay(1000);
MODEM_STREAM.begin(r4x.getDefaultBaudrate());
delay(1000);
DEBUG_STREAM.println(“setDiag”);
r4x.setDiag(DEBUG_STREAM);
DEBUG_STREAM.println(“r4x.init”);
r4x.init(&saraR4xxOnOff, MODEM_STREAM);

if (!r4x.connect(apn, urat)) {
  DEBUG_STREAM.println("FAILED TO CONNECT TO MODEM");
} else {
  DEBUG_STREAM.println("Connected to NBIOT network");
}

Modem no longer connects and also AT commands are sporadically working in passthrough mode.

I solved the modem problem by loading my personal sketch (which sets additional modem settings).
The modem connects fine.
After that I reuploaded the r4x example.
The modem now connects fine, but still r4x.socketHasPendingBytes remains false and MODEM_STREAM.available() is true. So problem is still not solved.