bportaluri / WiFiEsp

Arduino WiFi library for ESP8266 modules
GNU General Public License v3.0
551 stars 210 forks source link

How can I get data? #206

Open sbecerikli opened 3 years ago

sbecerikli commented 3 years ago

Hello,

Firstly thans for your library., I need to get data from a web server. How can I do that?

When request "client.println(F("GET /esp.php/?esp_value=61 HTTP/1.1"));" and print this while (client.available()) { char c = client.read(); Serial.write(c); }

It just print HTTP/1.1 200 OK Connection: close X-Powered-By: PHP/7.4.11 Content-Type: text/html; charset=UTF-8 Content-Length: 2

JAndrassy commented 3 years ago

then there is a gap in received data, available() returns 0 and you stop read

sbecerikli commented 3 years ago

I am not returning any data from php file. just echo what I get from url in php

sbecerikli commented 3 years ago

Here is my php file

if( $_GET["esp_value"] ) {

$myfile = fopen("newfile.txt", "a") or die("Unable to open file!");

fwrite($myfile, $_GET["esp_value"]);
echo $_GET["esp_value"];
fclose($myfile);

}

sbecerikli commented 3 years ago

Also here httpsrequest function

void httpRequest() { Serial.println();

// close any connection before send a new request // this will free the socket on the WiFi shield client.stop();

// if there's a successful connection if (client.connect(server, 80)) { Serial.println("Connecting...");

// send the HTTP PUT request
randNumber = random(300);
req = "GET /esp/esp.php?esp_value=";
req2 = " HTTP/1.1";

String request = req + randNumber + req2;

Serial.println("reuqest: " + request);
client.println(request);
client.println(F("Host: seyfullahbecerikli.com"));
client.println("Connection: close");
client.println();

// note the time that the connection was made
lastConnectionTime = millis();

} else { // if you couldn't make a connection Serial.println("Connection failed"); } }

JAndrassy commented 3 years ago

read my comment again