Circuit Diagram
Program Code:
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
/************************* Pin Definition *********************************/
//DHT11 for reading temperature and humidity value
#define DHTPIN D7
String temp;
String hum;
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
// Your WiFi credentials.
// Set password to "" for open networks.
const char* ssid = "*******";
const char* password = "*******";
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266!");
}
void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
void setup()
{
// Debug console
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
dht.begin();
server.on("/", handleRoot); // http://localIPAddress/
server.on("/dht-temp", []() // http://localIPAddress/dht-temp
{
int t = dht.readTemperature();
temp = String(t);
server.send(200, "text/plain", temp);
});
server.on("/dht-hum", []() // http://localIPAddress/dht-hum
{
int h = dht.readHumidity();
hum = String(h);
server.send(200, "text/plain", hum);
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop()
{
server.handleClient();
}
Node-red JSON file
[
{
"id": "64f52903c284b545",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "30a7782ba04b1a60",
"type": "ui_gauge",
"z": "64f52903c284b545",
"name": "",
"group": "a7841362.ae40c",
"order": 1,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "Temperature Data",
"label": "deg C",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"className": "",
"x": 490,
"y": 480,
"wires": []
},
{
"id": "e6a00cc180f7067b",
"type": "http request",
"z": "64f52903c284b545",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "192.168.43.243/dht-temp",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"senderr": false,
"x": 300,
"y": 480,
"wires": [
[
"30a7782ba04b1a60"
]
]
},
{
"id": "691c4dc63f202da8",
"type": "inject",
"z": "64f52903c284b545",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "3",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 480,
"wires": [
[
"e6a00cc180f7067b"
]
]
},
{
"id": "48feb7d8a567f7a7",
"type": "ui_gauge",
"z": "64f52903c284b545",
"name": "",
"group": "a7841362.ae40c",
"order": 1,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "Humidity Data",
"label": "%",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"className": "",
"x": 1040,
"y": 420,
"wires": []
},
{
"id": "3392fb2a675e207b",
"type": "http request",
"z": "64f52903c284b545",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "192.168.43.243/dht-hum",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"senderr": false,
"x": 850,
"y": 420,
"wires": [
[
"48feb7d8a567f7a7"
]
]
},
{
"id": "60b07f05b391fec5",
"type": "inject",
"z": "64f52903c284b545",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "5",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 670,
"y": 420,
"wires": [
[
"3392fb2a675e207b"
]
]
},
{
"id": "a7841362.ae40c",
"type": "ui_group",
"name": "My studio",
"tab": "2ff36ff5.bdc628",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "2ff36ff5.bdc628",
"type": "ui_tab",
"name": "Studio_control",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
No comments:
Post a Comment