Detecting deactivated SIM

Is there a way for a device to detect when it's disconnected due to a SIM deactivation request? I've tried calling Cellular.command() with "AT+CEREG?\r\n" but I only get an "OK" in response.

If you are monitoring the USB serial debug logs, you might see something like this:

0000075069 [ncp.at] TRACE: > AT+CEREG?
0000075078 [ncp.at] TRACE: < +CEREG: 2,3
0000075078 [ncp.at] TRACE: < OK
0000075079 [ncp.at] TRACE: > AT+UCGED=5
0000075087 [ncp.at] TRACE: < OK
0000075088 [ncp.at] TRACE: > AT+UCGED?
0000075098 [ncp.at] TRACE: < +CME ERROR: no network service

The CEREG:2,3 is the important part, where 3 = registration denied which occurs when the SIM is deactivated. It can occur in other situations as well, however.

One problem is that this error is not propagated up to user firmware.

You only find out about this after blinking green for a while, since the SIM doesn't know it's deactivated at the carrier level until it tries to connect. You should be able to query CEREG that way, but only when connection is in progress or connected. Also the result is in the + response, the line before the OK.

You can also install a log handler that analyzes the log messages looking for the CEREG response. This is not particularly difficult, just a little hacky, but I prefer it to polling for CEREG because it has less chance of interfering with or getting blocked by the system which is also using the modem.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.