Go Down

Topic: Arduino Uno+Ethernet Shield+XAMPP (Read 25558 times) previous topic - next topic

gerrynigro

Hi to all, and thanks in advance to anyone can help me.
I'm trying to realize an integration between Arduino and my Web server Apache running on my laptop. In particular I'm trying to make my arduino code launch a Web Service on my web server to insert a nel line on my mysql db.
I've the following configuration HW+SW.
1) Arduino Uno + Ethernet Shield
2) On my laptop I'm running the following configuration of XAMPP
   Apache 2.2.14
   MySQL 5.1.41
   PHP 5.3.1
3) Arduino IDE 0022 to develope

My actual SW is the following:
1) On Arduino:

Code: [Select]

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { YYY,YYY,YYY,YYY };
//byte server[] = { 173,194,33,104 }; // Google
//byte server[] = { XXX,XXX,XXX,XXX }; // Mio sito
byte server[] = { 127,0,0,1 }; // Mio sito
//byte server[] = { localhost }; // Mio sito

Client client(server, 80);

void setup() {

 Ethernet.begin(mac, ip);

 Serial.begin(9600);
 delay(1000);
 Serial.println("connecting...");

 // if you get a connection, report back via serial:
 if (client.connect()) {
   Serial.println("connected");
   // Make a HTTP request:
   //client.println("GET connessione su google HTTP/1.0"); //Su google - it works
   client.println("GET connessione mio web server HTTP/1.0"); // on my website - it doesn't work
   client.println();
 }
 else {
   // if you didn't get a connection to the server:
   Serial.println("connection failed");
 }
}


Unfortunately on Arduino serial monitor I receive:
Code: [Select]
connecting...
connection failed

disconnecting.


It's very strange for the following reasons:
1) If I lauch the same instruction with a normal browser
it works, the exposed web service works and I find a new row on my Database.

2) If I let the sketch run, specifying google server (173,194,33,104) as destination and
client.println("GET /search?q=Arduino HTTP/1.0");
as instruction, it works well, and I've the correct return in my serial monitor. I already exeperimeted all possibile server configuration (localhost, 127.0.0.1, XXX.XXX.XXX.XXX)

3) I think my Apache web server is working properly because I've set the log level to max and in my logs, at restart I have

Code: [Select]
[Thu Dec 30 10:52:39 2010] [notice] Child 4012: Starting thread to listen on port 443.
[Thu Dec 30 10:52:39 2010] [notice] Child 4012: Starting thread to listen on port 80.
[Thu Dec 30 10:52:39 2010] [notice] Child 4012: Starting thread to listen on port 443.
[Thu Dec 30 10:52:39 2010] [notice] Child 4012: Starting thread to listen on port 80.


so it seems to listen at the right port
and because when I launch the instruction in the web browser in my access.log file, I have normal connection rows in the access.log

I really don't know what else to do.
I hope someone can help me.

gerrynigro

Here I add the links I couldn't add in the first message

connessione a google --> GET /search?q=Arduino HTTP/1.0

connessione mio web service --> GET http://XXX.XXX.XXX.XXX/test/soap/client/do_action_get.php?name=PrimaInsert HTTP/1.0

PaulS

I'm familiar with LAMP (Linux, Apache, MySQL, PHP) and WAMP (Windows,...), but not XAMPP. What does the X stand for? What OS are you running?

Code: [Select]
   client.println("GET connessione mio web server HTTP/1.0"); // on my website - it doesn't work
If a connection is made, this exact string will be sent. It is not correctly formatted to do anything.

The server address, 127.0.0.1, is a special address. It says that the server is the same machine that the client is running on. That appears to not be the case, since you want the Arduino to connect to the laptop. Those are two different machines. In your case, the server is not running on the client machine. You need to specify the correct server address (that of the laptop).
The art of getting good answers lies in asking good questions.

zoomkat

If you want your arduino client to get something from your apache server, you will need to have something there specific to get (or do). Make a simple file with notepad, name it arduino.txt, and place it in the apache htdocs folder. The below in your code should download the contents of the file. If you need to execute some application via apache, put the executable in the cgi-bin folder and use an appropriate path.

client.println("GET /arduino.txt HTTP/1.0");
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

gerrynigro

First of all, thank you for your replies.
:-)

@Pauls:
XAMPP is a release to have PHP,MYSQL and Apache server on your pc. I think it is not very different from LAMP or WAMP. I installed it on my Windows machine, where now I'm doing my tries and on a Ubuntu virtual machine where I usually work.
Now I'm using the host system, windows 7 - 64 bit, because I've problems I'll solve later to use Ethernet shield with virtual machine.
Well, now some further explanation on my HW-SW configuration.
I have the web server regurlarly running on my pc and I've connected the arduino by cross cable. As I told you everything seems to work properly, in fact I CAN RECEIVE with my arduino the correct answer from google web server, but I can't connect to my apache web server.
It's strange, cause I can do it with my browser with any of these strings(192.168.137.1, localhost, 127.0.0.1) when I launch
Code: [Select]
http://192.168.137.1/test/soap/client/do_action_get.php?name=PrimaInsert
In the sketch I modified it in
Code: [Select]
client.println("GET http://192.168.137.1/test/soap/client/do_action_get.php?name=PrimaInsert HTTP/1.0");


The php page is responsible to invoke my web service passing the parameter name and the web service creates a new row on db.
But first of all, at the moment it seems I can't even connect with the instruction client.connect at my web server, and this seems to be my problem now :-(

@zoomcat
thank for your indications, but at the moment with my code it seems that the instruction client.connect() fails when I try to connect to my web server.The serial output trace is clear, it's the client.connect() that fails when I try to connect to my web apache server on the same machine.
Code: [Select]
byte server[] = { 192,168,137,1 }; // Mio sito
// 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):
Client client(server, 80);

