PHP GET return variable to display

Hello,

I use an arduino ethernet and with the following code i send a GET o the server

     client.print(getLine);
          for (i=0; i<5; i++) {
            if (code[i] < 16) client.print("0");
            client.print(code[i], HEX);
          }
          client.println(" HTTP/1 .1");
          client.println("Host: domain.com");
          client.println("User-Agent: arduino-ethernet");
          client.println("Connection: close");
          client.println();

but i saw somewhere that it is possible to return a value on a GET request.
So i want to return a name from the database and prints this to a display
Anyone have an example on how to do this IF it is possible...?

but i saw somewhere that it is possible to return a value on a GET request.

Of course it is. That's what a GET request is for. It tells the server to send some data. Specifically what to send depends on the script being executed on the server.

So i want to return a name from the database and prints this to a display

There are three parts to this. First, the server actually has to return some data. Second, the Arduino needs to read the server's response. Third, the Arduino needs to print the data to the display.

Anyone have an example on how to do this IF it is possible...?

How to do what? Make the server actually serve up some data? Make the Arduino read the server's response? Make the Arduino print something to some unknown display?

The client example shows how to read a server response. We can't tell, from the snippet you posted, whether you modified that example, or developed something entirely different.

Thanks for your help!

So yes it is possible, cool :slight_smile:

How do i return this data?
does it needs to be between special tags?
or does it just return the html value?

below my code, it a big copy paste project...

#include <SoftwareSerial.h>
#include <Ethernet.h>
#include <SPI.h>
#include <Wire.h>                         //display
#include <LiquidCrystal_I2C.h>            //display
#include "IP_setting.h"                  //tabblad
#include "Display.h"                  //tabblad

EthernetClient client;
SoftwareSerial mySerial(2,3);            // rx tx van rfid sensor
const int ledRfid =  4;                  // the number of the LED pin
LiquidCrystal_I2C lcd(0x27,16,2);        // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {

  Ethernet.begin(mac, ip);
  mySerial.begin(9600);                  // connect to the serial port
  Serial.begin(9600);                    // connect to the serial port
  pinMode(4, OUTPUT);                    // initialize the digital pin as an output  
  lcd.init();                            // initialize lcd
  lcd.backlight();                       // turn backlight on
  lcd.print(bRand);                   // welcome message on startup
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print(cOnnect);
  delay(2000);
  lcd.setCursor(0,1);
  lcd.print("                ");
  delay(500);
  lcd.setCursor(0,1);
  lcd.print(iPadress);
  delay(2000);
  lcd.setCursor(0,1);
  lcd.print("                ");
  delay(500);
  lcd.setCursor(3,1);
  uint8_t ipSize;
  ipSize = sizeof (ip);
  for ( uint8_t i = 0; i < ipSize; i++ )
  {
    lcd.print ( int(ip[i] ));
    lcd.print (".");
  }
  delay(2000);
  lcd.clear();
  lcd.print(bRand);
 digitalWrite(ledRfid, HIGH);    // set the LED on


}

void loop () {
  lcd.setCursor(0,1);
  lcd.print("                ");

  byte i = 0;
  byte val = 0;
  byte code[6];
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;

  if(mySerial.available() > 0) {
    if((val = mySerial.read()) == 2) {                  // check for header

      digitalWrite(ledRfid, LOW);   // set the LED off
      lcd.setCursor(0,1);
      lcd.print(rEadid);


      bytesread = 0;
      while (bytesread < 12) {                        // read 10 digit code + 2 digit checksum
        if( mySerial.available() > 0) {
          val = mySerial.read();
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading
            break;                                    // stop reading
          }
          // Do Ascii/Hex conversion:
          if ((val >= '0') && (val <= '9')) {
            val = val - '0';
          } 
          else if ((val >= 'A') && (val <= 'F')) {
            val = 10 + val - 'A';
          }
          // Every two hex-digits, add byte to code:
          if (bytesread & 1 == 1) {
            // make some space for this hex-digit by
            // shifting the previous hex-digit with 4 bits to the left:
            code[bytesread >> 1] = (val | (tempbyte << 4));

            if (bytesread >> 1 != 5) {                // If we're at the checksum byte,
              checksum ^= code[bytesread >> 1];       // Calculate the checksum... (XOR)
            };
          } 
          else {
            tempbyte = val;                           // Store the first hex digit first...
          };

          bytesread++;                                // ready to read next digit
        }
      }

      // Output to Serial:
      if (bytesread == 12) {                          // if 12 digit read is complete
        Serial.print("5-byte code: ");
        for (i=0; i<5; i++) {
          if (code[i] < 16) Serial.print("0");
          Serial.print(code[i], HEX);
          Serial.print(" ");
        }
        Serial.println();
        Serial.print("Checksum: ");
        Serial.print(code[5], HEX);
        Serial.println(code[5] == checksum ? " -- passed." : " -- error.");
        Serial.println();

        Serial.println("connecting...");
        delay(500);
        if (client.connect(server, 80)) {
          Serial.println("connected");
          lcd.setCursor(0,1);
          lcd.print(eMpty);

          client.print(getLine);
          for (i=0; i<5; i++) {
            if (code[i] < 16) client.print("0");
            client.print(code[i], HEX);
          }
          client.println(" HTTP/1 .1");
          client.println("Host: domain.com");
          client.println("User-Agent: arduino-ethernet");
          client.println("Connection: close");
          client.println();
          client.read();
         
          //test
          
            char c = client.read();
            Serial.print(c);
          


          //test
          
          client.stop();
          digitalWrite(ledRfid, HIGH);    // set the LED on
          lcd.setCursor(0,1);
          lcd.print(eMpty);
          lcd.setCursor(0,1);
          lcd.print(oKidoki);
          delay(1000);

        } 
        else {
          Serial.println("connection failed");
          lcd.setCursor(0,1);
          lcd.print(nOconn);
          delay(2000);
        }
      }

      bytesread = 0;
    }
  }
  // if there are incoming bytes available 
  // from the server, read them and print them:



}

but the part between //test does only return ÿ
and i think that should be something from the page

How do i return this data?
does it needs to be between special tags?
or does it just return the html value?

That would depend on the PHP script. Not really an Arduino issue, but PHP is commonly used (and I'm familiar with it) so you might get help with that part, if you posted the PHP code.

it a big copy paste project...

You should learn to write functions. Reading the RFID tag is something that belongs in a function. Dealing with the server belongs in a function.

Look back at the client example. It shows how to read the response from the server. You have a call to client.read() that throws away one character, then another call to client.read that reads one character. Neither call follows a client.available() call to assure that there is client data to read or a client.connected() call to assure that the connection to the server succeeded.

The PHP code is very basic now...
But if i know what to print finally

<?php


$waarde = $_GET["value"];


$con = mysql_connect("localhost","user","secret");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("arduino_test", $con);
mysql_query("INSERT INTO table_1 (value)
VALUE ('".$value."')");
   
mysql_close($con);
?>

but how do i do a simple test?
how can i return for example "test"?

Functions, mmm that is the next chapter i need to do i think...
I am just beginning with C so all is new for me
Any tips for me?