Skip to content

Commit eb26ac8

Browse files
committed
handled the case the Opta Cellular is not present
If the Opta Cellular is not present the Opta crashed due to some impossible communication or timeout in the _cellular.unlockSIM() function call With this change if the Cellular is not present no useless call to _cellular.unlockSIM() is performed and this prevent the crash
1 parent 335a553 commit eb26ac8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/CellularConnectionHandler.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,27 @@ static void beginOptaCellular() {
8383

8484
NetworkConnectionState CellularConnectionHandler::update_handleInit()
8585
{
86-
#if defined(ARDUINO_OPTA) && defined(BOARD_HAS_CELLULAR)
86+
#if defined(ARDUINO_OPTA)
8787
beginOptaCellular();
8888
#else
8989
_cellular.begin();
9090
#endif
9191
_cellular.setDebugStream(Serial);
92+
93+
#if defined(ARDUINO_OPTA)
94+
/* in case Opta Cellular is not wired this check on ce prevent the call
95+
to unlockSIM that cause a crash in the Opta (deep due to the missing
96+
communication with the modem) */
97+
if(ce) {
98+
if (String(_pin).length() > 0 && !_cellular.unlockSIM(_pin)) {
99+
Debug.print(DBG_ERROR, F("SIM not present or wrong PIN"));
100+
return NetworkConnectionState::ERROR;
101+
}
102+
}
103+
else {
104+
return NetworkConnectionState::ERROR;
105+
}
106+
#else
92107
if (strlen(_settings.cell.pin) > 0 && !_cellular.unlockSIM(_settings.cell.pin)) {
93108
DEBUG_ERROR(F("SIM not present or wrong PIN"));
94109
return NetworkConnectionState::ERROR;
@@ -98,6 +113,7 @@ NetworkConnectionState CellularConnectionHandler::update_handleInit()
98113
DEBUG_ERROR(F("The board was not able to register to the network..."));
99114
return NetworkConnectionState::ERROR;
100115
}
116+
#endif
101117
DEBUG_INFO(F("Connected to Network"));
102118
return NetworkConnectionState::CONNECTING;
103119
}

0 commit comments

Comments
 (0)