Skip to content

Commit 7992377

Browse files
authored
Enna_AW_v3
Enna_AW_v3
1 parent 09cab8b commit 7992377

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// 30.11.2017
2+
// nodemcu ile sicaklik ve nem takibi
3+
// electrocoder
4+
5+
// sahin mersin
6+
// v3
7+
8+
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
9+
10+
#include <DNSServer.h>
11+
#include <ESP8266WebServer.h>
12+
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
13+
14+
#include <ESP8266HTTPClient.h>
15+
16+
#include "DHT.h"
17+
18+
#define DHTPIN 4 // D2 - GPIO4
19+
#define DHTTYPE DHT22
20+
21+
DHT dht(DHTPIN, DHTTYPE);
22+
23+
24+
void configModeCallback (WiFiManager *myWiFiManager) {
25+
Serial.println("Ayarlar");
26+
Serial.println(WiFi.softAPIP());
27+
28+
Serial.println(myWiFiManager->getConfigPortalSSID());
29+
}
30+
31+
32+
void setup() {
33+
Serial.begin(115200);
34+
35+
WiFiManager wifiManager;
36+
//reset ayari
37+
//wifiManager.resetSettings();
38+
39+
wifiManager.setAPCallback(configModeCallback);
40+
41+
if (!wifiManager.autoConnect("MeseIoT", "MeseIoT**")) {
42+
Serial.println("Zaman asimi hatasi");
43+
44+
ESP.reset();
45+
delay(1000);
46+
}
47+
48+
Serial.println("Baglanti saglandi");
49+
50+
dht.begin();
51+
}
52+
53+
54+
void loop() {
55+
delay(2000);
56+
57+
float h = dht.readHumidity();
58+
float t = dht.readTemperature();
59+
float f = dht.readTemperature(true);
60+
61+
if (isnan(h) || isnan(t) || isnan(f)) {
62+
Serial.println("DHT hatasi!");
63+
return;
64+
}
65+
66+
float hif = dht.computeHeatIndex(f, h);
67+
float hic = dht.computeHeatIndex(t, h, false);
68+
69+
Serial.println("\n*****************************************************************");
70+
71+
Serial.print("Nem: ");
72+
Serial.print(h);
73+
Serial.print(" %\t");
74+
Serial.print("Sicaklik: ");
75+
Serial.print(t);
76+
Serial.print(" *C ");
77+
Serial.print(f);
78+
Serial.print(" *F\t");
79+
Serial.print("Heat index: ");
80+
Serial.print(hic);
81+
Serial.print(" *C ");
82+
Serial.print(hif);
83+
Serial.println(" *F");
84+
85+
Serial.println("\n*****************************************************************");
86+
87+
HTTPClient http;
88+
89+
http.begin("http://iothook.com/api/latest/datas/update/?api_key=API_KEY&value_1=" + String(t) + "&value_2=" + String(h) + "");
90+
91+
int httpCode = http.GET();
92+
if (httpCode > 0) {
93+
Serial.printf("[HTTP] GET... Return: %d\n", httpCode);
94+
95+
if (httpCode == HTTP_CODE_OK) {
96+
97+
int len = http.getSize();
98+
99+
uint8_t buff[128] = { 0 };
100+
101+
WiFiClient * stream = http.getStreamPtr();
102+
103+
while (http.connected() && (len > 0 || len == -1)) {
104+
size_t size = stream->available();
105+
106+
if (size) {
107+
// read up to 128 byte
108+
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
109+
110+
Serial.write(buff, c);
111+
112+
if (len > 0) {
113+
len -= c;
114+
}
115+
}
116+
delay(1);
117+
}
118+
119+
}
120+
} else {
121+
Serial.printf("[HTTP] GET... Hata...: %s\n", http.errorToString(httpCode).c_str());
122+
}
123+
124+
http.end();
125+
delay(13000);
126+
}
127+

0 commit comments

Comments
 (0)