Skip to content

Commit

Permalink
GSM: Add GSMSSLClient example
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Nov 7, 2023
1 parent 566c683 commit 3f6204c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
66 changes: 66 additions & 0 deletions libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
GSMSSLlient
This sketch connects to a website (https://ifconfig.me)
using the Portenta CAT.M1/NB IoT GNSS Shield and TLS.
*/

#include <GSM.h>

#include "arduino_secrets.h"
char pin[] = SECRET_PIN;
char apn[] = SECRET_APN;
char username[] = SECRET_USERNAME;
char pass[] = SECRET_PASSWORD;

const char server[] = "ifconfig.me";
const char* ip_address;
int port = 443;
GSMSSLClient client;

void setup() {
Serial.begin(115200);
while(!Serial) {}
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...");
// do nothing forevermore:
while(1);
}
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /ip HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
} else {
Serial.println("unable to connect to server");
}

}

void loop() {

// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();

// do nothing forevermore:
while (true);
}

}
4 changes: 4 additions & 0 deletions libraries/GSM/examples/GSMSSLClient/arduino_secrets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_USERNAME ""
#define SECRET_PASSWORD ""

0 comments on commit 3f6204c

Please sign in to comment.