Hello,
I am working on a code for my graduation project. I have set-up a database(MySQL) on Internet and want to synchronise my data from Arduino with it. I have an UNO with DFRobot Xbee Shield and RN-XV Wireless module on top. I have been trying MySQL Connector/Arduino code and many others to access the database, but WiFlyHQ library seems to not work well with this shield. So I headed the PHP way.
I wrote a basic code in order to connect to my Router and talk with my webserver. However, I am unable to send GET request to it. When I boot the device, it goes through the commands, connects to my router and no more. It wont connect to webserver and send the request. I have gone through pages and manuals but it simply won’t connect and I don’t get an output from Serial Terminal either(like HTTP connection failed etc.).
I have attached my Arduino and PHP code below. I am really lost after days of trying, I have to get this up in shape and hand in 2 weeks later, so any help would be much appreciated.
Thanks
#include <stdlib.h>
#include <PinChangeInt.h>
char recv[128];
uint8_t cont = 0;
void setup() {
Serial.begin(9600);
Serial.println("Starting");
while (Serial.available()>0) {}
// Enters in command mode
delay(10000);
Serial.print("$$"); check();
// Sets DHCP and TCP protocol
Serial.print("set ip dhcp 1\r"); check();
Serial.print("set ip protocol 1\r"); check();
// Configures the way to join the network AP
Serial.print("set wlan join 0\r"); check();
Serial.print("set wlan phrase 12341234\r"); check();
Serial.print("join OpenWrt\r"); check();
Serial.print("set dns name www.***.info\r"); check();
Serial.print("set ip host 0\r"); check();
Serial.print("set ip remote 80\r"); check();
Serial.print("set ip proto 18\r"); check();
Serial.print("set com remote GET$/ins_mysql.php?name=Gwen\r"); check();
Serial.print("exit\r"); check();
delay(1000);
}
void loop()
{
}
void check(){
cont=0; delay(2000);
while (Serial.available()>0)
{
recv[cont]=Serial.read(); delay(10);
cont++;
}
recv[cont]='\0';
Serial.println(recv);
Serial.flush(); delay(100);
}
<?php
if($_GET["name"])
{
echo "Welcome ". $_GET['name']. "
";
$_GET['name'] = $yourdata;
$database = "Patients";
$tablename = "Names";
if (mysql_connect($localhost, $username, $password))
{
@mysql_select_db($database) or die ("Unable to select database");
$query = "INSERT INTO $tablename VALUES ($yourdata)";
$result = mysql_query($query);
} else {
echo("Unable to connect to database.".mysql_error());
}
exit();
}
?>