Skip to content

Commit 703289d

Browse files
committed
GSM: Add GSMSSLClient example
1 parent 89cec9f commit 703289d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 66 additions & 0 deletions
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+
}
Lines changed: 4 additions & 0 deletions
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 ""

0 commit comments

Comments
 (0)