void setup() {
 // start the Ethernet connection:
 Ethernet.begin(mac, ip);
 // start the serial library:
 Serial.begin(9600);
 // 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()) {
   Serial.println("connected");
   // Make a HTTP request:
   client.println("GET http://192.168.137.1/test/soap/client/do_action_get.php?name=PrimaInsert HTTP/1.0");
   client.println();
 }
 else {
   // kf you didn't get a connection to the server:
   Serial.println("connection failed");
 }
}


and in the serial monitor I receive
Code: [Select]
connecting...
connection failed

disconnecting.

and I'm afraid it means I fail with my client.connect() instruction
Any indication about this? :-(
I'll take in mind your consideration on txt file and cgi.bin.
At the moment I'm trying to call that php page that is responsible to invoke the web service.
Don't you think I can invoke a php page from arduino sketch?
If this thing is possible I think I don't have problems because it's the php page, launched in a web browser already works, correctly invoke the web service and it inserts a new row in the database.

Thank you in advance,
Gerry


PaulS

localhost is an alias for 127.0.0.1. Both refer to the machine that the client is running on.

The 192.168.137.1 address should be correct for accessing the server from another machine, on the same subnet. To access this machine, though, the client needs to specify the correct subnet mask. I do not see that you are doing that.

The server to connect to is defined in the initialization of the Client instance. It is not part of the GET request. On the browser, the protocol and server need to be part of the URL, since the server and protocol can change with each request. This is not the case with the Arduino client.

So, remove the "http://192.168.137.1" bit from the GET request string.
The art of getting good answers lies in asking good questions.

zoomkat

I just tried the below code and it works with my setup. Per the comments in the code, on my windows XP laptop I have apache running on port 80, the laptop LAN IP address is 192.168.1.2, the arduino.txt file is in the apache htdocs folder, the arduino is assigned a LAN IP address of 192.168.1.102, the laptop is wirelessly connected to the router, and the arduino is hardwired to the router with an ethernet cable. I upload the below code to the arduino (USB attached to the laptop) from the laptop. I then start the serial monitor which resets the arduino, and the arduino gets the arduino.txt from the apache server on the laptop via the router, then sends the file contents back to the serial monitor for viewing. It all works as desired. You may want to see if you are doing anything different with your setup.

Code: [Select]
//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 }; //assigned arduino LAN IP address
byte server[] = { 192, 168, 1, 2 }; // laptop running apache LAN IP address

Client client(server, 80); //apache web server running on port 80

void setup()
{
 Ethernet.begin(mac, ip);
 Serial.begin(9600);
 Serial.println("starting simple arduino client test");
 Serial.println();

 delay(1000);

 Serial.println("connecting...");

 if (client.connect()) {
   Serial.println("connected");
   client.println("GET /arduino.txt HTTP/1.0"); //text file in apache htdocs folder
   client.println();
 } else {
   Serial.println("connection failed");
 }
}

void loop()
{
 if (client.available()) {
   char c = client.read();
   Serial.print(c);
 }

 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   Serial.println("==================================");
   Serial.println("");
   client.stop();
   for(;;);
 }
}

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

gerrynigro

Ok, I solved my problems and now my system works. ;D
I had to deactivate windows firewall and connect by cable both the Arduino and the laptop to my router.
It seems it doesn't work if my laptop is wiressly connected to the router, I don't know why.

Tanks to zoomkat and PaulS fot their precious indications.

For the benefit of other users now I describe my system.
1) Arduino Uno + Ethernet Shield
2) On my laptop I'm running the following configuration of XAMPP
  Apache 2.2.14
  MySQL 5.1.41
  PHP 5.3.1
3) Arduino IDE 0022 to develope
4) Ethernet shield and laptop hardly connected to the router

Code: [Select]

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 }; //assigned arduino LAN IP address
byte server[] = { 192, 168, 1, 100 }; // laptop running apache LAN IP address
Client client(server, 80); //apache web server running on port 80

void setup()
{
 Ethernet.begin(mac, ip);
 Serial.begin(9600);
 Serial.println("starting simple arduino client test");
 Serial.println();

 delay(1000);

 Serial.println("connecting...");

 if (client.connect()) {
   Serial.println("connected");
   client.println("GET /test/soap/client/do_action_get.php?name=FirstRecordOK HTTP/1.0"); //php page invoking my web service
   client.println();
 } else {
   Serial.println("connection failed");
 }
}

void loop()
{
 if (client.available()) {
   char c = client.read();
   Serial.print(c);
 }

 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   Serial.println("==================================");
   Serial.println("");
   client.stop();
   for(;;);
 }
}


Now I'd like to realize the same project with the cellular shield of Arduino.
I should be possible.
If you have any indication about that (type of antenna and so on)I'm grateful to you. :)

Thanks,
Gerry

zoomkat

Quote
It seems it doesn't work if my laptop is wiressly connected to the router, I don't know why.


Have you logged into your router to see if the laptop has the same lan IP address when wireless as when hard wired?
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

10612441

Can someone please help me by sending a detialed tutorials on how to control a LED tthrough a web by using arduino and ethernet shield.. and to display the status of the LED.PLEASE HELP.... :( :( :-[
please email me at gorospejma@yahoo.com..tnx a lot Godbless you..
I am using arduino diecimila and ATC1000M ethernet shield..please teach me step by step beause im a novice

PaulS

The art of getting good answers lies in asking good questions.

zoomkat

Some info below.

http://www.scienceprog.com/getting-hands-on-arduino-ethernet-shield/
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

Go Up