I am trying to configure my arduino uno to send some data over ethernet to the database hosted on my wamp server. However, when I run the code I currently have, nothing happens.
To configure my computer/wamp/router I used the following guide:
I am using the following php code to create the connection and execute the insert query. If I run this code using my URL bar (e.g “http://localhost/dbTest.php?value=300000” ) the code works fine and I can see the value appear in my database.
<?php
// Connection information
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "arduinotest";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// SQL query
$sql = "INSERT INTO testdata (myTime) VALUES ('".$_GET["value"]."')";
// Execute query
$conn->query($sql);
// Close connection
$conn->close();
?>
On the arduino end I am using the following code, the client connection always seems to pass.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,10);
IPAddress server(192,168,0,4);
EthernetClient client;
int data = 10;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
}
void loop() {
if (client.connect(server, 80)) {
Serial.println("Connected successfully\n");
// Print for debugging
Serial.print("GET /dbTest.php?");
Serial.print("value=");
Serial.print(data);
Serial.println(" HTTP/1.1");
Serial.print("Host: ");
Serial.println(server);
Serial.println("Connection: close");
client.print("GET /dbTest.php?");
client.print("value=");
client.print(data);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
client.println();
client.stop();
}
else {
Serial.println("Connection failed\n");
}
delay(30000);
}
This is where I am currently at, I’ve run out of ideas as to what could be the cause. I’d be really grateful for any suggestions or help. Thanks.