Char Array Client.Print Arduino

I am trying to read a QR code and send it the phpMyAdmin. I am using a DE2120 1D2D scanner and a UNO. The problem is with the printing , on the serial monitor looks like a string but in the php the each character from the code is printed on a new line, the idea is to client.print the entire code on the same row.
unionwells germany
Code bellow:

#include "SparkFun_DE2120_Arduino_Library.h"
#include "SoftwareSerial.h"
#include <Ethernet.h>
#define BUFFER_LEN 40

    byte mac[] = {
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE }; // 
    IPAddress ip(192, 168, 1, 22 );  //
    IPAddress gateway(10, 74, 0, 1); 
    IPAddress subnetMask(255, 255, 255, 192); 
    EthernetClient cliente;
    char server[] = "192.168.1.15"; // 

SoftwareSerial softSerial(3,2);
DE2120 scanner;

char scanBuffer[BUFFER_LEN];
String QR;

void setup() {

  Serial.begin(115200);
  
  softSerial.begin(9600);
  Serial.println(scanner.begin(softSerial));

  Ethernet.begin(mac, ip);
      IPAddress newSubnet(255, 255, 255, 192);
      Ethernet.setSubnetMask(newSubnet);
      Serial.print("Ethernet.localIP: ");
      Serial.println(Ethernet.localIP());
      Serial.print("Ethernet.gatewayIP:");
      Serial.println(Ethernet.gatewayIP());
      Serial.print("Ethernet.subnetMask:");
      Serial.println(Ethernet.subnetMask());
      
      if (cliente.connect(server, 8080)) {
        Serial.println("Connected to the server");}
}

void loop() {

  delay(200);

  if(scanner.readBarcode(scanBuffer, BUFFER_LEN)){
    Serial.println("QR availbale ");
    for(int i = 0; i < strlen(scanBuffer); i++){   // Production Order
      Serial.print(scanBuffer[i]);
      QR = String(scanBuffer[i]);
      
      (cliente.connect(server, 8080));
        cliente.print("GET /ethernet/data_qr.php?");
        cliente.print("QR=");
        cliente.println(QR); // I tried also with client.print(QR) followed by client.println(), no chance.
        //client.println(); 
        cliente.stop();
     }
    Serial.println();
  }
  }

Serial monitor - QR is a String

PSN6v

client.print result

NEW ACCOUNT LIMITED ONE PIC ALLOW 2nd in Reply Box.

I tried:

  1. To convert the Char scanBuffer[i] to String and than printed. - 0 results
  2. To store the serial monitor value ov scanBuffer[i] in a variable and the printed. - 0 results
  3. Client.println / Client.print

What can I try , some ideas on order to client.print the QR content in the same row.

Thank you ! :smiley:

What do you mean? Do you understand what phpMyAdmin is?

You mean send the entire string as a parameter to a single GET request?

If so, why does your code contain a for-loop which sends each character in a separate GET request?

Please do not post images of the serial monitor. Copy the text from serial monitor and paste it into your post between code tags.

Hello,

  1. phpMyAdmin is a package of software that allows you to store (DB) data from an Arduino or another IOT device. (Google it)

  2. Regarding with the "for" loop, I tried also like in the code from bellow:

#include "SparkFun_DE2120_Arduino_Library.h"
#include "SoftwareSerial.h"
#include <Ethernet.h>
#define BUFFER_LEN 40


    byte mac[] = {
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE }; // 
    IPAddress ip(192, 168, 1, 22 );  //
    IPAddress gateway(10, 74, 0, 1); 
    IPAddress subnetMask(255, 255, 255, 192); 
    EthernetClient cliente;
    char server[] = "192.168.1.15"; // 

SoftwareSerial softSerial(3,2);
DE2120 scanner;

char scanBuffer[BUFFER_LEN];
String QR; 




void setup() {

  
  Serial.begin(115200);
  
  softSerial.begin(9600);
  Serial.println(scanner.begin(softSerial));

  Ethernet.begin(mac, ip);
      IPAddress newSubnet(255, 255, 255, 192);
      Ethernet.setSubnetMask(newSubnet);
      Serial.print("Ethernet.localIP: ");
      Serial.println(Ethernet.localIP());
      Serial.print("Ethernet.gatewayIP:");
      Serial.println(Ethernet.gatewayIP());
      Serial.print("Ethernet.subnetMask:");
      Serial.println(Ethernet.subnetMask());
      
      if (cliente.connect(server, 8080)) {
        Serial.println("Connected to the server");}
}

