I cant connect arduino to php

hello again, i am using arduino uno r3, mfrc522, w5100 and also.i disconnected my internet so i am only using xampp as my localhost

my gateway is 192.168.1.1
my ip address is 192.168.1.8
my subnet is 255.255.255.0

i set up my connection on arduino with an ip address of 192.168.1.9

so when i tried to start connecting it.i print my ip address in arduino to check if it is connected and it shows 15.16.17.18 ..

then i tried to POST it to php but i cant get the data from arduino..can anyone help me with this and tell me what's wrong ?

i have less knowledge in networking and php and sorry for my bad english

Post your arduino sketch here and may be some one can help.
15.16.17.18 could be an example IP address in a configuration file which you have forgotten to change.

Here is my code, I still haven't put yet on how to POST on php

#include <SPI.h>
#include <MFRC522.h>
#include <Ethernet.h>

/*  My PIN configuration
 *   
 *         MFRC522 PIN    W5100 PIN
 *  RST        RST           9 
 *  SS         SDA           10
 *  MOSI       MOSI          11
 *  MISO       MISO          12
 *  SCK        SCK           13
 *
*/
#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte gateway[] = {192, 168, 1, 1};
byte subnet[] = {255, 255, 255, 0};

IPAddress ip(192, 168, 1, 9);
EthernetClient client;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();

  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  Ethernet.begin(mac);
}

void loop() {

  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) { 
    return;
  }
  String uID;
  
  String valA = String(mfrc522.uid.uidByte[0], HEX);
  String valB = String(mfrc522.uid.uidByte[1], HEX);
  String valC = String(mfrc522.uid.uidByte[2], HEX);
  String valD = String(mfrc522.uid.uidByte[3], HEX);
  uID = valA + valB + valC + valD;
  Serial.print(uID);
  Serial.println();
  Serial.println(Ethernet.localIP());
  mfrc522.PICC_HaltA();
}

this is also my configuration on my network

untitled.jpg

I hate it when people post screenshots with scroll bars in them ... it confuses me when I try to use them! :slight_smile:
(your image is also a bmp file named as a jpg). Not sure what your problem it, but the 15,16,17,18 sure has the feel of an index or something that you are getting instead of what it was supposed to point at.

sorry about the picture..i just screenshot it in my computer and also i think i should rephrase my problem

i tried this code which was posted in the examples

#include <SPI.h>
#include <Ethernet.h>

// network configuration. dns server, gateway and subnet are optional.

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  

// the dns server ip
IPAddress dnServer(192, 168, 1, 1);
// the router's gateway address:
IPAddress gateway(192, 168, 1, 1);
// the subnet:
IPAddress subnet(255, 255, 255, 0);

//the IP address is dependent on your network
IPAddress ip(192, 168, 1, 8);

void setup() {
 Serial.begin(9600);

 // initialize the ethernet device
 Ethernet.begin(mac, ip, dnServer, gateway, subnet);
 //print out the IP address
 Serial.print("IP = ");
 Serial.println(Ethernet.localIP());
}

void loop() {
}

and my output is
IP = 15.16.17.18

so my problem is..it should display the ip address you inputed but it shows different..and i research about it in google and found out it on NAT which is i dont understand and dont wanna go deeper..im only just trying to connect and get the data from arduino to php.

"sorry about the picture..i just screenshot it in my computer and also i think i should rephrase my problem" - yes, I know - I was poking fun at myself. I managed to do that all the time - grab a screenshot then forget I am looking at a screen shot and try to click or scroll something. :o

NAT is something that goes on (typically) in your router between the local network (LAN - in your house for example) and the outside world (WAN) It converts private addresses on the LAN (192.168.?.? or 10.?.?.? for example) to addresses for the internet. Think of it as the switchboard for a big company - you can only call in on a couple of numbers, but those can be connected to thousands of employees by the switchboard. Sort of. A bit more complex than that, but that is the basics of what NAT (Network Address Translation) does. All the machines on your local network (LAN) should have similar numbers - like 192.168.1.? for example (and typically the router will have 192.168.1.1 as it's LAN side.)

i see.its like you can make anykind of ip address using 15.16.17.18

but how do i connect it to my computer if it can be anykind of address..i need to connect arduino to my php so i can pass the uid of my rfid card

ok it seems i got printing it somehow like 192.168.1.8 as anything i putted in my IPaddress..but the next problem is when i try this code

/*
  Web client

 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe, based on work by Adrian McEwen

 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress dnServer(192, 168, 1, 1);
// the router's gateway address:
IPAddress gateway(192, 168, 1, 1);
// the subnet:
IPAddress subnet(255, 255, 255, 0);

//the IP address is dependent on your network
IPAddress ip(192, 168, 1, 6);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, dnServer, gateway, subnet);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}

it prints out like this

Failed to configure Ethernet using DHCP
connecting...
connected

disconnecting.

any ideas ?

ok i got it working now. i got some respone in google with this code

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,6);
IPAddress server(192,168,1,1);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());

Serial.println("Connecting to google....");
int ret;
  if (ret = client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
    Serial.println(ret);
  }
 
}

void loop() {

  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}

so ok :smiley: thx for letting me understand the addresses

and now can anyone give some short code for sending data to php ?
for example if have like this.

<?php
 $rfid = "";

?>

how do i send the uid from arduino to $rfid ?

Take a look at the GET http if you are not concerned about sensitive data (it is part of the URL when it sends it, but it makes it easy to debug). Here are a couple of links to check out:

https://www.ntu.edu.sg/home/ehchua/programming/webprogramming/HTTP_Basics.html