I have some questions about this code
/*************************************************************************************************
* Created By: Tauseef Ahmad
* Created On: 3 April, 2023
*
* YouTube Video: https://youtu.be/VEN5kgjEuh8
* My Channel: https://www.youtube.com/channel/UCOXYfOHgu-C-UfGyDcu5sYw/
*
* *********************************************************************************************
* Preferences--> Aditional boards Manager URLs :
* For ESP32 (2.0.3):
* https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
***********************************************************************************************/
#include <WiFi.h>
#include <HTTPClient.h>
String URL = "http://computer_ip/project_folder/project_file.php";
const char* ssid = "ENTER_WIFI_SSID";
const char* password = "ENTER_WIFI_PASSWORD";
int temperature = 50;
int humidity = 50;
void setup() {
Serial.begin(115200);
connectWiFi();
}
void loop() {
if(WiFi.status() != WL_CONNECTED) {
connectWiFi();
}
String postData = "temperature=" + String(temperature) + "&humidity=" + String(humidity);
HTTPClient http;
http.begin(URL);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST(postData);
String payload = http.getString();
String payload = "";
if(httpCode > 0) {
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end(); //Close connection
Serial.print("URL : "); Serial.println(URL);
Serial.print("Data: "); Serial.println(postData);
Serial.print("httpCode: "); Serial.println(httpCode);
Serial.print("payload : "); Serial.println(payload);
Serial.println("--------------------------------------------------");
}
void connectWiFi() {
WiFi.mode(WIFI_OFF);
delay(1000);
//This line hides the viewing of ESP as wifi hotspot
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("connected to : "); Serial.println(ssid);
Serial.print("IP address: "); Serial.println(WiFi.localIP());
}
Code credist goes to Tauseef Ahmad
1.Does the Arduino IDE or the ESP 32 board is sending the values to mysql database?
2.Does the values are written through online using the ESP 32 wifi connection?If yes can we send any data to any sever ?
3.If we want want to use the mysql database to show in a website what will be the procedure.The website data should be updated after refreshing the site.
Thank you.