#include <ESP8266WiFi.h>
const char* ssid = "Your SSID";
const char* password = "Your Wifi Password";
int LM35= A0; //Analog channel A0 as used to measure temperature
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address on serial monitor
Serial.print("Use this URL to connect: ");
Serial.print("http://"); //URL IP to be typed in mobile/desktop browser
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
float temperatureC;
float temperatureF;
int value = LOW;
if (request.indexOf("/Tem=ON") != -1) {
float reading = analogRead(LM35); //Analog pin reading output voltage by Lm35
float temperatureC=LM35/3.1; //Finding the true centigrate/celsius temperature
//Serial.println("CENTI TEMP= ");
//Serial.print(temperatureC); //Print centigrade temperature on Serial Monitor
float temperatureF= ((temperatureC ) * 9.0 / 5.0) + 32.0;
//Serial.println("FARE TEMP= ");
//Serial.print(temperatureF); //Print farenheight temperature on Serial Monitor
value = HIGH;
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("Celcius temperature =");
client.print(temperatureC);
client.println("Farenheight temperature =");
client.print(temperatureF);
if(value == HIGH) {
client.println("Updated");
} else {
client.print("Not Updated");
}
client.println("<br><br>");
client.println("<a href=\"/Tem=ON\"\"><button>Update Temperature</button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");