void loop() {
  
 delay(200);

  if(scanner.readBarcode(scanBuffer, BUFFER_LEN)){
    QR = scanBuffer; // String
    delay(2000);
    Serial.print("QR availbale: ");
    (cliente.connect(server, 8080));
    cliente.print("GET /ethernet/data_qr.php?");
    cliente.print("QR=");
    cliente.println(QR);
    cliente.stop();
    
    Serial.println(QR);
    delay(1000);     
        
}

}

Still not receiving the content of the QR in the DB, only in on the serial monitor.
I tried to print a predefined char and it works, I can't understand why can't print the content from the serial monitor to the DB.

Thanks!

I asked the question because I already know and suspected you don't know what phpMyAdmin is. And I was correct. You are confusing phpMyAdmin with MySQL. MySQL is a relational database. phpMyAdmin is a web interface for managing mySQL databases, allowing you to create databases, tables, examine, add/modify/remove data etc. without needing to code in SQL language. But it does not store data itself. I don't know why it is called "phpMyAdmin", I think a better name would have been "mySQLAdmin". I guess phpMyAdmin itself is written in PHP language, but that is irrelevant to the user.

I think php it is from "PHP" , "My" it is from MySQL (a sql db), and "admin" I think from administration. Anyway, I think it will not help me to find the root cause :smiley:

Did you check the QR Data? it seems to me that you have a "CR" somewhere in the data and may not show in the serial monitor, however the DB server you are connecting to is seeing it as a "new line" before the actual "end of line" from the "println" command

is pretty common for an scanner to send a "CR" at the end of the data, actually could be a CRLF already there, you may not need to send any println at all

try to do only "print" in the last command

Ok, perhaps the problem is that the QR code contains characters that are not valid in a GET parameter. Looking at the example from post #1, I can see "+" symbols, and I don't think they are valid. To avoid this problem, you have to put %XX instead of any characters that are not allowed in a GET parameter. The "XX" is the ASCII code for the character, in hexadecimal. So instead of "+" in the parameter, you would put "%2B".

Hi Hsaul17,

I used the println for changing the raw(new line) after reading the QR. I tried also with client.print and followed by client.println().
Where I can not understand is when I client.print a predefined char like " R32847923 232 554" it's working and when I scan the QR the content it is shown only on Serial monitor.

Try a different Serial monitor, not the arduino one, I recommend you this two:

https://www.hw-group.com/software/hercules-setup-utility

https://sourceforge.net/projects/realterm/

the main difference is that this terminals/monitors will actually show you "special" characters that the Arduino monitor won't show, then we can try to find the correct solution (you may need to change some settings in the terminals to make them show the special characters)

and again, try without using a single "cliente.println"

do it like this

        cliente.print("GET /ethernet/data_qr.php?");
        cliente.print("QR=");
        cliente.print(QR);

I suspect the request is returning an error, but your code is not reporting that error message to serial monitor.

You can simulate the request from your browser by entering the get request in the address bar, like

http://192.168.1.15:8080/ethernet/data_qr.php?QR=ABC123

where ABC123 is the code you see on Serial monitor.

Let me show you an example of special characters in the serial monitor, the same information was sent both times, the only difference is the Serial monitor software being use

this is the arduino Serial monitor, do you see any special character on it?

image

now this is with the Hercules Terminal

image

that is coming directly from the scanner and is exactly the same line ending that the arduino println() does, if you use a println() that means you are actually sending that line ending twice making the DB server think you are actually sending two lines instead of one

The problem is because you're sending one character at a time. In fact, you create a brand new connections for each character. Why do you need the loop? Why not simply cliente.println(scanBuffer) (as well as Serial.print(scanBuffer) )?

The Serial.print(scanBuffer[i]) it's in the for loop, if I print only Scan.Buffer it shows nothing.

Well then just print with no println . The ln ending in println stands for line and means a newline is "printed" or sent.
And, don't do a new connection in the loop! Create one connection, print the request and the QR= part, then inside the loop only print the characters, without a newline. Then after the loop print a newline.

Yes, you had right, I can print only the scan Buffer without the for loop, now the problem is the board don't send anything to the sql, see the code bellow:

void loop() { delay(200); if(scanner.readBarcode(scanBuffer, BUFFER_LEN)){ Serial.print("QR availbale: "); Serial.println(scanBuffer); delay(1000); (cliente.connect(server, 8080)); cliente.print("GET /ethernet/data_qr.php?"); cliente.print("scanBuffer="); cliente.println(scanBuffer); cliente.stop(); } }

That seems like a very different issue, to be asked in a new question.

I tried with another char declared in the beginning of the program, and it works, I don't understand the difference between char scanBuffer and another char, with the same length.