Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get data? #206

Open
sbecerikli opened this issue Nov 6, 2020 · 5 comments
Open

How can I get data? #206

sbecerikli opened this issue Nov 6, 2020 · 5 comments

Comments

@sbecerikli
Copy link

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
Copy link

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

@sbecerikli
Copy link
Author

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

@sbecerikli
Copy link
Author

sbecerikli commented Nov 6, 2020

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
Copy link
Author

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
Copy link

read my comment again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants