I have Arduino code (function) that uses a GET request. The request is being successfully sent but I am not getting the desired page printed on the serial monitor.
My aim is to get a value from my server (MySQL) and use it for my motor functions (like using the ThingSpeak API). But I am not able to receive the data.
Arduino code is here:
void getd() {
esp.println("AT+CIPMUX=0");
esp.println("AT+CIPSTART=\"TCP\",\""+server+"\",80");
//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
delay(1000);
}
delay(1000);
Req ="GET " + a +" ?val=
";
int l=Req.length();
Serial.println(l+2);
esp.print("AT+CIPSEND=");
esp.println(Req.length());
if(esp.find(">")) {
Serial.println("Sending..");
Serial.print(Req);
esp.print(Req);
if(esp.find("SEND OK")) {
Serial.println("Packe");
// if there are incoming bytes available
// from the server, read them and print them:
if (esp.available()) {
String c = String(esp.read());
Serial.println(c); // to see the value
// atoi is a function to convert ascii to integer
}
}
PHP code is here:
<?php
$sql= new mysqli('localhost','root', '', 'farminger');
if($sql->connect_error) {
die("connection failed:". $sql->connect_error);
}
$query1= $sql->query("select * from test order by timestamp desc limit 1" ); #insert in table
if($query1!==FALSE) {
while($row = mysqli_fetch_array($query1)) {
echo "val: " . $row["val"]. "<br>";
}
mysqli_free_result($query1);
}
$_POST['val']=$row["val"];
mysqli_close($sql);
?>
Am I doing some logical mistake in the PHP part? Should I be using a POST request there?