#include
#include
#include
#include
// Config Firebase
#define FIREBASE_HOST ""
#define FIREBASE_AUTH ""
// Config connect WiFi
#define WIFI_SSID ""
#define WIFI_PASSWORD "<0808656541>"
// Config DHT
#define DHTPIN D2
#define DHTTYPE DHT22
// LED Debug
#define DEBUG_WIFICONNECT 14
#define DEBUG_PUTHDATA 5
// Config time
int timezone = 7;
char ntp_server1[20] = "ntp.ku.ac.th";
char ntp_server2[20] = "fw.eng.ku.ac.th";
char ntp_server3[20] = "time.uni.net.th";
int dst = 0;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(DEBUG_WIFICONNECT, OUTPUT);
pinMode(DEBUG_PUTHDATA, OUTPUT);
Serial.begin(9600);
WiFi.mode(WIFI_STA);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
digitalWrite(DEBUG_WIFICONNECT, !digitalRead(DEBUG_WIFICONNECT));
delay(500);
}
digitalWrite(DEBUG_WIFICONNECT, HIGH);
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
configTime(timezone * 3600, dst, ntp_server1, ntp_server2, ntp_server3);
Serial.println("Waiting for time");
while (!time(nullptr)) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println("Now: " + NowString());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
dht.begin();
}
void loop() {
pinMode(DHTPIN, INPUT_PULLUP);
// Read temp & Humidity for DHT22
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
delay(500);
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.println();
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["temperature"] = t;
root["humidity"] = h;
root["time"] = NowString();
digitalWrite(DEBUG_PUTHDATA, HIGH);
// append a new value to /logDHT
String name = Firebase.push("logDHT", root);
// handle error
if (Firebase.failed()) {
Serial.print("pushing /logDHT failed:");
Serial.println(Firebase.error());
return;
}
Serial.print("pushed: /logDHT/");
Serial.println(name);
delay(2000);
digitalWrite(DEBUG_PUTHDATA, LOW);
delay(28000);
}
String NowString() {
time_t now = time(nullptr);
struct tm* newtime = localtime(&now);
String tmpNow = "";
tmpNow += String(newtime->tm_hour);
tmpNow += ":";
tmpNow += String(newtime->tm_min);
tmpNow += ":";
tmpNow += String(newtime->tm_sec);
return tmpNow;
}
ขอรบกวนหน่อยนะครับ
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
คอมไพล์โค้ดไป node mcu แล้ว error ครับ
#include
#include
#include
// Config Firebase
#define FIREBASE_HOST ""
#define FIREBASE_AUTH ""
// Config connect WiFi
#define WIFI_SSID ""
#define WIFI_PASSWORD "<0808656541>"
// Config DHT
#define DHTPIN D2
#define DHTTYPE DHT22
// LED Debug
#define DEBUG_WIFICONNECT 14
#define DEBUG_PUTHDATA 5
// Config time
int timezone = 7;
char ntp_server1[20] = "ntp.ku.ac.th";
char ntp_server2[20] = "fw.eng.ku.ac.th";
char ntp_server3[20] = "time.uni.net.th";
int dst = 0;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(DEBUG_WIFICONNECT, OUTPUT);
pinMode(DEBUG_PUTHDATA, OUTPUT);
Serial.begin(9600);
WiFi.mode(WIFI_STA);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
digitalWrite(DEBUG_WIFICONNECT, !digitalRead(DEBUG_WIFICONNECT));
delay(500);
}
digitalWrite(DEBUG_WIFICONNECT, HIGH);
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
configTime(timezone * 3600, dst, ntp_server1, ntp_server2, ntp_server3);
Serial.println("Waiting for time");
while (!time(nullptr)) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println("Now: " + NowString());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
dht.begin();
}
void loop() {
pinMode(DHTPIN, INPUT_PULLUP);
// Read temp & Humidity for DHT22
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
delay(500);
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.println();
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["temperature"] = t;
root["humidity"] = h;
root["time"] = NowString();
digitalWrite(DEBUG_PUTHDATA, HIGH);
// append a new value to /logDHT
String name = Firebase.push("logDHT", root);
// handle error
if (Firebase.failed()) {
Serial.print("pushing /logDHT failed:");
Serial.println(Firebase.error());
return;
}
Serial.print("pushed: /logDHT/");
Serial.println(name);
delay(2000);
digitalWrite(DEBUG_PUTHDATA, LOW);
delay(28000);
}
String NowString() {
time_t now = time(nullptr);
struct tm* newtime = localtime(&now);
String tmpNow = "";
tmpNow += String(newtime->tm_hour);
tmpNow += ":";
tmpNow += String(newtime->tm_min);
tmpNow += ":";
tmpNow += String(newtime->tm_sec);
return tmpNow;
}
ขอรบกวนหน่อยนะครับ
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).