i want to pass a value to my web server(apache) using php.
php code is below.
<?php
echo "in\n";
error_reporting(E_ALL);
$con=mysqli_connect("localhost","root", "QbdQbd365", "sensorvalue");
if(mysqli_connect_errno($con))
{
echo "Failed to connet to mySQL: " . mysqli_connect_error();
}
$distant = $_GET["distant"];
$sql = "insert into sensorvalue.stringvalues(distant) values($distant)";
mysqli_query($con, $sql);
mysqli_close($con);
echo "out\n";
?>
it pass value to db to save it.
it work well when i type 'localhost/insert_data.php/?distant=11' in my web browser.
so i thought it can pass using arduino code.
i'm using rn-171 wifi modules made by seeed studio
and i reference documents and example from Wifi Shield V2.0 | Seeed Studio Wiki
so i wrote..
#include <SoftwareSerial.h>
#include "WiFly.h"
#define SSID "yum2"
#define KEY "yum000000"
#define AUTH WIFLY_AUTH_WPA2_PSK
SoftwareSerial wiflyUart(2, 3); // create a WiFi shield serial object
WiFly wifly(&wiflyUart); // pass the wifi siheld serial object to the WiFly class
void setup() {
wiflyUart.begin(9600); // start wifi shield uart port
Serial.begin(9600); // start the arduino serial port
Serial.println("--------- WIFLY --------");
// wait for initilization of wifly
delay(1000);
wifly.reset(); // reset the shield
delay(1000);
wifly.sendCommand("set ip proto 18\r"); //enable html client
delay(100);
wifly.sendCommand("set dns name localhost\r"); // 192.168.0.2 is my computer ip
delay(100);
wifly.sendCommand("set ip address 0\r");
delay(100);
wifly.sendCommand("set ip remote 80\r");
delay(100);
wifly.sendCommand("set com remote 0\r");
delay(100);
wifly.sendCommand("open\r"); // open connection
delay(100);
Serial.println("Join " SSID );
if (wifly.join(SSID, KEY, AUTH)) {
Serial.println("OK");
} else {
Serial.println("Failed");
}
delay(5000);
Serial.println("Wifi_ready");
}
void loop() {
String str = "GET /insert_data.php/?distant=";
str += 15;
while (wifly.available()){
Serial.println(str);
wiflyUart.println(str + "\r");
delay(500);
}
}
there is no any error but it doesn't work.
where should i handle it??
and arduino and web server are connected a same computer.
the output from serial monitor is below.
--------- WIFLY ---------
Join yum2
OK
Wifi_ready
GET /insert_data.php/?distant=15
GET /insert_data.php/?distant=15
...