From a1c85e64272cf8f21b6055e310d476c0b91962db Mon Sep 17 00:00:00 2001 From: Santhosh Reddy Lotla Date: Wed, 9 Nov 2022 07:09:06 +0000 Subject: [PATCH] Update 'esppost.ino' --- esppost.ino | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/esppost.ino b/esppost.ino index e69de29..8eb2a0f 100644 --- a/esppost.ino +++ b/esppost.ino @@ -0,0 +1,65 @@ +#ifdef ESP32 + #include + #include +#else + #include + #include + #include +#endif + +#include + +const char* ssid = "Wifiname"; +const char* password = "password"; + +const char* serverName = "https://scholarspedia.com/Neonflake/post-esp-data.php"; +String apiKeyValue = "Neonflake0799"; + +void setup() { + 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()); +} +void loop() { + //Add your code here + + + + //End your code here + if(WiFi.status()== WL_CONNECTED){ + HTTPClient http; + http.begin(serverName); + http.addHeader("Content-Type", "application/x-www-form-urlencoded"); + //Change your names here + String httpRequestData = "api_key=" + apiKeyValue + "&temperature=" + Temp_value + "&luminosity=" + Lumi_value + "&pH=" + pH_value + ""; + //Dont edit anything below + int httpResponseCode = http.POST(httpRequestData); + if (httpResponseCode>0) { + if(httpResponseCode==200){ + Serial.print("Server succesfully updated"); + Serial.println(""); + } + else{ + Serial.print("HTTP Response code: "); + Serial.print(httpResponseCode); + Serial.println(""); + } + } + else { + Serial.print("Error code: "); + Serial.println(httpResponseCode); + } + http.end(); + } + else { + Serial.println("WiFi Disconnected"); + } + delay(900000); +} \ No newline at end of file