Dear all, I am new either on Arduino, Now I follow all the steps on icreateproject.com about save data in local XAMPP database. Arduino: Save data to database - iCreateProject
It seems everything fine apart from not be able to save the data.
I am able to write data to the database by php (write_data.php), and Arduino can purge out the data and display from the local network (169.254.189.141) .
My PC IP is, 192.168.0.13
Ethernet IP is: 169.254.189.138
Ardunio Ethernet localIP is: 169.254.189.141
Except IP address, all my coding exactly same, but connection fail, Can anyone help about the case?
Here is the Arduino code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Enter the IP address for Arduino
IPAddress ip(169,254,189,141);
int photocellPin = 0; // Analog input pin on Arduino we connected the SIG pin from sensor
int photocellReading; // Here we will place our reading
char server[] = "192.168.0.13";
// Initialize the Ethernet server library
EthernetClient client;
void setup() {
// Serial.begin starts the serial connection between computer and Arduino
Serial.begin(9600);
// start the Ethernet connection
Ethernet.begin(mac, ip);
}
void loop() {
photocellReading = analogRead(photocellPin); // Fill the sensorReading with the information from sensor
// Connect to the server (your computer or web page)
if (client.connect(server, 80)) {
client.print("GET /write_data.php?"); // This
client.print("value="); // This
client.print(photocellReading); // 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: 192.168.0.13");
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");
}
delay(10000);
}
I had tried to change the code IP server "192.168.0.13" to "localhost" or char server[] to IPAddress ip, but all those not work for me.