Edit:
I apologize for the lack of information and quality of the previous version of this question, I will try to rephrase and give more information about my issue.
I am currently running a web server using XAMPP in my laptop. The webserver contains several php files that make a website, and a database.
Inside the database I created a table for testing purposes called 'test'. This table consists on 2 columns: a timestamp and a value column which accepts integers.
One of the php files in the web server is called update.php, and uses GET to write information into the 'test' table in the database, like this:
<?php
require_once "db.php";
$value = $_GET['value'];
$query = "
INSERT INTO test(value)
VALUES ('".$value."')
";
mysqli_query($conn, $query);
?>
This works properly, if I go into my browser and type 'http://localhost/swater/update.php?value=2', a new row is successfully added to the table with value 2.
This is great, but I need this to be carried out from an ESP8266, which is connected to a button. The goal is that every X seconds the ESP checks if the button is pressed or not. If it is pressed it should add value 1 to the table, and if it is not it should add value 0.
I first carried this out connecting the ESP to my house Wi-Fi network, using this code:
void loop() {
if ((millis() - lastTime) > timerDelay) {
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
value = digitalRead(4);
String serverPath = serverName + "?value=" + value;
http.begin(client, serverPath.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
else {
Serial.println("Disconnected");
}
lastTime = millis();
}
}
This worked perfectly fine, and my table started periodically getting values added. However this is not my final goal, as I want the ESP to act as an access point, to which my laptop is connected.
I managed to write this code:
void setup() {
Serial.begin(115200);
WiFi.softAP(ssid, pwd);
pinMode(4, INPUT);
}
void loop() {
WiFiClient client;
HTTPClient http;
http.begin(client, "http://192.168.4.2:80/swater/update.php?value=1");
Serial.print("Request sent.\n");
delay(5000);
}
Note that I am not using the values that the ESP reads, I am just testing so I am skipping that part of the code and just using value=1 all the time.
When I run this code in the ESP, I can connect my laptop and my phone to the Wi-Fi that it creates, and I can successfully visit the website from any device connected to it, however no values are added to the 'test' table.
I apologize if I now made my explanation too long, but it is my first time working with this kind of systems and it is the first time I ask a question in this platform, I appreciate the help.