Menu

Expand
Rate this page:

Four Best Practices for Cellular Module Registration

As carriers turn off first 2G and then 3G networks in favor of their 4G and 5G infrastructure, many IoT application developers are experiencing connection issues that are typically caused by legacy code written oriented to those older network technologies. This can be a problem when the code is running on modern modem hardware.

These issues can be addressed by putting in place the best practices described in this guide. The techniques discussed center on how the driver checks for modem registration, and the range of possible registrations included in those checks. This guide will show you how to mitigate 2G and 3G switch-offs now, and to put yourself in a position to deal with future network transitions. More than that, these tips will help you build more robust cellular IoT products in general.

What is registration?

Registration takes place when a cellular module successfully connects to a cellular network via a cell tower. Until a modem is registered, it will not be able to establish a data session — a process called attachment — or even exchange SMS traffic. A modem can make multiple registrations depending on which radio access technologies (RATs) it supports and which are made available by the cell tower.

Today there are three registration types:

  • CSD — circuit switched; generally 2G or 3G.
  • GPRS — packet switched; 2G data.
  • EPS — enhanced packet switched; 3G or LTE.

As you can see, these types span generations of cellular network standards. CSD (Circuit Switched Data) was defined for 2G but was supported by 3G, which also introduced EPS (Evolved Packet System) — now the chosen mode for LTE (4G and 5G). GPRS (General Packet Radio Service) was introduced under 2G as a data-centric faster alternative to CSD. For this reason it was sometimes called 2.5G.

A modem can use any or all of these registration modes provided it supports the underlying standards. For example, an LTE-only modem can only register in EPS mode. Very old modems might only be able to register in CSD mode.

Similarly, as cellular carriers turn off their older networks, you’ll find that even modems which support the full range of 2G to 4G communications will not be able to use GPRS or CSD registration in areas where 2G and 3G networks are no longer available. For the purposes of connecting such a modem, that’s fine. Only a single registration is required to commence normal operations.

Unfortunately, older code may miss this because it doesn’t check all of the possible registration modes. Until recently, 2G was so ubiquitous that some modem drivers assumed that it was sufficient to check for CSD registration to determine whether or not the modem was connected — and therefore whether to initiate a data session. But if there is no 2G or 3G network, this assumption becomes false. A device capable of an LTE connection may never begin a data session because the driver, checking only for CSD, believes the modem is disconnected.

Best Practice 1

Check the status of all three registrations, and initiate communications when any registration is reported

How to check registration status

The 3GPP has defined AT commands that can be issued to any modem to determine the registration status for each of the current RATs:

  • CSD — AT+CREG?
  • GPRS — AT+CGREG?
  • EPS — AT+CEREG?

Because AT Commands can be chained into a single command, issue all of these commands together:

AT+CREG?;+CGREG?;+CEREG?

The result will be a series of responses of the form:

+CREG=<urc_mode>,<registration_state>[,<additional_information>]
+CGREG=<urc_mode>,<registration_state>[,<additional_information>]
+CEREG=<urc_mode>,<registration_state>[,<additional_information>]

The key property in each response is <registration state>. It is an integer; the values 1 and 5 indicate the modem is registered using that RAT. 1 indicates that the modem is registered with its home network, 5 that the modem is registered but on a visited network, i.e., one that it’s roaming on.

If none of these responses indicate a registration state of 1 or 5, then the modem is not connected to a network. If just one of them reports a registration state of 1 or 5, then the modem is connected and is therefore potentially able to host a data connection.

Connection is not immediate. With Super SIM, typically you will see state 2 (searching), and then 5 (registered, roaming) upon connection. Sometimes you may briefly see state 3 (rejected), but this is usually followed by a return to state 2.

Once a modem is registered on a network, the optional property <additional_information> may include the cell ID and the specific RAT in use. The data included is modem specific, so you should consult your modem’s manual for details.

Lastly, the value of the <urc_mode> property indicates whether the response was issued automatically as an unsolicited response code (URC) or as a result of a manual call.

Best Practice 2

Enable the automatic issue of registration URCs at boot time

How to enable registration URCs

Again, enable registration URCs using 3GPP commands that are available with all modems. Apply Best Practice 1 and issue the relevant AT commands together:

AT+CREG=2;+CGREG=2;+CEREG=2

The value 2 means “issue reports automatically by URC with extended information”. From this point, the modem will send +CREG/+CGREG/+CEREG URCs like those described earlier whenever the modem’s registration states change. Only a change in registration state will cause the modem to report the new registration state.

This is the quickest way for your application to determine registration state.

Some applications choose to poll for registration state information by periodically calling AT+CREG?;+CGREG?;+CEREG? but you should avoid this approach because it means that there will always be a time when a modem is no longer registered but the application has yet to learn that this is the case. Instead, keep your state machine up to date by using URCs and parsing them as they are received.

The URC setting is not recorded in the modem’s non-volatile storage, so you will need to issue the configuration command every time the modem is powered up.

On some modems, you may need to configure the URC output port too. For example, Quectel modems default to outputting URCs via the USB AT command port, so if the serial port is being used by the device, you need to update the configuration to reflect this. To do so, issue this command:

AT+QURCCFG="urcport","uart1"

This configuration is persisted in non-volatile and so only needs to be performed once. However, doing so at every boot should not cause issues.

Please consult your modem’s documentation for the command for your particular hardware.

Best Practice 3

Allow the modem time to connect…

All modems, in any operational mode, will always attempt to connect if they are disconnected. So at power up or upon registration loss, your application should always wait for registration and resist the temptation to “speed things up” by sending additional commands to the modem. On the contrary, these commands will almost always slow things down.

Best Practice 4

…but not an infinite amount of time

That said, modems are not perfect and can experience problems which prevent them from connecting. For this reason, it’s important to put in place a timeout which, when reached without successful registration, will turn the modem off and on again to restore it to a fresh state.

This timeout should not be shorter than 30 minutes. Under certain outage scenarios, it may take a significant amount of time for the modem to iterate through all of the connectivity options provided by Super SIM, and your application should allow all of these options to be exercised before assuming the modem has crashed and thus triggering a reboot.

If a troubled modem is still responding to AT commands, you should use its documented clean power down command — for example, AT+QPOWD on Quectel and Simcom modems. This ensures that the modem’s internal file system state is correctly preserved.

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.

Thank you for your feedback!

Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

Refer us and get $10 in 3 simple steps!

Step 1

Get link

Get a free personal referral link here

Step 2

Give $10

Your user signs up and upgrade using link

Step 3

Get $10

1,250 free SMSes
OR 1,000 free voice mins
OR 12,000 chats
OR more