Pages: [1]   Go Down
Author Topic: Connecting to PHP over LAN  (Read 2504 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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 192.168.0.2, and I have the httpd.conf file set to LISTEN 192.168.0.2:80. The IP of the arduino is 192.168.0.3, 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: 192.168.0.2:80/test2.php
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);
 Serial.begin(9600);
 delay(1000);
}

void loop(){
 // connect to server
 Serial.println("Try to connect to server:");
 if (client.connect()){
    Serial.println("OK");
 } else {
    Serial.println("Fail"); 
 }
 if (client.connected()){ 
   client.println("GET /test2.php");   
   char c = client.read();
   Serial.print(c);
   for(;smiley-wink
  ; 
} else {
   Serial.println("Connection problem/discconncted.");
 }
 client.stop();
 Serial.println("Client stopped.");
 delay(10000);
}

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

Thanks!
Logged

0
Offline Offline
Tesla Member
***
Karma: 115
Posts: 8932
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have test2.php in the apache htdocs folder?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Johannesburg
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 95
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Portugal
Offline Offline
Edison Member
*
Karma: 27
Posts: 1414
Tomorrow I will know a BIT more than yesterday
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your php file?
I also working in a similar project
Thanks
Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


Pages: [1]   Go Up
Jump to: