AT Getting started

Getting started with AT commands can be hard, as there are several special cases that needs to be considered based on the device. We've focused on Quectel BG-95, Sara N2** and Nordic Semiconductor nRF9160 as our main "go-to" devices. Below are some simple use cases to get started using these.

Note: Many of the commands might very well be usable on other devices as well.

To continue, we expect you have a serial connection to your device and modem, making it possible to interact with

Is everything OK?

The first command you should ask before doing anything, is a simple AT and your terminator. This is a quick way of deducing if you have some "starter" errors. This is the same for all devices, and when sending AT, you should get the result OK.

AT Debugging

  • No answer?

    Do you have the correct terminator and baud rate? The terminator and baud rate used across the devices differs, and the modem won't stop to process your command unless you send the correct terminator.

  • ERROR as an answer

    If you get an ERROR this early, something's usually very wrong and the modem is having internal problems. HOWEVER, sometimes there's a lingering state from a earlier failed command. Always do an addtional AT after a failed one to see if you can reset that state.

Listing IMEI and IMSI

IMEI and IMSI are needed to register your device in our IoT platform, and it's simple to retrieve these using AT commands.

  • IMEI

    Listing the IMEI from the modem can be achieved by sending the AT command

  • IMSI

    Listing the IMSI from the SIM can be achhieved by sending the AT command


Notes on the nRF9160

  • IMSI

    The nRF91 has a quirk that might confuse some. It's modem functionality is set to minimal by default, which leads to lower power consumption, but limits the functionality of the modem. To get the IMSI you need to set the functionality to "Full functionality" first.

  1. Send AT+CFUN=1
  2. Retrieve the current functionality state by sending AT+CFUN? and confirm that the return value is 1
  3. Send the command AT+CIMI? to list the IMSI from the SIM.

IMEI/IMSI Debugging

  • ERROR as answer

    If you get an ERROR on AT+CIMI?, make sure that your SIM card is properly placed within the SIM holder.

Managing APNs and PDP

APNs are sometimes given by the network and sometimes needs to be set on the modem. When the APN has been set, and activated, the modem will receive an IP from the network and is then able to create a socket to send data to our IoT platform.

Listing set APN and PDPs

An entry is connected to a PDP context, which has an ID, an APN name connected to it, as well as a potential IP/IPv6. To list the PDPs set for the modem you need to send the AT+CGDCONT?

Set new APN and PDP

To set a new APN and PDP context, you need to provide both an context ID where the PDP will be placed on the modem, the type of PDP context, as well as the name of the APN. The command is the SET command of AT+CGDCONT=<context ID>,"Type of context","<apn-name>. For more details, you can see go to the AT+CGDCONT command detail page.

Example setting APN

You want to set the context ID 0, the type, IP and the APN name mda.lab5e.


Notes on Sara N**

To store the set PDP and APN and enable automatic reconnect, you can run


The next time the module reboots, it'll automatically use the saved APN and connect.

Debugging setting APN

If you receive ERROR when running our example AT+CGDCONT=0,"IP","mda.lab5e", this could mean a lot of things, but the usual suspect is looking at the context ID. If you try to run AT+CGDCONT? you can see if there is already a PDP context in the given context ID. You can't overwrite an existing active PDP context, and you'll need to add it to another context ID (ex AT+CGDCONT=1,"IP","mda.lab5e")

Activating and deactivating APNs and PDPs

Sometimes there's multiple APNs available due to either you setting additional APNs manually, or that you get one extra from the network (a feature of nRF9160 and the BG-95). This is where AT+CGACT comes in. To activate or deactivate an APN and PDP context you send 1 or 0 and the ID of the context ID you want to act upon.

NOTE: If you only have one PDP context, it will implicitly be active.

Example deactivating/activating APNs

If you have a context with ID 1 you want to deactivate, you send


If you want to activate the same context again, you can send


Debugging activating APNs and PDPs

If you get an ERROR when trying to activate or deactivate a PDP, there can unfortunately be due to a lot of reasons.

  1. Make sure you do not mix the parameters.

    It can be quite confusing knowing that the context ID is last and that the first parameter is 0 for deactivation and 1 for activation.

  2. The modem already has the state you're trying to set.

    Try asking for the current activation state with AT+CGACT. If you try to set the same state that's already set the modem will give you an ERROR

  3. There's a conflicting state

    If you have an existing PDP you want to deactivate, you need to first activate your new one, and then deactivate the old one. Doing it out of order will return ERROR.

  4. Trying to activate/deactive when there's a single PDP entry

    When you only have a single PDP entry, it's implicitly "primary" and activated. If you try to activate/deactivate it, the modem will return ERROR.

Sending data

Now that we have a PDP context and APN that is activated, you can start sending data. How data sending is handled, is often different depending on your device of choice. We use endpoint values that can be found under our quick reference section.

Nordic Semiconductors nRF9160

To open a UDP socket from the nRF9160, use the command AT#XSOCKET


This will open a socket, which you can use with the AT#XSENDTO command

AT#XSENDTO="",1234,1,"Hello world"

We use our IP and port (, set the data type to plain text (1), and set the payload to be "Hello world". This will send the payload on the active socket we opened earlier.

To clean up and close the socket, use AT#XSOCKET again


Quectel BG-95

To open a socket for the BG-95, use the command AT+QIOPEN


This will open a port on the context ID 0, with a socket ID 0 as a UDP type. We use IP and port (, and allow the modem to choose a local port by providing 0, and use buffer as access mode (0).

You can then use the AT+QISEND command


Which informs the modem to pipe data into the given socket ID and that there's incoming data with the length provided.

Hello world!

Sending the data after, will send the payload.

Sara N2**

To create a new socket send


Then to send the data, set up a socket towards our endpoint, and send the data as hex using AT+NSOST


Note that the payload is hex encoded and that the length (12) is the number of bytes, not the length of the encoded string.

To clean up and close the socket use AT+NSOCL