How do I put into a buffer, a part of Serial response (UART)

Dear All,

While I send an AT command I need to put into a buffer the response.
I do have an Arduino UNO and TEL0051 shild with SIM908.

I also created a special ino file to work on that issue (see below)

First I quickly look at the AT command for SIM908
http://www.dfrobot.com/image/data/TEL0051/3.0/SIM908_AT%20Command%20Manual_V1.01.pdf
If you look at page 13, you can raed:

The "AT" or "at" prefix must be set at the beginning of each Command line. To terminate a
Command line enter <CR>.
Commands are usually followed by a response
that includes. "<CR><LF><response><CR><LF>"
Throughout this document, only the responses are presented, <CR><LF> are omitted
intentionall

Then when I send an AT command, I should "filter" the data from CR LF and the second CR LF.
I have difficulties to do that and I really will appreciate your help

Then now if you look at page 266, there is command AT+GPSSTATUS and the repsonse.

Now my code. I created a read_AT_serial.iono file will necessery code. Most of them it to start the module and power the GPS. It work. In order to understand my issue, look at loop() and read_AT_string(char* command, int timeout)

loop() will, each 10sec, call read_AT_string(). read_AT_string() will send the command and try to put into a buffer the response of the AT command.

For my exercise, I use AT+GPSSTATUS command. The detail is at page 266.
I adding comment in CAPITAL

Here is the code in a txt file (I had to put that code into an external file)
http://www.hello-web.net/temp/read_AT_string.txt

Here is what display buffer (It display a lot of '1' for the time of timeout. I do not pasted all '1')

DISPLAY BUFFER:
AT+GPSSTATUS
1
1
1

1
1
1
1

END DISPLAY BUFFER

If you look at page 226, I should have an response looking at this

Response
+CGPSSTATUS: Location Not Fix
OK

I hope I provided clear information and you can check at my code, because I am blocked and I do not have any colleague who have experience on my issue.

PS: When I will solve that issue, I will delete sendATcommand() and adapt read_AT_command while I am looking for a special response from the buffer.

Many thank.
Feel you free to ask me additional information

I had to put that code into an external file

No, you didn't. You could have used the Additional Options... link and attached the file to your post.

char read_AT_string(char* command, int timeout)
{

Fails to return anything.

           if(index < Serial.readBytesUntil(13, buffer, BUFFERSIZE-1))   // One less than the size of the buffer array
            {
              Serial.println("b");
              inChar = Serial.read();  // Read a character
              buffer[index] = inChar;  // Store it
              index++;                 // Increment where to write next
              buffer[index] = '\0';    // Null terminate the string
            }

After reading all the data available, up to the carriage return, or line feed, and storing it in buffer, read another character, and stomp on what is in buffer.

Where is the sense in that? Do you understand what readBytesUntil() does?

Are you using Serial to talk to the PC or to talk to the TEL0051 shield? Both is the WRONG answer (STILL!).

The Arduino code in this demo uses < and > as start- and end- markers. You should be easily able to adapt it to expect a pair of characters at the start and end.

...R

Dear Paul,
thank for reading my post

No, you didn't. You could have used the Additional Options... link and attached the file to your post.

Sorry I have not seen that option. But as I update my file I leave it into the remote place. But in nay case I will publish the solution. Of course

I did a wrong manipulation, because I wrote comment in CAPITAL. The file you read, the comment was not there. I updated my file with comment.

Do you understand what readBytesUntil() does?

Yes, but may be I am wrong. Here is the comment I added aboce readBytesUntil()

// Serial.readBytesUntil READ THE RESPONSE UNTIL IT MEET THE CARACTER SPECIFIED IN THE FIRST PARAMETER. IN MY CASE
//IS (13). BUT I DO NOT KNOW IF IT WORK AS MY CODE NEVER RUN UNTIL THIS STEP.
// WHEN readBytesUntil reach '13', IT BUT THE STRING INTO buffer, AND IT RETURN A BYTE BALUE EGAL TO THE NUMBER OF
// CARACTERS STORE IN buffer
// IN MY IF CONDITION, WHEN index IS EGAL TO THE RETURN VALUE (byte) OF readBytesUntil() IT RETURN FALSE AND CONTINUE

Are you using Serial to talk to the PC or to talk to the TEL0051 shield?

Serial talk to TEL0051 and I do have an USB cable from my Mac to Arduino to read what display the terminal

Serial talk to TEL0051 and I do have an USB cable from my Mac to Arduino to read what display the terminal

So, you are trying to use one serial port to talk to two devices. Hasn't worked well for anyone else.