ESP8266: Problems with link query to database

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

Most probably, your nginx server in test.marius1.de is forwarding http queries to https. If this is the case, you should use https client in your arduino sketch instead of http.

Perfect! That's it!
I turned off the automatic redirection from HTTP to HTTPs and now everything works, as usual. Thank you :slight_smile:
I think this won't be a security problem if this is only running over http, since it's not sensitive data, right?

Greetings and thanks a lot!
Marius

I don't think there will be a security issue since your wifi network is already secure and the exchanged data is not sensitive.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.