-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSapiv2.ino
64 lines (43 loc) · 1.58 KB
/
NSapiv2.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
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>
#include <Arduino_JSON.h>
char ssid[] = "Spothot";
char password[] = "12345678";
WiFiClientSecure client;
HTTPClient http;
//const String endpoint = "https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions[?type][&isActive]";
const String endpoint = "https://gateway.apiportal.ns.nl/reisinformatie-api/api/v3/disruptions?type=calamity&isActive=true";
const String key = "e2def5ae092e4b53add2c6350926fc7d";
// The fingerprint of the site you want to connect to.
#define HOST_FINGERPRINT "BA 78 CA 7E 98 B7 32 35 46 1F 62 CA E1 BF 27 1E A8 75 DE 01"
// The finger print will change every few months.
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
// If you want to check the fingerprint
client.setFingerprint(HOST_FINGERPRINT);
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
http.begin(client, endpoint); //Specify the URL
http.addHeader("Ocp-Apim-Subscription-Key", key, true);
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
else {
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
}
delay(30000);
}