Go Down

Topic: Connecting to PHP over LAN (Read 3848 times) previous topic - next topic



I currently have a LAN set up (no internet) through a switch to connect my PC to my arduino with ethernet shield. On my PC I have apache running with a simple php script, and I would like to be able to get data from there on the arduino. My problem is that even though I have everything set up, I can't seem to connect to the PHP script from any computer on the LAN other than the computer running apache.

The IP of the PC is, and I have the httpd.conf file set to LISTEN The IP of the arduino is, and when it is connected I can successfully ping that IP address, but I am unable to connect to the server. I also tried hooking up a laptop to the LAN and was again unsuccessful in connecting to the PHP script, but could ping the IP just fine.

The URL of the script is:
Arduino code is:

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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x25, 0xE1 }; // MAC address of ethernet shield
byte ip[] = { 192, 168, 0, 3 };
byte server[] = { 192, 168, 0, 2 };

Client client(server, 80);

void setup(){
Ethernet.begin(mac, ip);

void loop(){
// connect to server
Serial.println("Try to connect to server:");
if (client.connect()){
} else {
if (client.connected()){ 
   client.println("GET /test2.php");   
   char c = client.read();
} else {
   Serial.println("Connection problem/discconncted.");
Serial.println("Client stopped.");

I'm hoping that someone can suggest something to get this working, and tips would be greatly appreciated.



Do you have test2.php in the apache htdocs folder?
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Like zoomkat said, check that the file in in the correct place.

Also as you can't reach it from your pc, check that the firewall on your server is allowing connections on port 80 for apache.


Thanks for the replies,

If I'm running my apache server through WAMP, does the file need to be in C:\Program Files\Apache Group\Apache2\htdocs\, or in C:\wamp\www\? I have it in both just in case.

What's the easiest way to check if there's a firewall blocking connections on a particular port? I have tried changing the port in apache as well, but that does not seem to change things.

Thanks again!


As you can't access the php from any computer (or arduino) other than the webserver then it suggests its the problem is with the webserver or router

* It could be the router - check the manual for the router and see what it says about firewall/port mapping/port blocking (personally I doubt it is this, but worth checking)
* Check the webserver is serving other pages - try a standard html page (helloworld.html or something) in the same folder as the php and see if you can get it. If not you need to check the folders the webserver is pointing to (see WAMP documentation)
* Make sure you have the right site enabled - are you still running the default apache site or have you set up a different one (this basically the same as the folders above) (see WAMP documentation)


Thanks for the reply,

I'm not sure exactly what the issue was, but I switched the network switch out for a router, and it solved my issue. I assume it have something to do with DHCP.

Thanks for the help everyone!


Can you post your php file?
I also working in a similar project
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131