Page 1 of 1

Arduino/Ethernet – looking for PHP help

Arduino/Ethernet – looking for PHP help

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Hardware Arduino Arduino/Ethernet – looking for PHP help

This topic contains 3 replies, has 2 voices, and was last updated by  hans 3 weeks, 5 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • 11148

    hans
    Keymaster

    Based on a post at the Arduino Ethernet topic (link);

    Thanks for you answer.

    By the way i managed to connect and push data to server. All thanks to your project.

    As you know i’m trying to push RFID card data to MYSQL server.And i’m testing it 2 cards.

    But i had a problem again.When i try to push first data it won’t work.After first try it sends data.But the again one more problem is when i change the card it sends same information and after it sends changed card data.

    ————add_data.php————–


    <?php
    include (‘dbconnect.php’);
    $sql_insert = “INSERT INTO test.myguests (firstname, card_id, lastname) VALUES (‘”.$_GET[“firstname”].”‘, ‘”.$_GET[“card_id”].”‘, ‘”.$_GET[“lastname”].”‘)”;
    if(mysqli_query($con,$sql_insert))
    {
    echo “Done”;
    mysqli_close($con);
    }
    else
    {
    echo “error is “.mysqli_error($con );
    }
    ?>

    by the way i have to tell that RFID reader and ENC28J60 are using same ports(50,51,52).And i’m controlling them using RFID SDA pin,ENC28J60’s CS pin.
    and here is my arduino code:

    #include <SPI.h>
    #include <MFRC522.h>
    #include <UIPEthernet.h> // Used for Ethernet
    #include <LiquidCrystal.h>
    #define SS_PIN 20
    #define RST_PIN 2
    MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
    // **** ETHERNET SETTING ****
    // Ethernet MAC address – must be unique on your network – MAC Reads T4A001 in hex (unique in your network)
    static byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
    // For the rest we use DHCP (IP address and such)
    EthernetClient client;
    char server[] = “192.168.0.105”; // IP Adres (or name) of server to dump data to
    int interval = 5000; // Wait between dumps
    LiquidCrystal lcd(22, 23, 4, 5, 6, 7);
    void setup()
    {
      SPI.begin();// Initiate SPI bus
      mfrc522.PCD_Init(); // Initiate MFRC522
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print(“eAttendance v1.0”);
      lcd.setCursor(0, 1);
      lcd.print(“Connecting…”);
      pinMode(20, OUTPUT);
      pinMode(53, OUTPUT);
      digitalWrite(53, LOW);
      digitalWrite(20, HIGH);
      Serial.begin(9600); // Initiate a serial communication
      Ethernet.begin(mac);
      Serial.println(“eAttendace System v1.0”);
      Serial.println(“—————————————–\n”);
      Serial.print(“IP Address : “);
      Serial.println(Ethernet.localIP());
      Serial.print(“Subnet Mask : “);
      Serial.println(Ethernet.subnetMask());
      Serial.print(“Default Gateway IP: “);
      Serial.println(Ethernet.gatewayIP());
      Serial.print(“DNS Server IP : “);
      Serial.println(Ethernet.dnsServerIP());
      Serial.println(“Approximate your card to the reader…”);
      Serial.println();
    }
    void loop()
    {
      lcd.setCursor(0, 0);
      lcd.print(“eAttendance v1.0”);
      lcd.setCursor(0, 1);
      lcd.print(“Waiting card…”);
      digitalWrite(53, HIGH);
      digitalWrite(20, LOW);
      // Look for new cards
      if ( ! mfrc522.PICC_IsNewCardPresent())
      {
        return;
      }
      // Select one of the cards
      if ( ! mfrc522.PICC_ReadCardSerial())
      {
        return;
      }
      //Show UID on serial monitor
      Serial.print(“UID tag :”);
      String content = “”;
      byte letter;
      for (byte i = 0; i < mfrc522.uid.size; i++)
      {
        Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? ” 0″ : ” “);
        Serial.print(mfrc522.uid.uidByte[i], HEX);
        content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? ” 0″ : ” “));
        content.concat(String(mfrc522.uid.uidByte[i], HEX));
      }
      Serial.println();
      Serial.print(“Message : “);
      content.toUpperCase();
      if (content.substring(1) == “C2 E7 BC 50”) //change here the UID of the card/cards that you want to give access
      {
        // if you get a connection, report back via serial
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(“Sendind…”);
        lcd.setCursor(0, 1);
        lcd.print(“ID:C2-E7-BC-50”);
        digitalWrite(53, LOW);
        digitalWrite(20, HIGH);
        if (client.connect(server, 80)) {
          Serial.println(“-> Connected”);
          // Make a HTTP request:
          client.print( “GET /card/add_data.php?”);
          client.print(“firstname=”);
          client.print( “Gerelsukh” );
          client.print(“&&”);
          client.print(“card_id=”);
          client.print( “C2E7BC50” );
          client.print(“&&”);
          client.print(“lastname=”);
          client.print( “Tsogtgerel” );
          client.println( ” HTTP/1.1″);
          client.print( “Host: ” );
          client.println(server);
          client.println( “Connection: close” );
          client.println();
          client.println();
          Serial.println(“Writed”);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print(“Data Sent!”);
          client.stop();
        }
        else {
          // you didn’t get a connection to the server:
          Serial.println(“–> connection failed/n”);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print(“No Connection!”);
        }
      }
      else if (content.substring(1) == “7A 8F 74 63”) //change here the UID of the card/cards that you want to give access
      {
        // if you get a connection, report back via serial:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(“Sendind…”);
        lcd.setCursor(0, 1);
        lcd.print(“ID:7A-8F-74-63”);
        digitalWrite(53, LOW);
        digitalWrite(20, HIGH);
        client.connect(server, 80);
        if (client.connect(server, 80)) {
          Serial.println(“-> Connected”);
          // Make a HTTP request:
          client.print( “GET /card/add_data.php?”);
          client.print(“firstname=”);
          client.print( “Gombo” );
          client.print(“&&”);
          client.print(“card_id=”);
          client.print( “7A8F7463” );
          client.print(“&&”);
          client.print(“lastname=”);
          client.print( “Khorloo” );
          client.println( ” HTTP/1.1″);
          client.print( “Host: ” );
          client.println(server);
          client.println( “Connection: close” );
          client.println();
          client.println();
          Serial.println(“Writed”);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print(“Data Sent!”);
          client.stop();
        }
        else {
          // you didn’t get a connection to the server:
          Serial.println(“–> connection failed/n”);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print(“No Connection!”);
        }
        delay(interval);
      }
      else {
        Serial.println(“Unregistered User”);
        delay(3000);
      }
      digitalWrite(53, HIGH);
      digitalWrite(20, LOW);
    }

    any advices will be appreciated.

    11150

    hans
    Keymaster

    Hi Gombo,

    Apologies I had to remove your code from the original comment you placed – it was just getting too long.

    Anyhoo … I’d first test my PHP script manually, something like this;

    http://yourserver/add_data.php?firstname=Jogn&card_id=123&lastname=Doe

    Keep poking at it and see what does and what does not work.
    Once you’re 100% sure this work manually, then start tinkering with the Arduino sketch.
    Much easier testing and much faster 

    11152

    hordeous
    Participant

    I made some improvements in code.And now it’s working like a charm.Thanks to Ethernet Data Push article.

    Change:
    void loop()
    {
      client.stop();
      lcd.setCursor(0, 0);
      lcd.print(“eAttendance v1.0”);
      lcd.setCursor(0, 1);
      lcd.print(“Waiting card…”);
      digitalWrite(53, HIGH);
      digitalWrite(20, LOW);
      ...
        client.connect(server,80);
        if (client.connect(server, 80)) {
          ...
    }
    11154

    hans
    Keymaster

    Awesome! That is good news! 

Viewing 4 posts - 1 through 4 (of 4 total)



You must be logged in to reply to this topic.