We are using Arduino Uno board for our application. We have interfaced this board to an external GSM module via UART connection. With the help of Arduino board, we are sending AT commands to the GSM module and seeing the response in the console window.
I want to know how can we read the AT response from the console window.
we want to read the response and stores into the buffer, print the buffer data again on the console window.
Is there any special commands or codes are there to read the AT responses from Arduino console window?
some terminal emulators such as Teraterm Pro and realterm have facilities for logging received data
an alternative is to write your own application, e.g. using Visual Studio C#, C++ or VB with the SerialPort component or java with the jSerialComm library
You have the program that prints the commands to the console window.
So change this programm to store the interesting parts to your variables/buffers.
There are many tutorials to handle serial input,
but collecting characters in a buffer until cr/lf is read without chance of writing outside the buffer
is all what it takes, and that's a nice small programming exercise.
There is no need to read back the console window.
If you can not change the Arduino code (because it was lost, it's not your Arduino, ...), @horace gave good advice for that road.
Because it is a recurring problem, I use a class to handle serial input.
#include <WhandallSerial.h> // https://github.com/whandall/WhandallSerial
// simple handler just checks the start of line for "AT "
void processLine(const char* buf) {
if (!strncmp_P(buf, PSTR("AT "), 3)) { // PSTR is similar to F, but gives a char*
Serial.print(F("AT: "));
}
Serial.println(buf);
}
SSerial console(Serial, processLine); // used serial and handler
void setup() {
Serial.begin(250000);
console.begin(64); // buffer size
}
void loop() {
console.loop(); // collect chars and call handler for each line
}
You can read serial input basics to understand serial communication and get ideas how to read serial data. Or you can rely on Whandall's library and code.
sterretje:
Or you can rely on Whandall's library and code.
It can handle Nextion data too (triple 0xff delimiter and embedded 0x00), so it's worth a look anyway.
It even comes with doxygen mini documentation.
I like to have the line processing in a function, that way loop gets less complex.
And the buffer mechanism knows exactly when it's save to reuse the buffer.