Data form database to esp

Hi :slight_smile:
Is there someone who can help me and show me how i can receive data for database to esp, because i need this date in arduino sketch. I can send data to database, and this is my code in php:

<?php

$wartosc1 = $_GET['temperatura'];
$wartosc = $_GET['wilgotnosc'];

$connect = mysqli_connect("localhost","root","szynszyle","food") or die("blad polaczenia z baza danych");
 
if($wartosc!='')
{

$dodaj=mysqli_query($connect,"INSERT INTO device_values (device_id,temp_level,humidity_level) VALUES ('100','$wartosc1','$wartosc')");
echo "<h1>THE DATA HAS BEEN SEND!!</h1>";

mysqli_close($connect);
}
 
?>

and from arduino ide:

String url = "http://localhost/food/conec.php?temperatura="+String(t)+"&wilgotnosc="+String(h);


  Serial.print("Wysylam dane na serwer: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(adresSerwera) + "\r\n" + 
               "Connection: close\r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");

And this works fine, but how to receive date?I will be very grateful for help. :slight_smile:

Welcome to the forum! Nice job with the code so far.

In order to send data back the other way you need to display data from the database on a web page- see PHP MySQL Select Data for a basic introduction. Note that this will display all rows stored in the database so you will need to add a WHERE clause to your SELECT statement to only display the data you need.

On the arduino side maybe this thread will help you get started. The script posted by zoomcat seems to contain code that does what you need.

Thanks for reply. :slight_smile:

OK I displey data on webpage:

And there is minimum, maximum temperature and humidity, and minimum food. Unfortunately I dont understand how zoomcat code works :frowning:
I need this 5 values in my skech.

Nice work! Can you please publish your PHP code so others can benefit.

A complete web response contains a lot of headers before the actual data (open the web developer tools in Firefox or Chrome and choose the Network tab to see a complete exchange between server and client) I suggest you add a start and end character to the data so you can use the method in http://bildr.org/2011/06/arduino-ethernet-client/ (the readPage() subroutine) to just get the section containing your data. You will then have to parse and convert each value see serial - How do I split an incoming string? - Arduino Stack Exchange.

Suggest you start by simply printing out the line containing the data first, then move on to extracting the individual values later.