Untitled
unknown
plain_text
2 years ago
2.8 kB
1
Indexable
Never
#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include "index.h" //Our HTML webpage contents with javascripts //----------------------------------------Host & httpsPort const char* host = "script.google.com"; const int httpsPort = 443; //---------------------------------------- WiFiClientSecure client; //--> Create a WiFiClientSecure object. //---------------------------------------- #define ALTITUDE 1655.0 // Altitude in meters #define LED 2 //On board LED #define DHTpin 14 //D5 of NodeMCU is GPIO14 //SSID and Password of your WiFi router const char* ssid = "soil"; const char* password = "12345678"; ESP8266WebServer server(80); //Server on port 80 void handleRoot() { String s = MAIN_page; //Read HTML contents server.send(200, "text/html", s); //Send web page } float humidity, temperature; void handleADC() { char status; double T, P, p0, a; double Tdeg, Tfar, phg, pmb, tempF; String testing; String testing2; int soil = analogRead(A0); if (soil > 350 && soil < 400) { testing = "Black"; testing2 = "Rice & Cotton"; } else if (soil > 410 && soil < 430 ) { testing = "Red"; testing2 = "Potato & Ground nuts"; } else if (soil > 300 && soil < 330 ) { testing = "Sand"; testing2 = "Coconut"; } else if (soil > 1000 && soil < 1010 ) { testing = "Not Good"; testing2 = "Not Good"; } //Create JSON data String data = "{\"Temperature\":\"" + String(soil) + "\", \"Test\":\"" + String(testing) + "\" , \"Test2\":\"" + String(testing2) + "\" }"; digitalWrite(LED, !digitalRead(LED)); //Toggle LED on data request ajax server.send(200, "text/plane", data); //Send ADC value, temperature and humidity JSON to client ajax request Serial.print("Soil:"); Serial.println(soil); //dht.toFahrenheit(temperature)); } void setup() { Serial.begin(115200); Serial.println(); pinMode(LED, OUTPUT); 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 assigned to your ESP server.on("/", handleRoot); //Which routine to handle at root location. This is display page server.on("/readADC", handleADC); //This page is called by java Script AJAX server.begin(); //Start server Serial.println("HTTP server started"); client.setInsecure(); } void loop() { server.handleClient(); //Handle client requests }