I have trouble in getting the data from the webclient using GET api , so the process would be if the UID is exist in the database the webpage add.php will reply either in a get method or post but i dont know how to fetch that data from webpage to the serial monitor. Below is the code I get from this thread zoomkats reply https://forum.arduino.cc/index.php?topic=160616.0
Or is there a way that I can print the echo message from the web page to serial monitor in arduino? If it is possible can someone lend me some guide on how to achieved it?
if (client.connect(server,80)){ // attempt to get a value from the add.php
// using GET , this is confirmation wheither your UID exist in the database
Serial.println("Attempting to Connect for the 2nd time");
// get the reply value in php
client.print("GET /add.php");
client.print(" HTTP/1.1");
client.println();
client.println("Host: localhost");
client.println("Connection: close");
client.println();
Serial.println("ARDUINO : HTTP REQUEST SENT");
delay(1000);
if(client.available()){
while(client.connected()){ // zoomkats example code
char c = client.read();
if (readString.length() < 100) {
//store characters to string
readString += c;
}
//Serial.print(c);
if (c == '\n') {
Serial.println(readString);
client.stop();
if(readString.indexOf("on") >0)//checks for on
{
Serial.println("Led On");
}
if(readString.indexOf("off") >0)//checks for off
{
Serial.println("Led Off");
}
readString="";
}
}
}
else{
Serial.println("2ND ATTEMPT FAILED");
}
Below is my php code , Note: this is just test code , maybe theres some kind of errors exists in here I badly need help
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "micro";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$temp1=$_GET['value'];
echo "$temp1";
$que = "INSERT INTO students(id_number, student_name)
VALUES ('$temp1' , '$temp1')";
if($conn->query($que) == TRUE){
echo "nice!";
}
else{
echo $link->error();
}
$test = "on";
header("location:add.php?reply=".$test);
?>