8000 GSM: fix context initialization when client method is called before G… · arduino/ArduinoCore-mbed@c597242 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c597242

Browse files
committed
GSM: fix context initialization when client method is called before GSM.begin()
1 parent 4e2e81c commit c597242

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

libraries/GSM/src/GSM.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
5050
reset();
5151
}
5252

53-
_context = mbed::CellularContext::get_default_instance();
53+
if (!_context) {
54+
_context = mbed::CellularContext::get_default_instance();
55+
}
5456

5557
if (_context == nullptr) {
5658
DEBUG_ERROR("Invalid mbed::CellularContext");
@@ -117,7 +119,10 @@ void arduino::GSMClass::end() {
117119
}
118120

119121
int arduino::GSMClass::disconnect() {
120-
return _context->disconnect();
122+
if (_context) {
123+
return _context->disconnect();
124+
}
125+
return 0;
121126
}
122127

123128
unsigned long arduino::GSMClass::getTime()
@@ -144,9 +149,12 @@ bool arduino::GSMClass::isConnected()
144149
}
145150
}
146151

147-
148-
149152
NetworkInterface* arduino::GSMClass::getNetwork() {
153+
/* Can happen this is called before GSM.begin( .. ) when configuring GSMSSLClient
154+
* from sketch calling client.appendCustomCACert( .. ) */
155+
if (!_context) {
156+
_context = mbed::CellularContext::get_default_instance();
157+
}
150158
return _context;
151159
}
152160

0 commit comments

Comments
 (0)
0