Unable to upload data on NB-IOT network

Hi,
We have SODAQ SARA R412M Board and we are using DU NBIOT sim for sending some sensor data to the thingspeak website. Also checked with our network provider ,Du for the connectivity which is working fine and the sim is connected to the NBIOT network.

Our problem is that we are able to connect with the network but not be able to send data to the website. This code works well when we change some parameter for GPRS and at that time sim got connection to the GPRS.

The following is the code we are using to send data to website.

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

#define CONSOLE_STREAM   SerialUSB
#define MODEM_STREAM     Serial1

#define DUIOT
#if defined(DUIOT)
#define CURRENT_APN      "duiot"
#define CURRENT_OPERATOR  AUTOMATIC_OPERATOR             
#define CURRENT_URAT     SODAQ_R4X_NBIOT_URAT                                           //UNCOMMENT FOR NBIOT
//#define CURRENT_URAT      SODAQ_R4X_LTEM_URAT                                         //UNCOMMENT FOR 2G
#define CURRENT_MNO_PROFILE MNOProfiles::STANDARD_EUROPE
#define NBIOT_BANDMASK "524420"
#else 
#error "Please define a operator"
#endif

#define HTTP_HOST        "api.thingspeak.com"
#define HTTP_PORT        80
#define HTTP_QUERY       "/update?api_key=XXXXXXZXDF&field1=70&field2=41"



static Sodaq_R4X r4x;
static Sodaq_SARA_R4XX_OnOff saraR4xxOnOff;
static bool isReady;


void setup()
{
    CONSOLE_STREAM.begin(115200);  
    MODEM_STREAM.begin(r4x.getDefaultBaudrate());

    r4x.setDiag(CONSOLE_STREAM);
    r4x.init(&saraR4xxOnOff, MODEM_STREAM);

    isReady = r4x.connect(CURRENT_APN, CURRENT_URAT, CURRENT_MNO_PROFILE, CURRENT_OPERATOR,  NBIOT_BANDMASK, NBIOT_BANDMASK);
    CONSOLE_STREAM.println(isReady ? "Network connected" : "Network connection failed");

 

    CONSOLE_STREAM.println("Setup done");



    if (isReady) {
        downloadFile();
    }


}


void loop()
{
    if (CONSOLE_STREAM.available()) {
        int i = CONSOLE_STREAM.read();
        CONSOLE_STREAM.write(i);
        MODEM_STREAM.write(i);
    }

    if (MODEM_STREAM.available()) {
        CONSOLE_STREAM.write(MODEM_STREAM.read());
    }

     downloadFile();
     sodaq_wdt_safe_delay(100000);

}

void downloadFile()
{
    char buffer[2048];
    uint32_t i = r4x.httpGet(HTTP_HOST,HTTP_PORT, HTTP_QUERY, buffer, sizeof(buffer));

    CONSOLE_STREAM.print("Read bytes: ");
    CONSOLE_STREAM.println(i);

        if (i > 0) {
            buffer[i] = 0;
            CONSOLE_STREAM.println("Buffer:");
            CONSOLE_STREAM.println(buffer);
        }
}

And the corresponding serial monitor result is as follows.

Network connected
Setup done
Read bytes: 0

Please help us to find the mistake.

Hi @Priti ,

The used settings seem correct.

Can you enable the debug in the R4X library?
Remove // in front of #define DEBUG in Sodaq_R4X.cpp
Can you share the debug output? Hopefully we can then maybe see why NB-IoT isn’t working.

Best regards,
Jan

Hi,
Thanks for the response. We did as per requirement.
The following is the result we got from the Serial Monitor.

14:34:39.945 -> [init] started.
14:34:39.945 -> [initBuffer]
14:34:41.933 -> >> AT
14:34:41.933 -> 
<< timed out
14:34:42.444 -> >> AT
14:34:42.444 -> 
<< timed out
14:34:42.957 -> >> AT
14:34:42.957 -> 
<< timed out
14:34:43.437 -> >> AT
14:34:43.437 -> 
<< timed out
14:34:43.950 -> >> AT
14:34:43.950 -> 
<< timed out
14:34:44.425 -> >> AT
14:34:44.425 -> 
<< timed out
14:34:44.936 -> >> AT
14:34:44.936 -> 
<< AT

