forked from arduino/ArduinoCore-mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGSMSSLClient.ino
91 lines (72 loc) · 2.08 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
GSMSSLClient
This sketch connects to a website (https://example.com)
using the Portenta CAT.M1/NB IoT GNSS Shield and TLS.
*/
#include <GSM.h>
#include <Arduino_DebugUtils.h>
#include <GSMDebug.h>
#include "arduino_secrets.h"
#if defined(ARDUINO_EDGE_CONTROL)
#include "root_ca.h"
#endif
char pin[] = SECRET_PIN;
char apn[] = SECRET_APN;
char username[] = SECRET_USERNAME;
char pass[] = SECRET_PASSWORD;
const char server[] = "example.com";
const char* ip_address;
int port = 443;
GSMSSLClient client;
void setup() {
Serial.begin(9600);
while(!Serial) {}
#if defined(ARDUINO_EDGE_CONTROL)
// Power ON MKR2
pinMode(ON_MKR2, OUTPUT);
digitalWrite(ON_MKR2, HIGH);
// Configure root certificate
client.appendCustomCACert(root_ca);
#endif
// 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...");
// 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 / 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);
}
}