// post data to server
void postData() {
if (!inetOK) {
inetInit();
}
/*
unsigned int strSize = EEPROM.read(SERVER_ADDR_SIZE);
char server[strSize];
eeprom_read_string(SERVER_ADDR_OFFSET, server, strSize);
*/
//String myURL = "GET /attd_posting.php?tag=";
char myURL[] = "GET /attd_posting.php?tag=";
strcat(myURL, data);
strcat(myURL, " HTTP/1.1");
digitalWrite(readerLED, HIGH);
digitalWrite(systemLED, HIGH);
client.stop();
DEBUG_PRINTLN(F("Connecting to server..."));
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
DEBUG_PRINTLN(F("Connected!"));
// Make a HTTP request:
DEBUG_PRINTLN(F("Posting..."));
client.println(myURL);
DEBUG_PRINTLN(myURL);
client.print(F("Host: "));
client.println(server);
DEBUG_PRINT(F("Host: "));
DEBUG_PRINTLN(server);
client.println(F("Connection: close"));
client.println();
DEBUG_PRINTLN(F("Posted. Disconnecting from Server."));
DEBUG_PRINTLN();
client.flush();
client.stop();
DEBUG_PRINTLN(F("Connection closed"));
digitalWrite(systemLED, LOW);
digitalWrite(readerLED, LOW);
}
// if the server's disconnected, stop the client: A fail safe
else if (!client.connected()) {
client.stop();
DEBUG_PRINTLN(F("Posting failed."));
}
else {
// if you didn't get a connection to the server:
DEBUG_PRINTLN(F("Posting failed."));
}
Serial.flush();
keepAliveTimeElapsed = 0;
}
This code works perfectly!! So below is my background:
I'm trying to POST the rfid card data to a server for authentication. Posting works perfect as I am using it for attendance and no probs at all... now, if the same thing i want to use, where the card ID will be kept in a SQL, then i have one options only... posting it via http. I am using GET method for the purpose and not intended to change it. So, on GET http, if the thing is okey, then I will give output as 1 and if not, then i will output on web 0. I need to grab that as then I will open up a relay ased on 1/0. any ideas???
You can NOT do that. There is EXACTLY enough room in myURL for the data it contains. There is NOT room to add more data.
That is NOT a POST request being made, despite the incorrect print() statements.
Why do you think you need to make a POST request, to get the RFID data to the server?
any ideas???
Yes. You make a GET request, asking the server to do something and return a response. Then, you tell the server to f**k off, that you are not going to listen to it.
Change that attitude. Look at the examples that actually make GET requests properly AND read the server response.
PaulS:
Why do you think you need to make a POST request, to get the RFID data to the server?
Yes. You make a GET request, asking the server to do something and return a response.
I dont know, but these few days I am not that successful in telling people what I want to mean!!
I am using "GET" and I'm totally happy as that works perfect for me. Using the "GET" method of http, I can post the card ID into the SQL (as I am using a php page). Once I can post the card ID, I can validate and do the things like adding an entry in a table (as there is a match... basic login type thing, except of the POST method not used here via form.). So this part is fantastic for me, what I already developed. As I can read and validate from an SQL, using php, I also can generate a html output. The html output will be as much minimal as possible, just saying 1 or 0 for validation. There I need to read that output and extract that 1, so I can drive a relay, treating, it's authorized and you can drive it...
This reading part I'm stuck... can't figureout the way!!
[Consider, a RFID based accesscontrol system via a SQL based database and queries... php is because arduino does not need complex queries then... that can be done by php and arduino will read output for relay drive]
the people clearly understand what you have written.
The "problem" with your story is, that you are not doing POST requests, it's still a GET request even if you transmit "data" for your DB. As you are doing a GET you can fetch the data from the server.
I know it's ugly code because it is still a miss-usage of GET, but this pattern work's for sending a GET (with some variables) and receiving the answer. If you print it to serial or collect it to a char array should not be a big issue for you:
void sendGet() //client function to send/receie GET request data.
{
if (client.connect(myserver, 80)) {
Serial.println(F("client: connected"));
client.print (F("GET "));
client.print (F(HTTP_CLIENT_SERVERPATH));
client.print (F("?board="));
client.print (F(TXT_BOARDID));
client.print (F("&mes="));
client.print (DHT.temperature*10);
client.println(F(" HTTP/1.1"));
client.print (F("Host: "));
client.println(F(HTTP_CLIENT_SERVERNAME));
client.println();
}
else {
Serial.println(F("client: connection failed"));
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read();
Serial.print(c);
}
Serial.println();
Serial.println(F("client: disconnecting."));
client.stop();
}
noiasca:
The "problem" with your story is, that you are not doing POST requests, it's still a GET request even if you transmit "data" for your DB. As you are doing a GET you can fetch the data from the server.
hahaha!! I want to POST data using GET method!! The way is to be GET of http... but the purpose is basically not getting the data from server but sending the data to server...
The situation is kinda like, "Cow Eat Grass, Man Eat Cow, hence Man Eat Grass" fom beginning way that iti a GET, but I'm posting the data to server where posting means sending the value using the HTTP GET METHOD!!
Anyway, I will look in to your code and will come back very soon!!
PaulS:
That is NOT a misuse of GET. Suppose that you wish to google "POST vs. GET". How are you going to do that without sending data to the server?
Sending an RFID value, and getting "Hey, come on in" or "Keep out, thief" back is NOT a misuse of GET.
Stop using POST or post to mean send! The term POST means something far more than send.
Two HTTP Request Methods: GET and POST
Two commonly used methods for a request-response between a client and server are: GET and POST.
•GET - Requests data from a specified resource
•POST - Submits data to be processed to a specified resource
IMHO
This usecase is not regarding requesting a resource ("dear server, give me this or that page"), it's about submitting data to be processed ("dear Server - here is my rfid - let me in".
I compare it with a user authentication - I don't recommend to submit user/password via GET.
If "missuse" is the wrong word - I beg your indulgence - I'm no native Speaker.