14:34:45.347 -> << OK
14:34:45.856 -> << timed out
14:34:47.085 -> << timed out
14:34:47.085 -> >> AT+CMEE=2
14:34:47.085 -> 
<< AT+CMEE=2

14:34:47.085 -> << OK
14:34:47.085 -> >> AT+UGPIOC=16,255
14:34:47.085 -> 
<< AT+UGPIOC=16,255

14:34:47.119 -> << OK
14:34:47.119 -> >> ATE0
14:34:47.119 -> 
<< ATE0

14:34:47.119 -> << OK
14:34:47.119 -> >> AT+CFUN?
14:34:47.119 -> 
<< +CFUN: 1
14:34:47.119 -> << OK
14:34:47.119 -> >> AT+UMNOPROF?
14:34:47.119 -> 
<< +UMNOPROF: 100
14:34:47.119 -> << OK
14:34:47.119 -> >> AT+URAT?
14:34:47.119 -> 
<< +URAT: 8
14:34:47.153 -> << OK
14:34:47.153 -> >> AT+UBANDMASK?
14:34:47.153 -> 
<< +UBANDMASK: 0,524420,1,524420
14:34:47.153 -> << OK
14:34:47.153 -> >> AT+COPS=3,2
14:34:47.153 -> 
<< OK
14:34:47.153 -> >> AT+COPS?
14:34:47.153 -> 
<< +COPS: 0
14:34:47.153 -> << OK
14:34:47.153 -> >> AT+CGDCONT?
14:34:47.153 -> 
<< +CGDCONT: 1,"IP","duiot","0.0.0.0",0,0,0,0,0,0
14:34:47.187 -> << +CGDCONT: 2,"IPV4V6","duiot","0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0",0,0,0,0,0,0
14:34:47.187 -> << +CGDCONT: 3,"IPV6","duiot","0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0",0,0,0,0,0,0
14:34:47.187 -> << +CGDCONT: 4,"IP","duiot","0.0.0.0",0,0,0,0,0,0
14:34:47.187 -> << OK
14:34:47.187 -> >> AT+CSQ
14:34:47.187 -> 
<< +CSQ: 99,99
14:34:47.187 -> << OK
14:34:47.699 -> >> AT+CSQ
14:34:47.699 -> 
<< +CSQ: 99,99
14:34:47.699 -> << OK
14:34:49.199 -> >> AT+CSQ
14:34:49.199 -> 
<< +CSQ: 99,99
14:34:49.199 -> << OK
14:34:51.703 -> >> AT+CSQ
14:34:51.703 -> 
<< +CSQ: 27,99
14:34:51.703 -> << OK
14:34:51.703 -> >> AT+CGATT?
14:34:51.703 -> 
<< +CGATT: 1
14:34:51.703 -> << OK
14:34:51.703 -> >> AT+CGDCONT?
14:34:51.703 -> 
<< +CGDCONT: 1,"IP","duiot","10.95.248.156",0,0,0,0,0,0
14:34:51.738 -> << +CGDCONT: 2,"IPV4V6","duiot","0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0",0,0,0,0,0,0
14:34:51.738 -> << +CGDCONT: 3,"IPV6","duiot","0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0",0,0,0,0,0,0
14:34:51.738 -> << +CGDCONT: 4,"IP","duiot","0.0.0.0",0,0,0,0,0,0
14:34:51.738 -> << OK
14:34:51.738 -> >> AT+CPIN?
14:34:51.738 -> 
<< +CPIN: READY
14:34:51.738 -> << OK
14:34:51.738 -> Network connected
14:34:51.738 -> Setup done
14:34:52.015 -> >> AT+UHTTP=0
14:34:52.015 -> 
<< OK
14:34:52.433 -> >> AT+UDELFILE="http_last_response_0"
14:34:52.433 -> 
<< OK
14:34:52.433 -> >> AT+UHTTP=0,1,"api.thingspeak.com"
14:34:52.433 -> 
<< OK
14:34:52.433 -> >> AT+UHTTPC=0,1,"/update?api_key=W7CA5OMC4143G3QF&field1=25&field2=-405&field3=-352&field4=-673&field5= nan",""
14:34:52.433 -> 
<< OK
14:34:52.467 -> >> AT
14:34:52.467 -> 
<< OK
14:34:52.502 -> >> AT
14:34:52.502 -> 
<< +UUHTTPCR: 0,1,0
14:34:52.502 -> Unsolicited: UUHTTPCR: 1: 0
14:34:52.502 -> << OK
14:34:52.502 -> [ERROR]: An error occurred with the http request!
14:34:52.502 -> Read bytes: 0
14:34:52.502 -> >> AT+UHTTP=0
14:34:52.502 -> 
<< OK
14:34:52.536 -> >> AT+UDELFILE="http_last_response_0"
14:34:52.536 -> 
<< OK
14:34:52.536 -> >> AT+UHTTP=0,1,"api.thingspeak.com"
14:34:52.536 -> 
<< OK
14:34:52.536 -> >> AT+UHTTPC=0,1,"/update?api_key=W7CA5OMC4143G3QF&field1=25&field2=-396&field3=-348&field4=-669&field5=0.00",""
14:34:52.536 -> 
<< OK
14:34:52.536 -> >> AT
14:34:52.536 -> 
<< OK
14:34:52.605 -> >> AT
14:34:52.605 -> 
<< +UUHTTPCR: 0,1,0
14:34:52.605 -> Unsolicited: UUHTTPCR: 1: 0
14:34:52.605 -> << OK
14:34:52.605 -> [ERROR]: An error occurred with the http request!
14:34:52.605 -> Read bytes: 0

