Hello guys,
For a test i was making a system for checking in and out to register my times in an online system. I am using an arduino uno, ethernet shield and a RDM6300 rfid module.
Now here is my problem. When I scan a tag it is inserted in the database and I let my php echo out the table from my database. My arduino receives this perfect.
As soon as i edit my php and change "SELECT voornaam, checkedin FROM users" to "SELECT voornaam, checkedin FROM users WHERE tagid='$arduinobericht" my arduino receives all data but not the 2 values from the database. When i open the php page in a browser it displays it without any problem.
Anyone can help me with the problem ?
database tables (tablename - field1, field2 ...)
log - id, tagid, timestamp
users - id, voornaam, achternaam, tagid, checkedin
php code:
<?php
include("connect.php");
$arduinobericht=$_GET["tagid"];
$Sql="insert into log(tagid) values ('".$_GET["tagid"]."')";
mysqli_query($con,$Sql);
$result = mysqli_query($con,"select * from users WHERE tagid='$arduinobericht' ");
//$response=mysql_fetch_array($result);
If ($response [4] == "1")
{
mysqli_query($con,"UPDATE users SET checkedin=0 WHERE tagid='$arduinobericht' ");
//echo "$response[1]";
echo " checked out";
}
else
{
mysqli_query($con,"UPDATE users SET checkedin=1 WHERE tagid='$arduinobericht' ");
//echo "$response[1]";
echo " checked in";
}
$query = "SELECT voornaam, checkedin FROM users WHERE tagid='$arduinobericht'";
$result = mysqli_query($con, $query);
$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%s (%s)\n", $row[voornaam], $row[checkedin]);
//$result=mysqli_query($con,"select * from users");
//$row = mysqli_fetch_array($result);
//echo $row["voornaam"];
//printf("<arduino> %s %s </arduino>", $row["voornaam"], $row["checkedin"]);
mysqli_free_result($result);
?>
arduino code:
#include <SoftwareSerial.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
*my adruino mac is here* };
byte server[] = {
server.ip.adress.here }; //
EthernetClient client;
String http_response = "";
int response_start = 0;
int response_end = 0;
SoftwareSerial rfid(5,6);
String tagString;
char tagNumber[14];
boolean receivedTag;
void setup()
{
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
Serial.begin(9600);
Serial.print("arduino ip = ");
Serial.println(Ethernet.localIP());
//lcd.begin(16, 2);
//lcd.print("systeem opgestart");
Serial.println("ethernet started");
rfid.begin(9600); // the RDM6300 runs at 9600bps
Serial.println("Systeem klaar voor een tag!");
delay(2000);
}
void loop()
{
checkrfid();
if (receivedTag)
{
tagString=tagNumber;
Serial.println();
Serial.print("Tag Number: ");
Serial.println(tagString);
sendrfid(); // send rfid to database
delay(2500); // a delay of 1500ms and a flush() seems to stop tag repeats
rfid.flush();
}
memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber
}
void checkrfid()
{
receivedTag=false;
while (rfid.available())
{
int BytesRead = rfid.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag
receivedTag=true;
}
}
void sendrfid()
{
if (client.connect(server,80))
{
Serial.println("Connected!");
client.print( "GET /rfid/view.php");
client.println( " HTTP/1.1");
client.println( "Host: *my server domain" );
client.println("Connection: close");
client.println();
Serial.print("Tag ");
Serial.print(tagString);
Serial.println(" submitted to database.");
Serial.println("disconnecting.");
delay(1500);
while (client.available()>0)
{
char c = client.read();
http_response += c; // We store the response in a string
}
Serial.println(http_response);
filterresponse();
client.stop();
}
else
{
Serial.println("Cannot connect to Server");
}
}
void checkedin ()
{
tone(8, 250,150);
delay(150);
tone(8, 350, 250);
}
void checkedout ()
{
}
void filterresponse()
{
if((http_response.indexOf("<arduino>") > -1 )&&(http_response.indexOf("</arduino>") > -1 )){
// We check if the <arduino></arduino> are there.
response_start = http_response.indexOf("<arduino>")+9;
// Where it begins, the 9 is the length of ' <arduino> ',
// since we dont want it to appear in the response.
response_end = http_response.indexOf("</arduino>");
// Where it ends
http_response = http_response.substring(response_start,response_end);
// We keep only the response of the website
Serial.print("Website response : ");
Serial.println(http_response);
Serial.println();
}
else {
Serial.println("No response detected...");
Serial.println();
}
}