APNHelper error getting ICCID

Hi,

I’m using @rickkas7’s APNHelper, but sometimes (after reset), it can’t get the SIM ICCID (even though it appears on the serial logs), so it can’t determine which APN select. Is there any modem state where it might fail if a reset is performed?

[10/12/18 - 13:35:05:190] 0000000006 [system] INFO: Power Management Initializing.
[10/12/18 - 13:35:05:191] 0000000013 [system] INFO: State of Charge: 85.77 %
[10/12/18 - 13:35:05:191] 0000000014 [system] INFO: Battery Voltage: 4.08V
[10/12/18 - 13:35:05:193] 0000000014 [system] TRACE: Hello from Particle!
[10/12/18 - 13:35:05:194] 0000000015 [system] INFO: Device XXXX started
[10/12/18 - 13:35:05:194] 0000000067 [comm] INFO: channel inited
[10/12/18 - 13:35:05:205] Main: Init
[10/12/18 - 13:35:05:205] Main: CSR: 0x14000000
[10/12/18 - 13:35:05:207] 0.068 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:05:208] [ ElectronSerialPipe::begin ] = = = = = = = =
[10/12/18 - 13:35:05:208]
[10/12/18 - 13:35:05:209] [ Modem::powerOn ] = = = = = = = = = = = = = =
[10/12/18 - 13:35:05:503] 0.380 AT send 4 “AT\r\n”
[10/12/18 - 13:35:06:849] 1.700 AT send 4 “AT\r\n”
[10/12/18 - 13:35:08:147] 3.020 AT send 4 “AT\r\n”
[10/12/18 - 13:35:09:467] 4.340 AT send 4 “AT\r\n”
[10/12/18 - 13:35:10:787] 5.660 AT send 4 “AT\r\n”
[10/12/18 - 13:35:12:108] 6.980 AT send 4 “AT\r\n”
[10/12/18 - 13:35:13:423] 8.300 AT send 4 “AT\r\n”
[10/12/18 - 13:35:14:747] 9.620 AT send 4 “AT\r\n”
[10/12/18 - 13:35:15:205] APN: Reading ICCID result=-1, ICCID=
[10/12/18 - 13:35:15:209] APN: Reading ICCID failed ()
[10/12/18 - 13:35:16:067] 10.940 AT send 4 “AT\r\n”
[10/12/18 - 13:35:16:205] 11.079 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:17:381] 12.260 AT send 4 “AT\r\n”
[10/12/18 - 13:35:18:394] [ Modem reset ]
[10/12/18 - 13:35:18:802] 13.680 AT send 4 “AT\r\n”
[10/12/18 - 13:35:18:914] 13.789 AT read UNK 3 “AT\r”
[10/12/18 - 13:35:18:917] ▒6# getICCIDCallback len=3, #AT
[10/12/18 - 13:35:18:924] 13.790 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:19:126] 14.000 AT send 7 “AT E0\r\n”
[10/12/18 - 13:35:19:186] 14.039 AT read UNK 6 “A\xd4 E0\r”
[10/12/18 - 13:35:19:188] #PN: getICCIDCallback len=6, #A▒ E0
[10/12/18 - 13:35:19:189] 14.040 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:19:190] 14.040 AT send 11 “AT+CMEE=2\r\n”
[10/12/18 - 13:35:19:201] 14.079 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:19:202] APN: getICCIDCallback len=6, #
[10/12/18 - 13:35:19:203] OK
[10/12/18 - 13:35:19:203] #
[10/12/18 - 13:35:19:205] APN: Reading ICCID result=-2, ICCID=
[10/12/18 - 13:35:19:206] APN: Reading ICCID failed ()
[10/12/18 - 13:35:20:207] 15.080 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:20:267] 15.120 AT read + 30 “\r\n+CCID: 8944XXXXXXXXXXXXXXX\r\n”
[10/12/18 - 13:35:20:269] 15.121 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:20:270] APN: getICCIDCallback len=6, #
[10/12/18 - 13:35:20:270] OK
[10/12/18 - 13:35:20:271] #
[10/12/18 - 13:35:20:272] APN: Reading ICCID result=-2, ICCID=
[10/12/18 - 13:35:20:273] APN: Reading ICCID failed ()
[10/12/18 - 13:35:21:246] 16.122 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:21:310] 16.162 AT read + 30 “\r\n+CCID: 8944XXXXXXXXXXXXXXX\r\n”
[10/12/18 - 13:35:21:314] 16.173 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:21:315] APN: getICCIDCallback len=6, #
[10/12/18 - 13:35:21:315] OK
[10/12/18 - 13:35:21:316] #
[10/12/18 - 13:35:21:318] APN: Reading ICCID result=-2, ICCID=
[10/12/18 - 13:35:21:319] APN: Reading ICCID failed ()
[10/12/18 - 13:35:22:296] 17.174 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:22:352] 17.214 AT read + 30 “\r\n+CCID: 8944XXXXXXXXXXXXXXX\r\n”
[10/12/18 - 13:35:22:358] 17.225 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:22:361] APN: getICCIDCallback len=6, #
[10/12/18 - 13:35:22:362] OK
[10/12/18 - 13:35:22:363] #
[10/12/18 - 13:35:22:366] APN: Reading ICCID result=-2, ICCID=
[10/12/18 - 13:35:22:387] APN: Reading ICCID failed ()
[10/12/18 - 13:35:23:347] 18.226 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:23:402] 18.266 AT read + 30 “\r\n+CCID: 8944XXXXXXXXXXXXXXX\r\n”
[10/12/18 - 13:35:23:404] 18.267 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:23:405] APN: getICCIDCallback len=6, #
[10/12/18 - 13:35:23:406] OK
[10/12/18 - 13:35:23:406] #
[10/12/18 - 13:35:23:409] APN: Reading ICCID result=-2, ICCID=
[10/12/18 - 13:35:23:411] APN: Reading ICCID failed. Use default configuration
[10/12/18 - 13:35:30:844] 0000025699 [system] INFO: Sim not inserted? Detecting…
[10/12/18 - 13:35:30:844]
[10/12/18 - 13:35:30:845] [ Modem::powerOn ] = = = = = = = = = = = = = =
[10/12/18 - 13:35:31:130] 26.008 AT send 4 “AT\r\n”
[10/12/18 - 13:35:31:160] 26.038 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:370] 26.248 AT send 7 “AT E0\r\n”
[10/12/18 - 13:35:31:410] 26.288 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:411] 26.288 AT send 11 “AT+CMEE=2\r\n”
[10/12/18 - 13:35:31:450] 26.328 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:451] 26.328 AT send 19 “AT+CMER=1,0,0,2,1\r\n”
[10/12/18 - 13:35:31:492] 26.370 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:494] 26.370 AT send 15 “AT+IPR=115200\r\n”
[10/12/18 - 13:35:31:495] 26.372 AT read + 14 “\r\n+CIEV: 2,4\r\n”
[10/12/18 - 13:35:31:526] 26.402 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:624] 26.502 AT send 10 “AT+CPIN?\r\n”
[10/12/18 - 13:35:31:665] 26.542 AT read + 16 “\r\n+CPIN: READY\r\n”
[10/12/18 - 13:35:31:674] 26.552 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:675] 0000026553 [system] INFO: Sim Ready
[10/12/18 - 13:35:31:676] 0000026555 [system] INFO: ARM_WLAN_WD 1
[10/12/18 - 13:35:31:676]
[10/12/18 - 13:35:31:676] [ Modem::init ] = = = = = = = = = = = = = = =
[10/12/18 - 13:35:31:677] 26.554 AT send 9 “AT+CGSN\r\n”
[10/12/18 - 13:35:31:715] 26.594 AT read UNK 19 “\r\n35316XXXXXXXXXX\r\n”
[10/12/18 - 13:35:31:726] 26.604 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:727] 26.604 AT send 9 “AT+CGMI\r\n”
[10/12/18 - 13:35:31:765] 26.644 AT read UNK 10 “\r\nu-blox\r\n”
[10/12/18 - 13:35:31:776] 26.654 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:776] 26.654 AT send 9 “AT+CGMM\r\n”
[10/12/18 - 13:35:31:816] 26.694 AT read UNK 13 “\r\nSARA-G350\r\n”
[10/12/18 - 13:35:31:826] 26.704 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:827] 26.704 AT send 9 “AT+CGMR\r\n”
[10/12/18 - 13:35:31:847] 26.744 AT read UNK 9 “\r\n08.70\r\n”
[10/12/18 - 13:35:31:903] 26.754 AT read OK 6 “\r\nOK\r\n”
[10/12/18 - 13:35:31:904] 26.754 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:31:917] 26.794 AT read + 30 “\r\n+CCID: 8944XXXXXXXXXXXXXXX\r\n”
[10/12/18 - 13:35:31:935] 26.806 AT read OK 6 “\r\nOK\r\n”

Thank you

If it helps, It seems that it only works if the last message isn’t received:

Doesn’t work:

[10/12/18 - 13:35:20:207] 15.080 AT send 9 “AT+CCID\r\n”
[10/12/18 - 13:35:20:267] 15.120 AT read + 30 “\r\n+CCID: 8944XXXXXXXXXXXXXXX\r\n”
[10/12/18 - 13:35:20:269] 15.121 AT read OK 6 “\r\nOK\r\n”

Works:

[10/12/18 - 17:50:50:372] APN: Reading ICCID failed ()
[10/12/18 - 17:50:50:373] 17.391 AT send 9 “AT+CCID\r\n”
[10/12/18 - 17:50:50:412] 17.431 AT read + 30 “\r\n+CCID: 8944XXXXXXXXXXXXXXX\r\n”
[10/12/18 - 17:50:50:412] APN: getICCIDCallback len=30, #+CCID: 8944XXXXXXXXXXXXXXX#

But I don’t know why sometimes it gets the “OK” and sometimes the valid CCID…