Hello, I 've been searching and trying through the Internet more than six hours and I don't know what elese to try. I am trying with Ehternet shield to connect to my website and with php to send data to a db. I get an IP adrees but the problem is I cannot connect to the website. I tried instead www.google.com , but still nothing. My code is as follows
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
EthernetServer server(80);
const int temperaturePin = A0;
float temperature;
char pageName[] = "www.google.com";
// Initialize the Ethernet server library
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Ethernet.begin(mac, ip);
// start the Ethernet connection:
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
}
else {
Serial.println("Ethernet shield OK.");
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
else {
Serial.println("Ethernet cable is connected.");
}
}
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
temperature = getDegrees(temperaturePin); //Measure the voltage at the analog pin
int code = client.connect(pageName, 80);
Serial.print(code);
if (code) {
client.print("GET /write_data.php?"); // This
client.print("value="); // This
client.print(int(temperature)); // 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: www.google.com"); // 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: "www.yourwebpage.com")
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.
delay(10000);
}
float getDegrees(int pin) //Function to read and return
{
float temp = analogRead(pin);
return (temp * 0.48828125);
}