-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch.ino
44 lines (38 loc) · 1.22 KB
/
switch.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
#include <WiFi.h>
const char* ssid = "SwitchNetwork";
const char* password = "SwitchPassword";
const char* switchIP = "192.168.4.1"; // IP address of the switch
void setup() {
Serial.begin(115200);
// Connect to Switch's Wi-Fi network
WiFi.begin(ssid, password);
Serial.print("Connecting to Switch's Wi-Fi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected");
Serial.print("Switch IP address: ");
Serial.println(switchIP);
}
void loop() {
// Request status from switch and handle safe mode activation
WiFiClient client;
if (client.connect(switchIP, 80)) {
client.print("GET / HTTP/1.1\r\n");
client.print("Host: ");
client.print(switchIP);
client.print("\r\n\r\n");
while (client.connected() && !client.available()) delay(1);
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
// Parse the response and activate safe mode if intrusion detected
if (line.indexOf("Intrusion Detected") != -1) {
// Optionally, you can perform some action here when intrusion is detected
}
}
client.stop();
}
delay(5000); // Adjust polling interval as needed
}