Hello Arduino fans!
Currently I'm working on a new project which should be able of sending data to a mysql database through a php code. The connection between the php and the mysql is no problem, I am able to add content to my database by writing the data in my url bar. i.e. http://***********.com/add_db.php?id=12&name=john
Though, the connection between my arduino and the php code on the server side seems to me impossible, I have already searched on the forum and tried several codes and modified them a bit, especially those of zoomkat. Unfortunatelly, it seems impossible to make this work. I am currently experimenting with the following code, which is made by zoomkat:
//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[] = {0x90, 0xA2, 0xDA, 0x**, 0x**, 0x** };
byte ip[] = { ***, ***, ***, *** };
byte server[] = { **,**,**,**};
Client client(server, 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");
client.println("GET /add_db.php?id12&name=john HTTP/1.0");
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(;;);
}
}
Thanks, Niels