Hey,
I'm new here and I'm looking forward to your exciting answers!
I was thinking about a problem with the ESP8266 all day today. Unfortunately, I can't figure out my thinking error, maybe you guys can help me there.
I have built a small database, via mySQL and a little php: https://www.test.marius1.de/
With a link that navigates to "TX.php" the 4 variables can be changed. If I want to change cell 1-1 (g1) to 3, I can do this by retrieving from a link of the form:
https://test.marius1.de/TX.php?id=10001&pw=87129&g1=3
After that, the content of the database is simply returned shortly.
The ESP8266 should now simply call this link and read the data from the database in the process. My current code is the following: I write it directly to an ESP-01s modul.
#include <ESP8266WiFi.h>
const char* ssid = "WIFI-Name";
const char* password = "pw";
const char* host = "test.marius1.de";
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
}
void loop()
{
WiFiClient client;
Serial.printf("\n[Connecting to %s ... ", host);
if (client.connect(host, 80))
{
Serial.println("connected]");
Serial.println("[Sending a request]");
client.print(String("GET /") +"TX.php?id=10001&pw=87129&g1=2" + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n" +
"\r\n"
);
// wenn https://test.marius1.de/TX.php?id=10001&pw=87129&g1=2 aufgerufnden wird, wird die Zelle g1 geupdatet.
Serial.println("[Response:]");
while (client.connected())
{
if (client.available())
{
String line = client.readStringUntil('\n');
Serial.println(line);
}
}
client.stop();
Serial.println("\n[Disconnected]");
}
else
{
Serial.println("connection failed!]");
client.stop();
}
delay(5000);
}
I have also used various other example codes on the internet. However, I have never been able to rewrite the database. I would be very happy if someone can tell me where I might have a problem in the code. Or maybe what I'm trying to do doesn't work at all, I'm not very literate with ESP.
Have a great day!
Thanks in advance,
Greetings from Halle,
Marius