Hello. I am working a simple project with arduino and an enc28j60 ethernet module. I want to send GET requests and catch them in localhost in a php script that i made , however i face a trouble.
Here is my arduino code that i use:
(localhost: 192.168.10.9)
(enc pins: 10 = CS, 11 = SI, 12 = SO, 13 = SCK, 5V, Ground)
#include <UIPEthernet.h> // Used for Ethernet
// **** ETHERNET SETTING ****
// Arduino Uno
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
// For the rest we use DHCP (IP address and such)
EthernetClient client;
char server[] = "192.168.10.9"; // IP Adres (or name) of server to dump data to
int interval = 5000; // Wait between dumps
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
}
void loop() {
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("-> Connected");
// Make a HTTP request:
client.print( "GET /index.php?");
client.print("variable=");
client.print( "2888806X" );
client.println( " HTTP/1.1");
client.print( " Host: " );
client.println(server);
client.println( " Connection: close" );
client.println();
client.println();
client.stop();
}
else {
// you didn't get a connection to the server:
Serial.println("--> connection failed/n");
}
delay(interval);
}
and my basic php script:
<?php $link = mysqli_connect("localhost", "root", "", "variable"); if(mysqli_connect_error()){ die("database failed"); } if(isset($_GET['variable'])){ $query = "INSERT INTO variables (variable) VALUES ('". $_GET['variable'] ."') "; mysqli_query($link, $query); } ?>I have tried many variations of the code and other examples but have found the solution yet. However if i put the url manually in browser from other device and check the database i can see the inserted data. Is there anyone who can help me?
Thank you.