Hey guys, I'm having a little bit of trouble here... Here's my situation:
I have a web server running on a Beaglebone Black, and I'm trying to send data from the arduino to its webpage so it can, eventually, be stored in a mySQL database.
I am able to connect to the server with my arduino (based off an example I took on the forum that worked for many), but it doesn't seem like the data I'm sending is going through...
Here's my code - arduino side:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x2A, 0x8D };
byte ip[] = { 192, 168, 2, 77 };
byte gw[] = {192,168,2,1};
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 192, 168, 2, 83 }; // Server IP
int data = 1022;
void setup()
{
Serial.begin(9600); // Used for serial debugging
}
void loop()
{
Serial.println("Program running...");
delay(5000);
senddata(); // Data is sent every 5 seconds
}
void senddata()
{
Ethernet.begin(mac, ip, gw, subnet);
EthernetClient client;//(server, 80);
Serial.println();
Serial.println("ATE :)");
delay(1000); //Keeps the connection from freezing
if (client.connect(server, 80)) {
Serial.println("Connected");
client.print("GET /insertdata.php?data=");
client.print(data);
client.println(" HTTP/1.1");
client.println("Host: 192.168.2.83");
client.println();
Serial.println();
}
else
{
Serial.println("Connection unsuccesful");
}
//}
//stop client
client.stop();
while(client.status() != 0)
{
delay(5);
}
}
And here's the code - server side - php
<!DOCTYPE html>
<html>
<?php
echo "Access OK";
echo "
"; //newline
if (isset($_GET['data'])){
$data = $_GET['data'];
echo $data;
}
else{
echo "Data not received";
}
//Connect to database
?>
</html>
At first I tried simply echoing the $data, without the if condition, but I wasn't getting anything so I looked up online and found that this was a common thing to do. Now, still not getting the right thing, as it is just displaying the "Data not received", which means it didn't get anything from the $_GET statement...
Any help is extremely appreciated, hoping to get this fixed fairly soon