Your quick response is very important for us.

With Regards,
Pratibha K

Hi @Priti ,

Here in Europe I know providers who have NB-IoT only support UDP.
Can you verify with DU that TCP is possible over NB-IoT with their sims?

Best regards,
Jan

Hi,

Thank you for your quick response.

We have received message from DU network. Kindly refer below details from DU.

"Not only Europe providers have NB-IoT support only UDP, also du. Unlike GPRS, NB-IoT is not an always on type connection which normally using TCP. NB-IoT is not session oriented, latencies are much higher and the device will enter a power save mode. This is very different to always-on modems with “chatty” protocols like TCP. UDP sockets do not create connections to servers; UDP is a connection-less datagram protocol. Because of this MO messages may not be received by the server and lost. The application should take this in to consideration and provide its own acknowledgements between the UE and server. CoAP is one protocol which can be used on top of UDP to provide this."

I hope you understood the above message and kindly I need your advice for further step.

If we are going to connect with UDP:

  1. What will be the changes to be done in our CODE?
  2. What are the setting changes to be done in SIM/DU?

Regards
Pratibha K

Hi Priti,

A quick solution would be to setup a server that listens on a port for messages. We recommend node-red for simplicity and versatility.
This node-red flow should contain an UDP listener that converts the UDP message received to a HTTP GET response to whatever you’re trying to do now.
In your code you need to change r4x.httpGet to r4x.socketCreate and r4x.socketSend (and probably a r4x.socketClose).

Regards,
Thom

Hi,

Thanks for your advice. Can you please provide us some sample examples? It will be very helpful for our further development.

Regards
Pratibha K

Hi Priti,

Below is a good starting point, import this in your node-red instance.

[{"id":"e64d2814.9c32d8","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"296f4f6d.741ae","type":"udp in","z":"e64d2814.9c32d8","name":"","iface":"","port":"3500","ipv":"udp4","multicast":"false","group":"","datatype":"buffer","x":640,"y":280,"wires":[["d9e5c3ab.13519"]]},{"id":"33792e93.e60d62","type":"http request","z":"e64d2814.9c32d8","name":"","method":"use","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":930,"y":300,"wires":[["c9678c4e.b07ec"]]},{"id":"41633672.dbf6b8","type":"inject","z":"e64d2814.9c32d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":640,"y":320,"wires":[["d9e5c3ab.13519"]]},{"id":"c9678c4e.b07ec","type":"debug","z":"e64d2814.9c32d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1070,"y":300,"wires":[]},{"id":"d9e5c3ab.13519","type":"function","z":"e64d2814.9c32d8","name":"","func":"msg.name = msg.payload;\n\nmsg.url = \"api.thingspeak.com/update?\";\n\n//Demo:\nmsg.url += \"api_key=XXXXXXZXDF&field1=70&field2=41\"\n//You probably want below:\n//msg.url += message.payload;\n\nmsg.method=\"GET\";\n\nmsg.headers = {};\n\nmsg.payload = \"\";\n\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":300,"wires":[["33792e93.e60d62"]]}]

Tweak the function node to make it behave as you want it to.

Regards,
Thom