-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
67 lines (52 loc) · 1.83 KB
/
main.cpp
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
#include <HTTPClient.h>
#include <WiFi.h>
//#include <HttpClient.h>
#include <ArduinoJson.h>
#include <deneyap.h>
#include <Deneyap_OLED.h>
const char* ssid = "WiFi_Adi";
const char* password = "WiFi_Sifresi";
OLED OLED;
void setup() {
OLED.begin(0x7A);
OLED.clearDisplay();
Serial.begin(115200); // Seri haberlesmeyi baslat
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) { // WiFi baglantisini sagla
delay(500);
Serial.println(".");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http; // HTTPClient olustur ve OpenWeatherMap API'ye istek yap
http.begin("https://api.openweathermap.org/data/2.5/weather?q=CITY_NAME,LANGUAGE_CODE&APPID=YOUR_API_KEY");
int httpCode = http.GET();
if (httpCode > 0) { // Basarili istek durumunda devam et
String payload = http.getString();
char json[512]; // String'i char dizisine cevir
payload.toCharArray(json, 512);
// JSON verisini isle
StaticJsonDocument<512> doc;
deserializeJson(doc, json);
String location = doc["name"];
String status = doc["weather"][0]["main"];
float temp = doc["main"]["temp"];
float humidity = doc["main"]["humidity"];
int pressure = doc["main"]["pressure"];
float tempC = temp - 273.15;
OLED.clearDisplay();
OLED.setTextXY(0, 0);
OLED.putString(location + "-");
OLED.putString(status);
OLED.setTextXY(2, 0);
OLED.putString("Sicaklik: " + String(tempC) + "C");
OLED.setTextXY(4, 0);
OLED.putString("Nem: " + String(humidity) + "%");
OLED.setTextXY(6, 0);
OLED.putString("Basinc: " + String(pressure) + "hPa");
delay(10000); // 10 saniye bekle
}
http.end(); // HTTP istegini sonlandir
}
}