NB-IoT AT Commands

The SODAQ NB-IoT shield is using the uBlox Sara Nxx series NB-IoT module, which is based on the Neul chipset.
The full AT Command manual can be dowloaded here.
SARA-N2_ATCommandsManual_(UBX-16014887)

The Neul chipset is controlled by AT Commands. These are ASCII commands that are sent to the module over the serial interface at 9600bps.
If the command is executed correctly, the module replies with OK.

Sketch:

#include "Arduino.h"

#if defined(ARDUINO_AVR_LEONARDO)
#define USB Serial 
#define UBLOX Serial1

#elif defined(ARDUINO_SODAQ_EXPLORER)
#define USB SerialUSB
#define UBLOX Serial

#elif defined(ARDUINO_SAM_ZERO)
#define USB SerialUSB
#define UBLOX Serial1

#else
#error "Please select a Sodaq ExpLoRer, Arduino Leonardo or add your board."
#endif

// Pin to turn on/off the nb-iot module
#define powerPin 7 
unsigned long baud = 9600;  //start at 9600 allow the USB port to change the Baudrate


void setup() 
{
  // Turn the nb-iot module on
  pinMode(powerPin, OUTPUT); 
  digitalWrite(powerPin, HIGH);

  // Start communication
  USB.begin(baud);
  UBLOX.begin(baud);
}

// Forward every message to the other serial
void loop() 
{
  while (USB.available())
  {
    uint8_t c = USB.read();
    UBLOX.write(c);
  }

  while (UBLOX.available())
  {     
    USB.write(UBLOX.read());
  }

  // check if the USB virtual serial wants a new baud rate
  if (USB.baud() != baud) {
    baud = USB.baud();
       UBLOX.begin(baud);
  }
}

Below are all the commands you need to establish a connection and send and receive data over NB-IoT.

You can reboot to bring it into a ‘clean’ mode by:

AT+NRB

Switch scrambling is off (since this is not supported in the backend yet):

AT+NCONFIG=CR_0354_0338_SCRAMBLING,FALSE
AT+NCONFIG=CR_0859_SI_AVOID,FALSE

You can check if these settings are now on FALSE by the following command:

AT+NCONFIG?

Switch the radio off by:

AT+CFUN=0

Then select the CDP (in this case Ocean Connect on the T-Mobile platform).

AT+NCDP=172.16.14.22

Then set the APN for authentication (again this is for the T-Mobile Netherlands platform)

 AT+CGDCONT=1,"IP","oceanconnect.t-mobile.nl"

Then switch on the radio. The previous commands are ‘sticky’ (stored in NVRAM) so only need to be entered once.
Next time you can just start with this command:

AT+CFUN=1

Then select the right band (in case of T-Mobile BAND 8)

AT+NBAND=8

Forces an attempt to select and register with the network operator (20416 is T-Mobile NL)

AT+COPS=1,2,"20416"

You can now check the signal quality. Keep repeating this until you get something else than 99,99.

AT+CSQ

You can now check if you are attached to the network. If you get a value of 1 you are!

AT+CGATT?

You can check your IP address. This is from a private IP range.

AT+CGPADDR

You can ping the CDP if you like:

AT+NPING=172.16.14.22

You are now ready to send the first message. You can first switch on the Send Message Indicator (optionally)

AT+NSMI=1

And send a message (in this case 11 bytes, encode in HEX)

AT+NMGS=11,48656c6c6f20576f726c64

Check you send message queue:

AT+NQMGS

Here are a few more commands.
Check the manufacturer of the module:

AT+CGMM

Check the firmware version:

AT+CGMR

Check the IMEI Number

AT+CGSN=1

Display network statistics:

AT+NUESTATS