Hello,
I'm struggling to receive all data from a serial port and store it into a char array so I can work with it.
The full data i should receive is:
+QMTRECV: 0,3,"command/test","{"data":"Test","ispublic":true,"ts":1605188045123}"
This is coming in from a quectel BG96 when subscribed to a mqtt topic, so I don't know when it is coming in, I have to catch it, also the length of the "data" could be much higher.
I do receive this when I use Serial.readString(), but since arduino cannot handle strings easily I do not prefer to use this function, I already see it crashing sometimes after running a while because of this.
So I replaced it with the code below:
uint16_t index = 0;
char _buffer[255];
while (cellular.available())
{
char c = cellular.read();
if (c == '\r')
{
continue;
}
if (c == '\n' && index == 0)
{
// Ignore first \n.
continue;
}
_buffer[index++] = c;
}
_buffer[index] = 0;
if(index > 0)
{
loggerPrint("[QUECTEL] SERIAL: ");
loggerPrintln(_buffer);
}
Located in the main loop.
This is basicly how all examples I could found show me, I tried some different ways but the outcome is never the right.
This code results the following:
+QMTRECV: 0,1,"command/test","{"data":"Test","ispublic":tru
I figured as this are about 63 bytes, it has something to do with the serial buffer of max 64, but since I'm reading it in the while it should read the bytes before the buffer is full, right?
Thanks!