-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient_Level.cpp
More file actions
62 lines (52 loc) · 1.47 KB
/
Copy pathClient_Level.cpp
File metadata and controls
62 lines (52 loc) · 1.47 KB
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
#include <ESP8266WiFi.h>
const char *ssid = "YOUR_SSID"; // Your Wi-Fi SSID
const char *password = "YOUR_PASSWORD"; // Your Wi-Fi password
const char *serverIP = "192.168.209.234"; // Server IP address
const int serverPort = 80; // Port the server is listening on
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(10);
// Connect to Wi-Fi
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Connect to server
Serial.print("Connecting to server: ");
Serial.println(serverIP);
if (!client.connect(serverIP, serverPort)) {
Serial.println("Connection failed");
return;
}
Serial.println("Connected to server");
}
void loop() {
// Send a request to the server
client.println("GET / HTTP/1.1");
client.println("Host: 192.168.209.234"); // Server IP
client.println("Connection: close");
client.println();
// Wait for the response
while (client.connected() && !client.available()) {
delay(1);
}
// Print the response
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("Request sent");
// Disconnect from the server
client.stop();
Serial.println("Disconnected from server");
// Wait before sending the next request
delay(5000);
}