|
- #ifdef ESP32
- #include <WiFi.h>
- #include <HTTPClient.h>
- #else
- #include <ESP8266WiFi.h>
- #include <ESP8266HTTPClient.h>
- #include <WiFiClient.h>
- #endif
-
- #include <Wire.h>
-
- 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);
- }
|