I am involved in a project that is creating a RFID reader that talkes to a database, confirming if a person has purchased a ticket for a particular event. To this point I have got everything working except for the part where the the HTTP GET response is sent back to the Arduino.
A "#1" is sent back to the Ardiuno if the person has purchased a ticket and a "#0" is if they haven't.
~I need to parse the incoming HTTP data to determine if a #1 or #0 is sent back and then light up a LED accordingly. How can I do this???
A "#1" is sent back to the Ardiuno if the person has purchased a ticket and a "#0" is if they haven't.
How is that data being received on the Arduino? Show some code.
If you KNOW that you will always get two characters (not necessarily a safe assumption), you can just test whether the second character is equal to '1' or '0'.
I receive a "#1" or "#0" because of the asp.net object handler that I have sitting on my website. The Arduino sends a query string through a GET command and the handler page uses those parameters to query a database to give me a yes or no answer. This answer is sent back to the Arduino in a #1 or #0.
Here's what I was trying to do:
if (client.available()) {
char read = client.read();
String c = read;
Serial.print(c);
if (c.endsWith("#1")) {
Serial.println("Ticket Purchased");
}
else {
Serial.print("No Ticket Purchased");
}
}
I find that incoming client data is one character at a time so the IF statement looks to see if the data endsWith a #1, it checks the first letter of the data stream which is "H" from "HTTP/1.1 OK". I tried storing the whole stream as a string and then checking with endsWith but still no luck.
And every time the client data is sent back from the GET request, there is always a #1 or #0, so it is always there to parse.
if (client.available()) {
char read = client.read();
String c = read;
Serial.print(c);
if (c.endsWith("#1")) {
Serial.println("Ticket Purchased");
}
else {
Serial.print("No Ticket Purchased");
}
}
There's no while loop here to read all the data. The if(client.available()) statement should be while(client.available()).
The c variable should be declared outside of the while loop.
The read variable should be appended to the string c.
Even simpler, though, than using strings is just a simple test:
while(client.available() > 0)
{
char c = client.read();
if(c == '#')
{
while(client.available() == 0) { } // Do nothing while we wait for the next value
c = client.read();
if(c == '0')
// No way, Jose. Go but a ticket
else
// Enjoy the concert
}
}
That works! Thank you so much. This part of my project has been a huge stumbling block. I am new at the Arduino and all its code so I will look over the code you gave me and learn how it works.
Hi to all!
I'm a happy new owner of an arduino + ethershield and a bunch of el. component Great isn't it ?!
I am working on a project for small home automation - turning lights/appliances on/off through arduino web server connected to my lan. Unfortunately I am a bit stuck. I managed to make arduino turn on/off a relay through a small web page and i don't know how make arduino parse more than one argument in the url in order to turn on/off more relays ...
I am very far from programmer however have little experience with PHP there you have parse_url and parse_string is there a trick to achieve that functionality in arduino language ?
I thought that the best way to achieve what i intend would be to put these arguments in an array and later to parse the array independently of how many digital outputs you have received at a time.
Not familiar with strtok function. Couldn't find it in the reference (probably my searching capabilities)
Will be very grateful to get more info or example how to use it.
Couldn't find it in the reference (probably my searching capabilities)
Robtilaart provided links to the strtok function. The Reference page only lists the stuff you might find in chapter 1 of a C book - variable types, loops, basic operators (+, -, &, &&, etc.) and the functions that are specific to the Arduino. Any C function, with limited exceptions - fopen, for example, can be used on the Arduino.
Don't feel that you need to limit yourself to those functions on the reference page.