forked from arduino/ArduinoCore-mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGSMSSLClient.ino
66 lines (54 loc) · 1.57 KB
/
GSMSSLClient.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
}
}