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
client.print result
NEW ACCOUNT LIMITED ONE PIC ALLOW 2nd in Reply Box.
I tried:
To convert the Char scanBuffer[i] to String and than printed. - 0 results
To store the serial monitor value ov scanBuffer[i] in a variable and the printed. - 0 results
Client.println / Client.print
What can I try , some ideas on order to client.print the QR content in the same row.
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.
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
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
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".
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.
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"
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?
now this is with the Hercules Terminal
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) )? Olehana France
Well then just print with noprintln . 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:
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.