How to test modem connectivity using AT commands

10 Nov.,2023

 

Connectivity is a critical element of all Internet of Things (IoT) use cases. You will need to make sure your devices can connect when they are out in the field creating value.

By using this sequence of AT commands, you can establish a data connection and test modem connectivity for your IoT devices.

NB: This article requires knowledge of connecting to your device’s cellular module/modem.

The AT command test sequence

Once you are connected to your device’s cellular module/modem, you are ready to start establishing a connection.

Here’s an overview of our recommended AT Command sequence for establishing a data connection:

  1. AT – checks the connection to the modem
  2. AT+CGREG? and/or AT+CEREG? – queries for the packet-switched network status*
  3. AT+CGREG=1 and/or AT+CEREG=1 – activate the Unsolicited Response Codes for the network status
  4. AT+COPS? – check the current network and selection mode
  5. AT+CGDCONT=1,”PDP type”,”APN” – defines a PDP context
  6. AT+CGACT=1,1 – activate PDP context 1

* Use CGREG for GPRS/EDGE and CEREG for LTE and newer technologies. Or just use both, that’s the sure-fire way to get the status you want.

Establishing a data connection

In order to establish a data connection, follow this sequence of AT commands:

1. AT

AT checks the connection to the modem, it should respond OK.

AT
OK

This step is not strictly needed, but is good to run so that you are sure the connection to the modem is working.

2. AT+CGREG? and/or AT+CEREG?

AT+CGREG? and AT+CEREG? query the packet-switched network status.

Use AT+CEREG? if the modem you are testing with supports LTE or newer technologies. Use AT+CGREG? for GSM modems. If you are using modems with both types of technology, use both.

If you use both commands, the modem will report x,4 to the technology that is currently not active.

If the response is +CGREG: x, 5 or +CEREG: x,5, then your modem is registered to a network and is roaming.

AT+CEREG?
+CEREG: 1,5
OK

The “x” in the x,4 or x,5 part indicates the URC status and is not important for this step.

With Onomondo SIMs, you will always be roaming, which is why the response x,5 is always expected.

You can read full overviews of the packet-switched network status AT commands here:

3. AT+CGREG=1 and/or AT+CEREG=1

AT+CGREG=1 and AT+CEREG=1 activate the Unsolicited Response Codes (URCs) for the packet-switched network status.

AT+CEREG=1
OK

Basically, this tells the modem to respond when the network status changes, without having to check connectivity using AT+CGREG? or AT+CEREG?.

4. AT+COPS?

The AT+COPS? command checks the current network selection mode of the modem. You can read a full overview of the command here: AT+COPS overview.

Onomondo recommends using automatic operator selection to ensure a connection with good enough (-85db) signal quality and reduce the chances of packet loss and other transmission problems. You can read more about automatic network selection and it’s advantages here: Improve coverage with automatic network selection.

Some modems are set to automatic selection mode by default and don’t need to be set manually. If the response is anything other than +COPS: 0, you will want to set it to choose network operator automatically using AT+COPS=0.

AT+COPS?
+COPS: 1

AT+COPS=0
OK

AT+COPS?
+COPS: 0

Beware of manually using AT+COPS=0 after powering on a modem without first using the read command AT+COPS?. It can lead to unforeseen consequences which you can read more about in this developer blog: Why you shouldn’t tell IoT modems to detach/attach.

Note: Some modems/modules have their own automatic selection mode AT command. Consult your specific modem’s documentation for more information.

5. AT+CGDCONT=1,”PDP type”,”APN”

AT+CGDCONT defines the Packet Data Protocol (PDP) context, including PDP type (IP, IPv6, X.25, etc.).

The first parameter is the Context ID, the second is the PDP type, and third is the APN of the operator.

AT+CGDCONT=1,"IP","onomondo"
OK

6. AT+CGACT=1,1

AT+CGACT=1,1 activates PDP context 1.

AT+CGACT=1,1
OK

This sequence should work with any modem that adheres to 3GPP TS 27.007.

Some modems require the use of their proprietary AT commands in order for the PDP context to be registered in the correct way in their own internal state.

For example, you should use AT+QIACT=1,1 for Quectel modems to activate the PDP context for profile 1. Consult your modem’s documentation for more information.

This is a good point to verify that the data connection has been established. In the Onomondo App, you can see this in the Network Logs tab under the SIM page (see example below).

The AT command test sequence in action

Here’s an example of the sequence we have created for testing connectivity in action. Below, you will see the results of the sequence in Onomondo’s Network Logs.

My data connection attached, what’s next?

If you’ve gotten this far, then you are able to send data, and your network connectivity is working.

From here, you can send some data through the network and see the results, something that is achieved using Traffic Monitor at Onomondo, but you can also use Wireshark, for example.

A simple way to test modem connectivity is to send a ping through the modem.

This is not a standard AT command, so each manufacturer slightly differs. You can find the information in the AT command manual of your cellular module.

Some examples:

You can read more about testing connectivity in the article: How to ping your modem using AT commands.

I am not getting the expected results

Here are a couple of common things we recommend you check when a device is not connecting.

Check for available networks

Check for available networks using the AT+COPS=? command.  It returns the current selection mode, operator format, operator, and radio access technology and you should see something that looks like this:

AT+COPS=?
+COPS: <mode>[,<format>,<oper>,[AcT>]]
OK

If you get a result that looks like the one below, then unfortunately your device has no available networks to connect to:

AT+COPS=?
+COPS: ,,(0,1,2,3,4),(0,1,2)
OK

Check the bands/technologies the device can connect to and a coverage map if available. GSMA has a good starting point.

Local base station databases or coverage maps from local providers are, however, usually better.

Clearing the Forbidden Network List (FPLMN)

Typically, when a device attempts to connect to a network and it is not on the network allow list, it will add that network to the SIM’s FPLMN list and will not attempt to connect to that network in the future.

How and when devices write to the SIM’s FPLMN list differ from manufacturer to manufacturer, as well as from product to product. For example, some devices have been seen to write networks to the FPLMN list when they try to connect when the SIM has been deactivated.

For information on how to check whether the list is empty and how to clear it, follow the instructions in this blog: How to clear the FPLMN (forbidden network) list on a SIM.

Delays between AT commands

If your device is finding a network but is having trouble attaching and getting a data connection, it can be good to add a small delay of e.g. 50-100ms between AT commands.

Delay requirements between AT commands can differ from manufacturer to manufacturer, and if needed, they are usually specified in their technical specifications.

Do you still not have a connection?

If you are not getting the expected results, please contact your cellular IoT connectivity provider. Make sure you provide the details of the problem, any logs from your tests, as well as contextual information, e.g. what device and modem you are using.

The more information your connectivity provider has, the easier it will be for them to solve the issue.

Onomondo users can contact our customer success team via this form: contact us.

With high quality products and considerate service, we will work together with you to enhance your business and improve the efficiency. Please don't hesitate to contact us to get more details of Bulk Sms Modem.