Hello everyone,
today i'm trying to read some text from webpage after open that page via URL with GET information.
Example:
1- arduino connected with the website
2- open www.link.com/page.php?info=1
3- info = 1 produce a certain print in the page: N011
4- arduino print "N011" on LCD
How can i read the "N001" in the page? i'm stuck on point 3
This is the result on Serial Monitor
"UID: 0xD7 0xCB 0x5B 0x52" this is the RFID card uid
"FFFFFFFF" it's the print but the webpage is returning "N001"
I dont' really know, the webpage is very simple: when you open the page with "?uid=XXX", the page read in the database the data and print it .
So the final result is:
keep things simple when you debug, try with a very crude code making the request to ensure your web server is actually responding. Try with this (typed here, so hopefully works)
#include <Ethernet.h>
EthernetClient client;
byte mac[] = { 0xBE, 0xEF, 0xDE, 0xAD, 0xFE, 0xED };
void setup() {
while (!Serial);
Serial.begin(57600);
if (Ethernet.begin(mac) == 0) {
Serial.println(F("No IP through DHCP"));
while (true); // stop here
}
// make a request
if (client.connect("prova.altervista.org", 80)) {
Serial.println("Connected to server");
client.print(F("GET /chiavi.php?uid=1020304050"));
client.println(F( " HTTP/1.1"));
client.println(F("Host: prova.altervista.org"));
client.println(F("User-Agent: arduino-ethernet"));
client.println(F("Connection: close"));
client.println(); // needed to end HTTP header
// read the answer
while (client.connected())
if (client.available())
Serial.print((char) client.read());
client.stop();
Serial.println();
Serial.println("disconnected");
} else {
Serial.println("connection failed");
}
}
void loop() {}
DHCP Success
UID: 0xD7 0xCB 0x5B 0x52
DHCP Success
UID: 0xD7 0xCB 0x5B 0x52
disconnected
DHCP Success
UID: 0xD7 0xCB 0x5B 0x52
HTTP/1.1 400 Bad Request
Date: Fri, 16 Apr 2021 09:35:40 GMT
Server: Apache
Content-Length: 268
Connection: close
Content-Type: text/html; charset=iso-8859-1
<html><title>Bad request</title><head></head><body><p>Anomalia nella richiesta al sito, se il problema persiste <b>cancella i cookie</b>, <a href='https://support.google.com/accounts/answer/32050?hl=it' target='_blank'>maggiori informazioni</a></li></ul></body></html>disconnected
sometime after the UID print the program jump on Riavvia() -> reaload
sometimes print disconnected
and sometimes print bad request (the URL point at the right page)
so the good news is that you do get an answer.
The bad news is that it does not look like this at all
<html>
<head></head>
<body>N001</body>
</html>
I'm sending a GET for /chiavi.php?uid=1020304050 --> would an incorrect UID generate the response you saw? can you try with a legit UID instead of 1020304050?
Connected to server
HTTP/1.1 400 Bad Request
Date: Fri, 16 Apr 2021 13:01:27 GMT
Server: Apache
Content-Length: 268
Connection: close
Content-Type: text/html; charset=iso-8859-1
<html><title>Bad request</title><head></head><body><p>Anomalia nella richiesta al sito, se il problema persiste <b>cancella i cookie</b>, <a href='https://support.google.com/accounts/answer/32050?hl=it' target='_blank'>maggiori informazioni</a></li></ul></body></html>
disconnected