forked from Saiikishen/Medicine-Dispenser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_test.ino
More file actions
41 lines (34 loc) · 920 Bytes
/
http_test.ino
File metadata and controls
41 lines (34 loc) · 920 Bytes
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
#include <WiFi.h>
#include <HTTPClient.h>
// Wi-Fi credentials
const char* ssid = "Enter SSID";
const char* password = "Enter pass";
// HTTP server details
const char* serverName = "your server url";
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverName);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String httpDateTime = http.getString();
Serial.println("HTTP Date and Time: " + httpDateTime);
} else {
Serial.println("Error in HTTP request");
}
http.end();
} else {
Serial.println("WiFi not connected");
}
delay(10000); // Delay 1 minute before next check
}