05.12(11주차) Node Red를 이용한 DHT - rlarlqor0513/smart-device GitHub Wiki

ESP32 및 DHT11 연결

32-1

아래 코드 입력

#include <WiFi.h>
#include <HTTPClient.h>
#include <DHT.h>

#define DHTPIN 13
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

float tem = 0;
float hum = 0;

const char* ssid = "yourWIFIname";
const char* password = "WIFIpassword";
String serverName = "http://ip/https-severname";

unsigned long lastTime = 0;
unsigned long timerDelay = 5000;

void setup() {

delay(500);
Serial.begin(9600);

WiFi.begin(ssid, password);
Serial.println("Connecting");

while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {

tem = dht.readTemperature();
hum = dht.readHumidity();

Serial.print("Temperature :");
Serial.print(tem);

Serial.print("Humidity :");
Serial.print(hum);


if ((millis() - lastTime) > timerDelay) {

if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
String serverPath = serverName + "?Temperature=" + String(tem) + "&" + "Humidity=" + String(hum);

http.begin(serverPath.c_str());       //부동숫자 문자열로 변경

int httpResponseCode = http.GET();

if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}

http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}

Node-red 작성

노드 연결

image

결과값 확인

33 34

아두이노에서 컴파일 및 업로드에서 오류가 없고 결과값은 나오는데 DHT 기기 오류로 인해 출력값이 NaN이 출력됩니다..

⚠️ **GitHub.com Fallback** ⚠️