Go Down

Topic: There not errors... Everything is ok... But data is not write Mysql Database... (Read 441 times) previous topic - next topic

kaanrevan

Hi. My circuit is ok, I use Arduino Uno + RFID(RC522) + Ethernet Shield...

Arduino Uno Code is ;


Code: [Select]
#include<SPI.h>
#include<MFRC522.h>
#include<SoftwareSerial.h>
#include <Ethernet.h>
#define SS_PIN 4 //FOR RFID SS PIN BECASUSE WE ARE USING BOTH ETHERNET SHIELD AND RS-522
#define RST_PIN 9
#define No_Of_Card 3
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char server[] = "192.168.1.99";   //YOUR SERVER
IPAddress ip(192, 168, 6, 177);
EthernetClient client;
SoftwareSerial mySerial(6,7);     
MFRC522 rfid(SS_PIN,RST_PIN);
MFRC522::MIFARE_Key key;
byte id[No_Of_Card][4]={
  {240,135,55,166},             //RFID NO-1
  {252,41,131,99},             //RFID NO-2
  {151,94,80,84}              //RFID NO-3
};
byte id_temp[3][3];
byte i;
int j=0;
void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  for(byte i=0;i<6;i++)
  {
    key.keyByte[i]=0xFF;
  }
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }
  delay(1000);
  Serial.println("connecting...");
 }
void loop()
{int m=0;
  if(!rfid.PICC_IsNewCardPresent())
  return;
  if(!rfid.PICC_ReadCardSerial())
  return;
 
for(i=0;i<4;i++)
  {
   id_temp[0][i]=rfid.uid.uidByte[i];
             delay(50);
  }
 
   for(i=0;i<No_Of_Card;i++)
  {
          if(id[i][0]==id_temp[0][0])
          {
            if(id[i][1]==id_temp[0][1])
            {
              if(id[i][2]==id_temp[0][2])
              {
                if(id[i][3]==id_temp[0][3])
                {
                  Serial.print("your card no :");
                  for(int s=0;s<4;s++)
                  {
                    Serial.print(rfid.uid.uidByte[s]);
                    Serial.print(" ");
                   
                  }
                  Serial.println("\nVALID");
                  Sending_To_DB();
                  j=0;
                           
                            rfid.PICC_HaltA(); rfid.PCD_StopCrypto1();   return;
                }
              }
            }
          }
   else
   {j++;
    if(j==No_Of_Card)
    {
      Serial.println("inVALID");
      Serial.print("your card no :");
                  for(int s=0;s<4;s++)
                  {
                    Serial.print(rfid.uid.uidByte[s]);
                    Serial.print(" ");
                   
                  }
      Sending_To_DB();
      j=0;
    }
   }
  }
 
     // Halt PICC
  rfid.PICC_HaltA();
// Stop encryption on PCD
  rfid.PCD_StopCrypto1();
 }

 void Sending_To_DB()   //CONNECTING WITH MYSQL
 {
   if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    //Serial.print("GET rfid/nodemcu_rfid/rfid_read.php?allow=");
    client.print("GET rfid/nodemcu_rfid/rfid_read.php?allow=");     //YOUR URL
    if(j!=No_Of_Card)
    {
     // Serial.print('1');
      client.print('1');
    }
    else
    {
     // Serial.print('0');
      client.print('0');
    }

   // Serial.print("&id=");
    client.print("&id=");
    for(int s=0;s<4;s++)
                  {
                   // Serial.print(rfid.uid.uidByte[s]);
                    client.print(rfid.uid.uidByte[s]);
                                 
                  }
                 // Serial.println(" ");
    client.print(" ");      //SPACE BEFORE HTTP/1.1
    client.print("HTTP/1.1");
    client.println();
    client.println("Host: 192.168.1.99");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  client.stop();
 }




All Code is Run Good...





Php file Code is;

Code: [Select]
<?php
class rfid{
 public 
$link='';
 function 
__construct($allow$id){
  
$this->connect();
  
$this->storeInDB($allow$id);
 }
 
 function 
connect(){
  
$this->link mysqli_connect('localhost','root','') or die('Cannot connect to the DB');
  
mysqli_select_db($this->link,'rfveritabani') or die('Cannot select the DB');
 }
 
 function 
storeInDB($allow$id){
  
$query "insert into rfid set rfid='".$id."', allow='".$allow."'";
  
$result mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
 
}
if(
$_GET['allow'] != '' and  $_GET['id'] != ''){
 
$rfid=new rfid($_GET['allow'],$_GET['id']);
}
?>


This code is Run good when i send data from Chrome Address Bar...

Problem is;  all process is run without errors, but open phpmyadmin and open tables... But this is not save data that I sent from RFID.

What's problem? I dont understand. Please help. Thanks in advance.


evanmars

Out of bounds?

Code: [Select]
byte id_temp[3][3]; //id_temp[3][0], id_temp[3][1], id_temp[3][2]


for(i=0;i<4;i++)  //0, 1, 2, 3
  {
   id_temp[0][i]=rfid.uid.uidByte[i];
             delay(50);
  }

kaanrevan

Out of bounds?

Code: [Select]
byte id_temp[3][3]; //id_temp[3][0], id_temp[3][1], id_temp[3][2]


for(i=0;i<4;i++)  //0, 1, 2, 3
  {
   id_temp[0][i]=rfid.uid.uidByte[i];
             delay(50);
  }

I don't understand you. Out of Bounds? This arduino codes has this screen shoot below. Should I edit arduino codes?



PaulS

Quote
Should I edit arduino codes?
Yes. You are trying to store the rfid values in arrays that are too small.

Quote
But this is not save data that I sent from RFID.
Only you have any idea what you think you sent, what you designed the table to hold, and what actually gets stored in the table. Therefore, only you can determine why what you get is not what you expect. If you need help, you need to go back to kindergarten and learn to share.
The art of getting good answers lies in asking good questions.

Go Up