Trying to connect ethernet shield to local apache server

So for the most part I have had really great luck with the ethernet shield that I recently purchased. I am now trying to upload analog data from the arduino to a local mysql db. My write_data.php file seems to be working perfectly and I can upload data to the data base whenever I call the write_data.php file in the url. I am using a netgear router and I checked the allowed devices list on the netgear genie network admin and the arduino was listed, which makes sense because it has worked for all of my other projects. Would really apprieciate some advice and ideas here. Also, not sure if this would make a difference but I am using mamp as my local server enviroment. The censored files are below :


<?php // Prepare variables for database connection $dbusername = "test"; // enter database username, I used "arduino" in step 2.2 $dbpassword = "test"; // enter database password, I used "arduinotest" in step 2.2 $server = ""; // IMPORTANT: if you are using XAMPP enter "localhost", but if you have an online website enter its address, ie."" // Connect to your database $dbconnect = mysql_pconnect($server, $dbusername, $dbpassword); $dbselect = mysql_select_db("Test",$dbconnect); // Prepare the SQL statement $sql = "INSERT INTO Test.Sensor (value) VALUES ('".$_GET["value"]."')"; // Execute SQL statement mysql_query($sql); ?>

arduino sketch:

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

byte mac = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Enter the IP address for Arduino, as mentioned we will use
// Be careful to use , insetead of . when you enter the address here
IPAddress ip(192,xxx,xx,xx);

int photocellPin = 2; // Analog input pin on Arduino we connected the SIG pin from sensor
int photocellReading; // Here we will place our reading

char server = “”; // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie. “”)

// Initialize the Ethernet server library
EthernetClient client;

void setup() {

// Serial.begin starts the serial connection between computer and Arduino

// start the Ethernet connection
Ethernet.begin(mac ,ip);


void loop() {

photocellReading = analogRead(photocellPin); // Fill the sensorReading with the information from sensor

// Connect to the server (your computer or web page)
if (client.connect(server,8888)) {
client.print(“GET /write_data.php?”); // This
client.print(“value=”); // This
client.print(photocellReading); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
client.println(" HTTP/1.1"); // Part of the GET request
client.println(“Host:”); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: “”)
client.println(“Connection: close”); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server


else {
// If Arduino can’t connect to the server (your computer or web page)
Serial.println("–> connection failed\n");

// Give the server some time to recieve the data and store it. I used 10 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.

Can you telnet to your server and check if you send exactly what is in your arduino code if that works or not. I have seen web servers requiring user-agent for example.

265 6.659723 de:ad:be:ef:fe:ed Broadcast ARP 60 Who has Tell

I have wireshark and this is the response that I have found that is associated with my arduinos ip address which is Although not sure what this means.

Don't care about wireshark at that time. See if sending what you want to send makes sense for your server..

Open a telnet connection to your server
Type GET /.... HTTP/1.1. (Exactly as it would be sent in your arduino code), hit enter
Type Host: and hit enter (hopefully you don't have the xxx :slight_smile: )
TYpe Connection: close and hit enter 3 times

See what happens.

(Btw you don't need to obsfucate your 192.168.x.x address to us, that's a local network address so we can't do anything with it)

Are you certain the server is listening to this port? Apache normally listens to port 80.

 if (client.connect(server,8888)) {