Skip to content

Avoid to unlock the Sim if already unlocked #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/ArduinoCellular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,32 @@ SimStatus ArduinoCellular::getSimStatus(){
this->debugStream->println("SIM Status: " + String(simStatus));
}

if (modem.getSimStatus() == 0) {
if (simStatus == 0) {
return SimStatus::SIM_ERROR;
} else if (modem.getSimStatus() == 1) {
} else if (simStatus == 1) {
return SimStatus::SIM_READY;
} else if (modem.getSimStatus() == 2) {
} else if (simStatus == 2) {
return SimStatus::SIM_LOCKED;
} else if (modem.getSimStatus() == 3) {
} else if (simStatus == 3) {
return SimStatus::SIM_ANTITHEFT_LOCKED;
} else {
return SimStatus::SIM_ERROR;
}
}

bool ArduinoCellular::unlockSIM(String pin){
if(this->debugStream != nullptr){
this->debugStream->println("Unlocking SIM...");
int simStatus = modem.getSimStatus();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this shadowing the global simStatus ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I had an issue with visualization, everything is ok 🙂

if(simStatus == SIM_LOCKED) {
if(this->debugStream != nullptr){
this->debugStream->println("Unlocking SIM...");
}
return modem.simUnlock(pin.c_str());
}
return modem.simUnlock(pin.c_str());
else if(simStatus == SIM_ERROR || simStatus == SIM_ANTITHEFT_LOCKED) {
return false;
}
/* SIM is ready */
return true;
}

bool ArduinoCellular::awaitNetworkRegistration(){
Expand Down
Loading