-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEspecially_Safe.ino
149 lines (122 loc) · 4.66 KB
/
Especially_Safe.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <WiFiClientSecure.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DNSServer.h>
const char* dnsServerIP = "1.1.1.1"; // Google DNS Server
const int dnsServerPort = 443; // DNS-over-HTTP (DoH) port
const char* dohServer = "dns.cloudflare";
const char* dohPath = "/resolve";
DNSServer dnsServer;
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 oled(SCREEN_WIDTH,SCREEN_HEIGHT, &Wire, -1);
#define PIN_RED 25 // Led red pin is connected to 23
#define PIN_GREEN 33 // Led green pin is connected to 22
#define PIN_BLUE 32
const char* ssid = "HIMU"; // your network SSID (name of wifi network)
const char* password = "12345678910"; // your network password
const char* server = "www.howsmyssl.com"; // Server URL
// www.howsmyssl.com root certificate authority, to verify the server
// change it to your server root CA
// SHA1 fingerprint is broken now!
const char* test_root_ca= \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDuzCCAqOgAwIBAgIQF5lWz9/TKoQTvShHZ04+OjANBgkqhkiG9w0BAQsFADBI\n" \
"MRswGQYDVQQDDBJFU0VUIFNTTCBGaWx0ZXIgQ0ExHDAaBgNVBAoME0VTRVQsIHNw\n" \
"b2wuIHMgci4gby4xCzAJBgNVBAYTAlNLM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f\n" \
"raHBA5gQVjxENf4ehTohcA86a5JAIgWve6GW6LzMCWCyrslnGkTEC/Uigi8CncEf\n" \
"67zrnfmWFPYQfhM0blAXNN0zQ6vvGKXpL+9CHpB+1Azn9rr7w2sTmq7Yb8UtHTo=\n" \
"-----END CERTIFICATE-----\n";
// You can use x.509 client certificates if you want
//const char* test_client_key = ""; //to verify the client
//const char* test_client_cert = ""; //to verify the client
WiFiClientSecure client;
void setup() {
// Initialize serial and wait for the port to open:
Serial.begin(115200);
delay(100);
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_BLUE, OUTPUT);
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("Failed to start SSD1306 OLED"));
while(1);
}
delay(2000);
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.println("Connection Secure");
oled.display();
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// Attempt to connect to WiFi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
// Wait 1 second before retrying
delay(1000);
}
Serial.print("Connected to ");
Serial.println(ssid);
client.setCACert(test_root_ca);
Serial.println("\nStarting connection to server...");
if (!client.connect(server, 443)) {
Serial.println("Connection failed!");
} else {
Serial.println("Connected to server!");
// Make an HTTP request:
client.println("GET /a/check HTTP/1.1");
client.println("Host: www.howsmyssl.com");
client.println("Connection: close");
client.println();
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("Headers received");
break;
}
}
// If there are incoming bytes available from the server, read and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
client.stop();
}
}
void loop() {
// Red color code
analogWrite(PIN_RED, 255);
analogWrite(PIN_GREEN, 0);
analogWrite(PIN_BLUE, 0);
delay(1000); // Keep the color for 1 second
// Green color code
analogWrite(PIN_RED, 0);
analogWrite(PIN_GREEN, 0);
analogWrite(PIN_BLUE, 255);
delay(1000); // Keep the color for 1 second
// Blue color code
analogWrite(PIN_RED, 0);
analogWrite(PIN_GREEN, 255);
analogWrite(PIN_BLUE, 0);
delay(1000); // Keep the color for 1 second
}