From b2de6f2cb784fdf89eb808536a05176d28c30ad1 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 17 Apr 2024 12:18:58 +0200 Subject: [PATCH 1/7] GSMClient GSMSSLClient: align constructor to other Client classes Remove the possibility to set socket timeout from constructor. The preferred way should be using setSocketTimeout() method. --- libraries/GSM/src/GSMClient.cpp | 24 ------------------------ libraries/GSM/src/GSMClient.h | 4 ---- libraries/GSM/src/GSMSSLClient.cpp | 24 ------------------------ libraries/GSM/src/GSMSSLClient.h | 3 --- 4 files changed, 55 deletions(-) delete mode 100644 libraries/GSM/src/GSMClient.cpp delete mode 100644 libraries/GSM/src/GSMSSLClient.cpp diff --git a/libraries/GSM/src/GSMClient.cpp b/libraries/GSM/src/GSMClient.cpp deleted file mode 100644 index 2db67df7d..000000000 --- a/libraries/GSM/src/GSMClient.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - GSMClient.cpp - Copyright (c) 2023 Arduino SA. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "GSMClient.h" - -arduino::GSMClient::GSMClient(): AClient(100) { - -} diff --git a/libraries/GSM/src/GSMClient.h b/libraries/GSM/src/GSMClient.h index 52c794a75..f29292fb9 100644 --- a/libraries/GSM/src/GSMClient.h +++ b/libraries/GSM/src/GSMClient.h @@ -26,10 +26,6 @@ namespace arduino { class GSMClient : public AClient { -public: - GSMClient(); - -private: NetworkInterface *getNetwork() { return GSM.getNetwork(); } diff --git a/libraries/GSM/src/GSMSSLClient.cpp b/libraries/GSM/src/GSMSSLClient.cpp deleted file mode 100644 index 0070f210e..000000000 --- a/libraries/GSM/src/GSMSSLClient.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - GSMSSLClient.cpp - Copyright (c) 2023 Arduino SA. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "GSMSSLClient.h" - -arduino::GSMSSLClient::GSMSSLClient(): ASslClient(100) { - -} diff --git a/libraries/GSM/src/GSMSSLClient.h b/libraries/GSM/src/GSMSSLClient.h index ab07d1f79..cc7d3c194 100644 --- a/libraries/GSM/src/GSMSSLClient.h +++ b/libraries/GSM/src/GSMSSLClient.h @@ -28,9 +28,6 @@ extern const char CA_CERTIFICATES[]; namespace arduino { class GSMSSLClient : public arduino::ASslClient { -public: - GSMSSLClient(); - private: NetworkInterface *getNetwork() { return GSM.getNetwork(); From 6011d05097dd59314e6d7632fc672271d35bc84a Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 17 Apr 2024 12:20:16 +0200 Subject: [PATCH 2/7] AClient ASSLClient: remove possibility to set timeout from constructor This way was used on by GSMClient and now is not more needed --- libraries/SocketWrapper/src/AClient.cpp | 4 ---- libraries/SocketWrapper/src/AClient.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/libraries/SocketWrapper/src/AClient.cpp b/libraries/SocketWrapper/src/AClient.cpp index 013868d7c..272b18946 100644 --- a/libraries/SocketWrapper/src/AClient.cpp +++ b/libraries/SocketWrapper/src/AClient.cpp @@ -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()); diff --git a/libraries/SocketWrapper/src/AClient.h b/libraries/SocketWrapper/src/AClient.h index c93bea0f3..195f7a1f2 100644 --- a/libraries/SocketWrapper/src/AClient.h +++ b/libraries/SocketWrapper/src/AClient.h @@ -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); @@ -71,7 +70,6 @@ class ASslClient : public AClient { public: ASslClient() {} - ASslClient(unsigned long timeout) : AClient(timeout) {} void disableSNI(bool statusSNI); From 4e2e81c8d44c1bcc7dbe318727d402e57654aa3e Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 18 Apr 2024 15:18:16 +0200 Subject: [PATCH 3/7] MbedSSLClient: remove the possibility to set timeout from constructor --- libraries/SocketWrapper/src/MbedSSLClient.cpp | 4 ---- libraries/SocketWrapper/src/MbedSSLClient.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/libraries/SocketWrapper/src/MbedSSLClient.cpp b/libraries/SocketWrapper/src/MbedSSLClient.cpp index 3233c8dba..e0aa1d2dd 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.cpp +++ b/libraries/SocketWrapper/src/MbedSSLClient.cpp @@ -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)); }; diff --git a/libraries/SocketWrapper/src/MbedSSLClient.h b/libraries/SocketWrapper/src/MbedSSLClient.h index ddedcb563..34f4d583d 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.h +++ b/libraries/SocketWrapper/src/MbedSSLClient.h @@ -33,8 +33,6 @@ class MbedSSLClient : public arduino::MbedClient { public: MbedSSLClient(); - MbedSSLClient(unsigned long timeout); - virtual ~MbedSSLClient() { stop(); } From c5972429fc42ac8db85e4e38dca4a5b870c6b58f Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 18 Apr 2024 15:20:02 +0200 Subject: [PATCH 4/7] GSM: fix context initialization when client method is called before GSM.begin() --- libraries/GSM/src/GSM.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index f45d7b35c..cf5f5b975 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -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"); @@ -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() @@ -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; } From 7eecb7cab16b655e5dfea3b828debe72b8b17b77 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 18 Apr 2024 15:28:53 +0200 Subject: [PATCH 5/7] GSMSSLClient example update root_ca and enable GSM library debug --- .../examples/GSMSSLClient/GSMSSLClient.ino | 14 ++++-- libraries/GSM/examples/GSMSSLClient/root_ca.h | 44 +++++++++++-------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino b/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino index 0aa85f669..721b8ea12 100644 --- a/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino +++ b/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino @@ -1,5 +1,5 @@ /* - GSMSSLlient + GSMSSLClient This sketch connects to a website (https://example.com) using the Portenta CAT.M1/NB IoT GNSS Shield and TLS. @@ -7,6 +7,8 @@ */ #include +#include +#include #include "arduino_secrets.h" #if defined(ARDUINO_EDGE_CONTROL) @@ -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); @@ -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..."); diff --git a/libraries/GSM/examples/GSMSSLClient/root_ca.h b/libraries/GSM/examples/GSMSSLClient/root_ca.h index c314f4cc2..581338be2 100644 --- a/libraries/GSM/examples/GSMSSLClient/root_ca.h +++ b/libraries/GSM/examples/GSMSSLClient/root_ca.h @@ -1,23 +1,29 @@ static const char root_ca[] = "-----BEGIN CERTIFICATE-----\n" -"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" +"MIIEyDCCA7CgAwIBAgIQDPW9BitWAvR6uFAsI8zwZjANBgkqhkiG9w0BAQsFADBh\n" "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" -"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaW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QAYIKwYBBQUHMAKG\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"; From aca5d7ad2ea819319e5992d1ea898c87af55712a Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 18 Apr 2024 15:31:46 +0200 Subject: [PATCH 6/7] GSMClient example: enable GSM library debug --- .../GSM/examples/GSMClient/GSMClient.ino | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/GSM/examples/GSMClient/GSMClient.ino b/libraries/GSM/examples/GSMClient/GSMClient.ino index 14b031b0b..287cac24c 100644 --- a/libraries/GSM/examples/GSMClient/GSMClient.ino +++ b/libraries/GSM/examples/GSMClient/GSMClient.ino @@ -1,6 +1,16 @@ +/* + GSMClient + + This sketch connects to a website (https://example.com) + using the Portenta CAT.M1/NB IoT GNSS Shield. + + */ + #include +#include +#include +#include "arduino_secrets.h" -#include "arduino_secrets.h" char pin[] = SECRET_PIN; char apn[] = SECRET_APN; char username[] = SECRET_USERNAME; @@ -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..."); From a588a81f1cb8792c5f5ab0588577ae7d61df9d01 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 18 Apr 2024 15:49:46 +0200 Subject: [PATCH 7/7] Compile examples: add Arduino_DebugUtils librery dependency --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 71c0cef9d..645f35f96 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -72,6 +72,7 @@ jobs: - name: ArduinoGraphics - name: Arduino_GigaDisplayTouch - name: emWin + - name: Arduino_DebugUtils additional-sketch-paths: | - libraries/PDM - libraries/doom @@ -177,6 +178,7 @@ jobs: fqbn: arduino:mbed:edge_control additional-libraries: | - name: MicroNMEA + - name: Arduino_DebugUtils additional-sketch-paths: | - libraries/GSM - libraries/USBHID