TEMPERATURE MONITORING WEB SERVER
make this temperature monitoring web server using node mcu and temperature sensor . use the following code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <math.h>
int sensorPin = A0; // select the input pin for the potentiometer
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0 ; // Convert Celcius to Fahrenheit
return Temp;
}
//SSID and Password of your WiFi router
const char* ssid = "kali";
const char* password = "0TSspwyV";
ESP8266WebServer server(80); //Server on port 80
int T = 0;
//===============================================================
// This rutine is exicuted when you open its IP in browser
//===============================================================
void handleRoot() {
String s = "<!DOCTYPE html>\n<html>\n<head>\n<title>Temperature Monitoring Web Server</title>\n<style>\ndiv.card {\n width: 300px;\n\n box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);\n text-align: center;\n border-radius: 5px;\n background-color: #F5F7A0\n}\n\ndiv.header {\n background-color: #E03C3C;\n color: white;\n padding: 10px;\n font-size: 40px;\n border-radius: 5px;\n}\n\ndiv.container {\n padding: 4px;\n}\n</style>\n</head>\n<body>\n\n<center><h2>Temperature Monitoring Web Server</h2>\n\n<div class=\"card\">\n <div class=\"header\">\n <h1>"+T+"°C</h1>\n </div>\n\n <div class=\"container\">\n <h2>Temperature</h2>\n </div>\n</div>\n\n</center>\n</body>\n</html>\n\n);\n";
int Temperature;
Temperature = analogRead(A0); //Read Analog Voltage of ADC Pin
Temperature = Temperature/10; //10mV is 1 degree C
//Convert Temperature int to String then Replace @@temp@@ in HTML with temperaure value
s.replace("@@temp@@",String(Temperature));
server.send(200, "text/html", s); //Send webpage to browser
}
//===============================================================
// SETUP
//===============================================================
void setup(void){
Serial.begin(9600);
WiFi.begin(ssid, password); //Connect to your WiFi router
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address of ESP
server.on("/", handleRoot); //handle root location
server.begin(); //Start server
Serial.println("HTTP server started");
}
//===============================================================
// LOOP
//===============================================================
void loop(void){
T = temp;
server.handleClient(); //Handle client requests
}
if you are using this sensor
you dont need to change the code use 3.3 volts as power or make some adgustments in code and use 5v.or if you are using some other sensors than you can replace codes in temperature function.
change SSID and PASSWORD and have fun with this project.
feel free to ask anything in the comment i will reply as soon as i can.