HTTP GET Request 403 Error when trying to send Arduino RC522 data to mySQL


hello,

i've had issues sending data mysql database using wamp server , arduino uno. below arduino code using project:


code: [select]


/*
arduino uno,ethernet shield, rfid mfrc522 & mysql
     
  circuit:
  * typical pin layout used:(mfrc 522)
 * -----------------------------------------------------------------------------------------
 *             mfrc522      arduino       arduino   arduino    arduino          arduino
 *             reader/pcd   uno/101       mega      nano v3    leonardo/micro   pro micro
 * signal      pin          pin           pin       pin        pin              pin
 * -----------------------------------------------------------------------------------------
 * rst/reset   rst          9             9         d9         reset/icsp-5     rst
 * spi ss      sda(ss)      4/10          4/53      d10        10               10
 * spi mosi    mosi         11 / icsp-4   51        d11        icsp-4           16
 * spi miso    miso         12 / icsp-1   50        d12        icsp-1           14
 * spi sck     sck          13 / icsp-3   52        d13        icsp-3           15
 
 */


#include<spi.h>
#include<mfrc522.h>
#include<softwareserial.h>
#include <ethernet.h>
#define ss_pin 4 //for rfid ss pin becasuse using both ethernet shield , rs-522
#define rst_pin 9
#define no_of_card 2

byte mac[] = { 0xde, 0xaa, 0xbe, 0xee, 0xfe, 0xed }; //random address assigned doesn't interfere
ipaddress server(xx,xx,xxx,xx);   //this ip address of wamp server. obtained typing in ipconfig in command line , using ipv4 address. address of wamp server , computer should same
ipaddress ip(xx,xx,xxx,xx); //this ip address of ethernet shield. obtained call ethernet.localip()
ethernetclient client;
softwareserial myserial(8,9);
mfrc522 rfid(ss_pin,rst_pin);
mfrc522::mifare_key key;
byte id[no_of_card][4]={              //these id's of 2 rfid cards
   {0xb0,0xe5,0x7f,0x7a},             //rfid no-1
   {0x00,0xc9,0x49,0x39}              //rfid no-2             
};
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 configure ethernet using dhcp");
    ethernet.begin(mac, ip);
  }
  delay(1000);
  serial.println("connecting...");
  serial.print("my clientip address: ");
  serial.println(ethernet.localip());
  serial.println("waiting card...");
 }
void loop()
{int m=0;
  if(!rfid.picc_isnewcardpresent())
  return;
  if(!rfid.picc_readcardserial())
  return;

//this gets id of rfid cards

  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 number:");
                  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");
      sending_to_db();
      j=0;
    }
   }
  }
 
     // halt picc
  rfid.picc_halta();

  // stop encryption on pcd
  rfid.pcd_stopcrypto1();
 }

 void sending_to_db()   //connecting mysql
 {
   if (client.connect(server, 80)) {
    serial.println("connected");
    // make http request:
    client.print("get /rfid/rfid_read.php?allow="); //this request accesses php code stored in rfid folder inside www folder in wamp server
       
    if(j!=no_of_card)
    {
      client.print('1'); //card valid
    }
    else
    {
      client.print('0'); //card not valid
    }
   
    client.print("&id=");
    for(int s=0;s<4;s++)
                  {
                    client.print(rfid.uid.uidbyte[s]);
                                 
                  }
    client.print(" ");      //space before http/1.1
    client.print("http/1.1");
    client.println();
    client.println("host: xx.xx.xxx.xx"); //ip address of server
    client.println("connection: close");
    client.println();

// tried comment out request above , try request below in case syntax of above request off. still received 403 error

//client.print("get /rfid/rfid_read.php?allow=1&id=176229127122 http/1.1\r\n");
   
  } else {
    // if didn't connection server:
    serial.println("connection failed");
  }
  client.stop();
 }





and here php code:

code: [select]

<?php

class rfid{
 
public 
$link='';
 
function __construct($allow$id){
  
$this->connect();
  
$this->storeindb($allow$id);
 
}
 
 
//connects to database rfid_data and to mysql account nberko4

function connect(){
  
$this->link mysqli_connect('localhost','nberko4','********') or die('cannot connect to the db');
  
mysqli_select_db($this->link,'rfid_data') or die('cannot select the db');
 
}
 
 
//inserts rfid and allow into table rfid

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']);

}



?>







so i've been able upload code database typing http://localhost/rfid/rfid_read.php?allow=1&id=176229127122 in browser, know php script working.

also, i've looked @ httpd.conf file apache , phpmyadmin.conf file in order enable access ip addresses. believe settings correct, , mysql database should effected ipaddresses other local host.

essentially, requests working when send them local host (server), not when i'm sending them arduino (ethernet shield ip address).

thanks in advance help!

also, i've looked @ httpd.conf file apache , phpmyadmin.conf file in order enable access ip addresses. believe settings correct, , mysql database should effected ipaddresses other local host.


to know sure, run url ip replacing "localhost" different pc on local network, , you'd know if having access problem.



Arduino Forum > Using Arduino > Programming Questions > HTTP GET Request 403 Error when trying to send Arduino RC522 data to mySQL


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts