Skip to content

GSM: remove possibility to set timeout from constructor #869

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 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
- name: ArduinoGraphics
- name: Arduino_GigaDisplayTouch
- name: emWin
- name: Arduino_DebugUtils
additional-sketch-paths: |
- libraries/PDM
- libraries/doom
Expand Down Expand Up @@ -177,6 +178,7 @@ jobs:
fqbn: arduino:mbed:edge_control
additional-libraries: |
- name: MicroNMEA
- name: Arduino_DebugUtils
additional-sketch-paths: |
- libraries/GSM
- libraries/USBHID
Expand Down
21 changes: 17 additions & 4 deletions libraries/GSM/examples/GSMClient/GSMClient.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/*
GSMClient

This sketch connects to a website (https://example.com)
using the Portenta CAT.M1/NB IoT GNSS Shield.

*/

#include <GSM.h>
#include <Arduino_DebugUtils.h>
#include <GSMDebug.h>
#include "arduino_secrets.h"

#include "arduino_secrets.h"
char pin[] = SECRET_PIN;
char apn[] = SECRET_APN;
char username[] = SECRET_USERNAME;
Expand All @@ -13,19 +23,22 @@ GSMClient client;

void setup() {

Serial.begin(9600);
while(!Serial) {}

#if defined(ARDUINO_EDGE_CONTROL)
// Power ON MKR2
pinMode(ON_MKR2, OUTPUT);
digitalWrite(ON_MKR2, HIGH);
#endif

Serial.begin(115200);
while(!Serial) {}

// To enable AT Trace debug uncomment the following lines
//GSM.trace(Serial);
//GSM.setTraceLevel(4);

Debug.setDebugOutputStream(&Serial);
Debug.setDebugLevel(4);

Serial.println("Starting Carrier Network registration");
if(!GSM.begin(pin, apn, username, pass, CATNB, BAND_20 | BAND_19)){
Serial.println("The board was not able to register to the network...");
Expand Down
14 changes: 10 additions & 4 deletions libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*
GSMSSLlient
GSMSSLClient

This sketch connects to a website (https://example.com)
using the Portenta CAT.M1/NB IoT GNSS Shield and TLS.

*/

#include <GSM.h>
#include <Arduino_DebugUtils.h>
#include <GSMDebug.h>
#include "arduino_secrets.h"

#if defined(ARDUINO_EDGE_CONTROL)
Expand All @@ -25,6 +27,9 @@ GSMSSLClient client;

void setup() {

Serial.begin(9600);
while(!Serial) {}

#if defined(ARDUINO_EDGE_CONTROL)
// Power ON MKR2
pinMode(ON_MKR2, OUTPUT);
Expand All @@ -34,13 +39,14 @@ void setup() {
client.appendCustomCACert(root_ca);
#endif

Serial.begin(115200);
while(!Serial) {}

// To enable AT Trace debug uncomment the following lines
//GSM.trace(Serial);
//GSM.setTraceLevel(4);

// Enable GSM library debug
Debug.setDebugOutputStream(&Serial);
Debug.setDebugLevel(4);

Serial.println("Starting Carrier Network registration");
if(!GSM.begin(pin, apn, username, pass, CATM1, BAND_3 | BAND_20 | BAND_19)){
Serial.println("The board was not able to register to the network...");
Expand Down
44 changes: 25 additions & 19 deletions libraries/GSM/examples/GSMSSLClient/root_ca.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
static const char root_ca[] =
"-----BEGIN CERTIFICATE-----\n"
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n"
"MIIEyDCCA7CgAwIBAgIQDPW9BitWAvR6uFAsI8zwZjANBgkqhkiG9w0BAQsFADBh\n"
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdE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20wQAYIKwYBBQUHMAKG\n"
"NGh0dHA6Ly9jYWNlcnRzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RH\n"
"Mi5jcnQwQgYDVR0fBDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQuY29t\n"
"L0RpZ2lDZXJ0R2xvYmFsUm9vdEcyLmNybDA9BgNVHSAENjA0MAsGCWCGSAGG/WwC\n"
"ATAHBgVngQwBATAIBgZngQwBAgEwCAYGZ4EMAQICMAgGBmeBDAECAzANBgkqhkiG\n"
"9w0BAQsFAAOCAQEAkPFwyyiXaZd8dP3A+iZ7U6utzWX9upwGnIrXWkOH7U1MVl+t\n"
"wcW1BSAuWdH/SvWgKtiwla3JLko716f2b4gp/DA/JIS7w7d7kwcsr4drdjPtAFVS\n"
"slme5LnQ89/nD/7d+MS5EHKBCQRfz5eeLjJ1js+aWNJXMX43AYGyZm0pGrFmCW3R\n"
"bpD0ufovARTFXFZkAdl9h6g4U5+LXUZtXMYnhIHUfoyMo5tS58aI7Dd8KvvwVVo4\n"
"chDYABPPTHPbqjc1qCmBaZx2vN4Ye5DUys/vZwP9BFohFrH/6j/f3IL16/RZkiMN\n"
"JCqVJUzKoZHm1Lesh3Sz8W2jmdv51b2EQJ8HmA==\n"
"-----END CERTIFICATE-----\n";
16 changes: 12 additions & 4 deletions libraries/GSM/src/GSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
reset();
}

_context = mbed::CellularContext::get_default_instance();
if (!_context) {
_context = mbed::CellularContext::get_default_instance();
}

if (_context == nullptr) {
DEBUG_ERROR("Invalid mbed::CellularContext");
Expand Down Expand Up @@ -117,7 +119,10 @@ void arduino::GSMClass::end() {
}

int arduino::GSMClass::disconnect() {
return _context->disconnect();
if (_context) {
return _context->disconnect();
}
return 0;
}

unsigned long arduino::GSMClass::getTime()
Expand All @@ -144,9 +149,12 @@ bool arduino::GSMClass::isConnected()
}
}



NetworkInterface* arduino::GSMClass::getNetwork() {
/* Can happen this is called before GSM.begin( .. ) when configuring GSMSSLClient
* from sketch calling client.appendCustomCACert( .. ) */
if (!_context) {
_context = mbed::CellularContext::get_default_instance();
}
return _context;
}

Expand Down
24 changes: 0 additions & 24 deletions libraries/GSM/src/GSMClient.cpp

This file was deleted.

4 changes: 0 additions & 4 deletions libraries/GSM/src/GSMClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
namespace arduino {

class GSMClient : public AClient {
public:
GSMClient();

private:
NetworkInterface *getNetwork() {
return GSM.getNetwork();
}
Expand Down
24 changes: 0 additions & 24 deletions libraries/GSM/src/GSMSSLClient.cpp

This file was deleted.

3 changes: 0 additions & 3 deletions libraries/GSM/src/GSMSSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ extern const char CA_CERTIFICATES[];
namespace arduino {

class GSMSSLClient : public arduino::ASslClient {
public:
GSMSSLClient();

private:
NetworkInterface *getNetwork() {
return GSM.getNetwork();
Expand Down
4 changes: 0 additions & 4 deletions libraries/SocketWrapper/src/AClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
#include "AClient.h"
#include "MbedSSLClient.h"

AClient::AClient(unsigned long timeout) {
setSocketTimeout(timeout);
}

void arduino::AClient::newMbedClient() {
client.reset(new MbedClient());
client->setNetwork(getNetwork());
Expand Down
2 changes: 0 additions & 2 deletions libraries/SocketWrapper/src/AClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AClient : public Client {
public:

AClient() {}
AClient(unsigned long timeout);

virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
Expand Down Expand Up @@ -71,7 +70,6 @@ class ASslClient : public AClient {
public:

ASslClient() {}
ASslClient(unsigned long timeout) : AClient(timeout) {}

void disableSNI(bool statusSNI);

Expand Down
4 changes: 0 additions & 4 deletions libraries/SocketWrapper/src/MbedSSLClient.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "MbedSSLClient.h"

arduino::MbedSSLClient::MbedSSLClient(unsigned long timeout): MbedClient(timeout), _disableSNI{false} {
onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA));
}

arduino::MbedSSLClient::MbedSSLClient(): _disableSNI{false} {
onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA));
};
2 changes: 0 additions & 2 deletions libraries/SocketWrapper/src/MbedSSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class MbedSSLClient : public arduino::MbedClient {
public:
MbedSSLClient();

MbedSSLClient(unsigned long timeout);

virtual ~MbedSSLClient() {
stop();
}
Expand Down
Loading