Skip to content

Commit dd74c5b

Browse files
authored
Merge pull request #759 from pennam/thales_edge
Add TLS support to Portenta CAT.M1/NB IoT GNSS Shield
2 parents 52a91c4 + 149883b commit dd74c5b

24 files changed

+857
-69
lines changed

Diff for: .github/workflows/compile-examples.yml

-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ jobs:
156156
- libraries/USBHOST
157157
- libraries/USBMSD/examples/AccessFlashAsUSBDisk
158158
- libraries/WiFi
159-
- libraries/GSM
160159
- ~/Arduino/libraries/ArduinoBLE
161160
- board:
162161
fqbn: arduino:mbed:nicla_voice

Diff for: libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
GSMSSLlient
3+
4+
This sketch connects to a website (https://ifconfig.me)
5+
using the Portenta CAT.M1/NB IoT GNSS Shield and TLS.
6+
7+
*/
8+
9+
#include <GSM.h>
10+
11+
#include "arduino_secrets.h"
12+
char pin[] = SECRET_PIN;
13+
char apn[] = SECRET_APN;
14+
char username[] = SECRET_USERNAME;
15+
char pass[] = SECRET_PASSWORD;
16+
17+
const char server[] = "ifconfig.me";
18+
const char* ip_address;
19+
int port = 443;
20+
GSMSSLClient client;
21+
22+
void setup() {
23+
Serial.begin(115200);
24+
while(!Serial) {}
25+
Serial.println("Starting Carrier Network registration");
26+
if(!GSM.begin(pin, apn, username, pass, CATM1, BAND_3 | BAND_20 | BAND_19)){
27+
Serial.println("The board was not able to register to the network...");
28+
// do nothing forevermore:
29+
while(1);
30+
}
31+
Serial.println("\nStarting connection to server...");
32+
// if you get a connection, report back via serial:
33+
if (client.connect(server, port)) {
34+
Serial.println("connected to server");
35+
// Make a HTTP request:
36+
client.println("GET /ip HTTP/1.1");
37+
client.print("Host: ");
38+
client.println(server);
39+
client.println("Connection: close");
40+
client.println();
41+
} else {
42+
Serial.println("unable to connect to server");
43+
}
44+
45+
}
46+
47+
void loop() {
48+
49+
// if there are incoming bytes available
50+
// from the server, read them and print them:
51+
while (client.available()) {
52+
char c = client.read();
53+
Serial.write(c);
54+
}
55+
56+
// if the server's disconnected, stop the client:
57+
if (!client.connected()) {
58+
Serial.println();
59+
Serial.println("disconnecting from server.");
60+
client.stop();
61+
62+
// do nothing forevermore:
63+
while (true);
64+
}
65+
66+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#define SECRET_PIN ""
2+
#define SECRET_APN ""
3+
#define SECRET_USERNAME ""
4+
#define SECRET_PASSWORD ""

Diff for: libraries/GSM/src/GSM.cpp

+40-58
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1+
/*
2+
GSM.cpp - Library for GSM on mbed platforms.
3+
Copyright (c) 2011-2023 Arduino LLC. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
120
#include "GSM.h"
221

322
#include "mbed.h"
423
#include "CellularLog.h"
24+
#include "CellularDevice.h"
525
#include "CellularContext.h"
626
#include "CellularInterface.h"
727
#include "GEMALTO_CINTERION_CellularStack.h"
828

929
#define MAXRETRY 3
1030

11-
bool _cmuxEnable = false;
12-
arduino::CMUXClass * arduino::CMUXClass::get_default_instance()
31+
arduino::CMUXClass *arduino::CMUXClass::get_default_instance()
1332
{
1433
static mbed::UnbufferedSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200);
1534
serial.set_flow_control(mbed::SerialBase::RTSCTS_SW, MBED_CONF_GEMALTO_CINTERION_CTS, NC);
@@ -19,24 +38,24 @@ arduino::CMUXClass * arduino::CMUXClass::get_default_instance()
1938

2039
mbed::CellularDevice *mbed::CellularDevice::get_default_instance()
2140
{
22-
static auto cmux = arduino::CMUXClass::get_default_instance();
23-
static mbed::GEMALTO_CINTERION device(cmux->get_serial(0));
24-
nextSerialPort++;
25-
device.enableCMUXChannel = mbed::callback(cmux, &arduino::CMUXClass::enableCMUXChannel);
26-
return &device;
41+
static auto cmux = arduino::CMUXClass::get_default_instance();
42+
static mbed::GEMALTO_CINTERION device(cmux->get_serial(0));
43+
nextSerialPort++;
44+
device.enableCMUXChannel = mbed::callback(cmux, &arduino::CMUXClass::enableCMUXChannel);
45+
return &device;
2746
}
2847

2948
int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat, uint32_t band, bool restart) {
3049

3150
if(restart || isCmuxEnable()) {
32-
pinMode(PJ_10, OUTPUT);
33-
digitalWrite(PJ_10, HIGH);
51+
pinMode(MBED_CONF_GEMALTO_CINTERION_RST, OUTPUT);
52+
digitalWrite(MBED_CONF_GEMALTO_CINTERION_RST, HIGH);
3453
delay(800);
35-
digitalWrite(PJ_10, LOW);
36-
pinMode(PJ_7, OUTPUT);
37-
digitalWrite(PJ_7, LOW);
54+
digitalWrite(MBED_CONF_GEMALTO_CINTERION_RST, LOW);
55+
pinMode(MBED_CONF_GEMALTO_CINTERION_ON, OUTPUT);
56+
digitalWrite(MBED_CONF_GEMALTO_CINTERION_ON, LOW);
3857
delay(1);
39-
digitalWrite(PJ_7, HIGH);
58+
digitalWrite(MBED_CONF_GEMALTO_CINTERION_ON, HIGH);
4059
delay(1);
4160
// this timer is to make sure that at boottime and when the CMUX is used,
4261
// ^SYSTART is received in time to avoid stranger behaviour
@@ -50,7 +69,7 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
5069
printf("Invalid context\n");
5170
return 0;
5271
}
53-
pinMode(PJ_7, INPUT_PULLDOWN);
72+
pinMode(MBED_CONF_GEMALTO_CINTERION_ON, INPUT_PULLDOWN);
5473

5574
static mbed::DigitalOut rts(MBED_CONF_GEMALTO_CINTERION_RTS, 0);
5675

@@ -99,11 +118,11 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
99118
return connect_status == NSAPI_ERROR_OK ? 1 : 0;
100119
}
101120

102-
void arduino::GSMClass::enableCmux(){
121+
void arduino::GSMClass::enableCmux() {
103122
_cmuxGSMenable = true;
104123
}
105124

106-
bool arduino::GSMClass::isCmuxEnable(){
125+
bool arduino::GSMClass::isCmuxEnable() {
107126
return _cmuxGSMenable;
108127
}
109128

@@ -130,53 +149,16 @@ bool arduino::GSMClass::setTime(unsigned long const epoch, int const timezone)
130149
return _device->set_time(epoch, timezone);
131150
}
132151

133-
static PlatformMutex trace_mutex;
134-
135-
static void trace_wait()
152+
bool arduino::GSMClass::isConnected()
136153
{
137-
trace_mutex.lock();
138-
}
139-
140-
static void trace_release()
141-
{
142-
trace_mutex.unlock();
143-
}
144-
145-
static char* trace_time(size_t ss)
146-
{
147-
static char time_st[50];
148-
auto ms = std::chrono::time_point_cast<std::chrono::milliseconds>(rtos::Kernel::Clock::now()).time_since_epoch().count();
149-
//snprintf(time_st, 49, "[%08llums]", ms);
150-
snprintf(time_st, 1, "\n");
151-
return time_st;
152-
}
153-
154-
static Stream* trace_stream = nullptr;
155-
static void arduino_print(const char* c) {
156-
if (trace_stream) {
157-
trace_stream->println(c);
154+
if (_context) {
155+
return _context->is_connected();
156+
} else {
157+
return false;
158158
}
159159
}
160160

161-
void arduino::GSMClass::debug(Stream& stream) {
162-
163-
#if MBED_CONF_MBED_TRACE_ENABLE
164-
165-
mbed_trace_init();
166161

167-
trace_stream = &stream;
168-
mbed_trace_print_function_set(arduino_print);
169-
mbed_trace_prefix_function_set( &trace_time );
170-
171-
mbed_trace_mutex_wait_function_set(trace_wait);
172-
mbed_trace_mutex_release_function_set(trace_release);
173-
174-
mbed_cellular_trace::mutex_wait_function_set(trace_wait);
175-
mbed_cellular_trace::mutex_release_function_set(trace_release);
176-
177-
#endif
178-
179-
}
180162

181163
NetworkInterface* arduino::GSMClass::getNetwork() {
182164
return _context;

Diff for: libraries/GSM/src/GSM.h

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/*
22
GSM.h - Library for GSM on mbed platforms.
3-
Copyright (c) 2011-2021 Arduino LLC. All right reserved.
3+
Copyright (c) 2011-2023 Arduino LLC. All right reserved.
4+
45
This library is free software; you can redistribute it and/or
56
modify it under the terms of the GNU Lesser General Public
67
License as published by the Free Software Foundation; either
78
version 2.1 of the License, or (at your option) any later version.
9+
810
This library is distributed in the hope that it will be useful,
911
but WITHOUT ANY WARRANTY; without even the implied warranty of
1012
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1113
Lesser General Public License for more details.
14+
1215
You should have received a copy of the GNU Lesser General Public
1316
License along with this library; if not, write to the Free Software
1417
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -30,10 +33,28 @@
3033
#include "CMUXClass.h"
3134
#include "PTYSerial.h"
3235

33-
#define MBED_CONF_GEMALTO_CINTERION_TX PA_0
34-
#define MBED_CONF_GEMALTO_CINTERION_RX PI_9
35-
#define MBED_CONF_GEMALTO_CINTERION_RTS PI_10
36-
#define MBED_CONF_GEMALTO_CINTERION_CTS PI_13
36+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
37+
#define MBED_CONF_GEMALTO_CINTERION_TX PA_0
38+
#define MBED_CONF_GEMALTO_CINTERION_RX PI_9
39+
#define MBED_CONF_GEMALTO_CINTERION_RTS PI_10
40+
#define MBED_CONF_GEMALTO_CINTERION_CTS PI_13
41+
#define MBED_CONF_GEMALTO_CINTERION_RST PJ_10
42+
#define MBED_CONF_GEMALTO_CINTERION_ON PJ_7
43+
#elif defined (ARDUINO_EDGE_CONTROL)
44+
/* IMPORTANT: turn on the module's 5V on demand by calling
45+
pinMode(ON_MKR2, OUTPUT);
46+
digitalWrite(ON_MKR2, HIGH);
47+
*/
48+
#define MBED_CONF_GEMALTO_CINTERION_TX p24
49+
#define MBED_CONF_GEMALTO_CINTERION_RX p25
50+
#define MBED_CONF_GEMALTO_CINTERION_RTS NC
51+
#define MBED_CONF_GEMALTO_CINTERION_CTS NC
52+
#define MBED_CONF_GEMALTO_CINTERION_RST p31
53+
#define MBED_CONF_GEMALTO_CINTERION_ON p2
54+
#else
55+
#error Gemalto Cinterion cellular connectivity not supported
56+
#endif
57+
3758
#define MBED_CONF_APP_SOCK_TYPE 1
3859

3960
#if defined __has_include
@@ -87,10 +108,12 @@ class GSMClass : public MbedSocketClass {
87108
bool setTime(unsigned long const epoch, int const timezone = 0);
88109
void enableCmux();
89110
bool isCmuxEnable();
90-
void debug(Stream& stream);
111+
void trace(Stream& stream);
112+
void setTraceLevel(int trace_level, bool timestamp = false);
91113
int ping(const char* hostname, uint8_t ttl = 128);
92114
int ping(const String& hostname, uint8_t ttl = 128);
93115
int ping(IPAddress host, uint8_t ttl = 128);
116+
bool isConnected();
94117

95118
friend class GSMClient;
96119
friend class GSMUDP;
@@ -115,6 +138,7 @@ class GSMClass : public MbedSocketClass {
115138
extern GSMClass GSM;
116139

117140
#include "GSMClient.h"
141+
#include "GSMSSLClient.h"
118142
#include "GSMUdp.h"
119143

120144
#endif

Diff for: libraries/GSM/src/GSMClient.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
GSMClient.cpp
3+
Copyright (c) 2023 Arduino SA. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "GSMClient.h"
21+
22+
arduino::GSMClient::GSMClient(): MbedClient(100) {
23+
24+
}

Diff for: libraries/GSM/src/GSMClient.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
namespace arduino {
2727

2828
class GSMClient : public MbedClient {
29+
public:
30+
GSMClient();
31+
32+
private:
2933
NetworkInterface *getNetwork() {
3034
return GSM.getNetwork();
3135
}

Diff for: libraries/GSM/src/GSMSSLClient.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
GSMSSLClient.cpp
3+
Copyright (c) 2023 Arduino SA. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "GSMSSLClient.h"
21+
22+
arduino::GSMSSLClient::GSMSSLClient(): MbedSSLClient(100) {
23+
24+
}

0 commit comments

Comments
 (0)