vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.91k stars 709 forks source link

[SIM7600] getSimStatusImpl() locking for multiple seconds #625

Open simkard69 opened 2 years ago

simkard69 commented 2 years ago

Hello Everyone,

Seems like "getSimStatus()" (related to "getSimStatusImpl()" in file "TinyGsmGPRS.tpp") is locking code for some delay (timeout_ms = 10000L).

Is there any way of avoiding such a time lock ?

Does command "getSimStatus()" actually takes time to complete ?

Attached related code from file "TinyGsmGPRS.tpp"

  SimStatus getSimStatusImpl(uint32_t timeout_ms = 10000L) {
    for (uint32_t start = millis(); millis() - start < timeout_ms;) {
      thisModem().sendAT(GF("+CPIN?"));
      if (thisModem().waitResponse(GF("+CPIN:")) != 1) {
        delay(1000);
        continue;
      }
      int8_t status =
          thisModem().waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"),
                                   GF("NOT INSERTED"), GF("NOT READY"));
      thisModem().waitResponse();
      switch (status) {
        case 2:
        case 3: return SIM_LOCKED;
        case 1: return SIM_READY;
        default: return SIM_ERROR;
      }
    }
    return SIM_ERROR;
  }

Thanks

star297 commented 2 years ago

Depends if there's a working sim inserted at power on. No sim, the modem takes a while to respond. With sim, pretty much straight away.

modem.init() or modem.restart() won't succeed without sim inserted. Both methods only takes a few seconds to complete if sim is inserted on SIM7600 and SIM7000. Call that first then if successful call modem.getSimStatus() if you need it.