-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHTTPSClient.ino
66 lines (52 loc) · 1.88 KB
/
HTTPSClient.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
/**
* Example demonstrating how to make an HTTPS GET request using
* the ArduinoHttpClient library and the ArduinoCellular library.
*
* Instructions:
* 1. Insert a SIM card with or without PIN code in the Arduino Pro 4G Module.
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
* with a current rating of at least 2A and connect it to the VIN and GND pins.
* 3. Specify the APN, login, and password for your cellular network provider.
* 4. Upload the sketch to the connected Arduino board.
* 5. Open the serial monitor to view the output.
*
* Initial author: Cristian Dragomir
*/
#include <Arduino.h>
#include "ArduinoCellular.h"
#include <ArduinoHttpClient.h>
#include "arduino_secrets.h"
const char server[] = "example.com";
const char resource[] = "/";
const int port = 443;
ArduinoCellular cellular = ArduinoCellular();
HttpClient client = cellular.getHTTPSClient(server, port);
void getResource(){
Serial.println("Making GET request...");
client.get(resource);
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
client.stop();
}
void setup(){
Serial.begin(115200);
while (!Serial);
// cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
cellular.begin();
if(String(SECRET_PINNUMBER).length() > 0 && !cellular.unlockSIM(SECRET_PINNUMBER)){
Serial.println("Failed to unlock SIM card.");
while(true); // Stop here
}
Serial.println("Connecting...");
if(!cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD)){
Serial.println("Failed to connect to the network.");
while(true); // Stop here
}
Serial.println("Connected!");
getResource();
}
void loop(){}