Skip to main content
All CollectionsGetting startedBasic connectivity tests
How to test connectivity with AT commands
How to test connectivity with AT commands

By using the AT command sequence, you can establish a data connection to Onomondo to test modem connectivity.

Jason Godfrey avatar
Written by Jason Godfrey
Updated over a month ago

This article requires knowledge of how to connect to your device’s cellular module/modem. Please refer to the user manual or visit the manufacturer's website for specific instructions.


The AT command test sequence

Once you are connected to your device’s cellular module/modem, you are ready to test whether it can attach to a network. Here is 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

In the following sections, we will go through this process step-by-step.


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. If the connection is established, the modem should respond: OK.

AT 
OK

This step is not strictly needed, but is good to go through it first, so that you are sure that 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 2G/3G modems.

If you are using modems with both types of technology or you are unsure which ones apply to your device, use both commands.

AT+CEREG? 
+CEREG: 1,5
OK

The modem will respond with a set of digits. The x in the x,5 part indicates the Unsolicited Response Code (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:

AT+CGREG overview

AT+CEREG overview


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

AT+CGREG=1 and AT+CEREG=1 activate the 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 its 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 modem documentation for more information.

5. AT+CGDCONT=1,”IP”,”onomondo”

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

Make sure the context type is set to "IP" and not "IPV4V6", when setting the APN to avoid issues on networks.

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).

NB: Sending data, using AT commands, varies among modem manufacturers, unless you are using a PPP connection through dial-up. In order to test sending data - please consult the documentation for your particular modem.

Additionally, the activation of the PDP context usually has to be done using a proprietary AT command if you want to use any of the modem's proprietary commands, e.g. pinging or establishing a TCP connection.


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:

SIMCom SIM7020 uses AT+CIPPING: SIM7020 Series_AT Command Manual_V1.01

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 check 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.

Clear 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 article: 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 the technical specifications.

Still no connection?

If you are not getting the expected results - reach out to [email protected].

Please provide the details of the problem, any logs from your tests, as well as contextual information, e.g. what device and modem are you using. The more information we have, the better we can work together to solve your issues.


* Unsolicited Response Codes are codes used in various communication protocols to indicate a response that was not directly requested by the recipient. These codes are typically sent without prior solicitation from the receiving end. In networking, for instance, unsolicited responses can include status updates, notifications, or alerts that are sent autonomously by a device or server.

Did this answer your question?