Reputation: 1
i have a short question for some standard problem.
How can I read a full line from a receive buffer without getline(), fgets or scanf().
Because its not availble in the arduino enviroment.
I get only one sign, after saving data into message. Here my code:
message = ((char)LoRa.read());
With the serial monitor it works fine to receiv and print the full line from the sender.
Thanks so much :)
Tried to find some libs for using getline(), fgets or scanf() in arduino ide. But it couldnt work
Upvotes: 0
Views: 332
Reputation: 66
Could be something like this:
char incomingMessage[200];
String receivedLine;
uint16_t pointer = 0;
bool lineReceived = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
memset(incomingMessage, NULL, sizeof(incomingMessage));
receivedLine.reserve(200);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
incomingMessage[pointer] = (char)Serial.read();
pointer++;
if (incomingMessage[pointer] == '\n') {
lineReceived = true;
}
}
if (lineReceived) {
lineReceived = false;
receivedLine = "";
pointer = 0;
receivedLine = incomingMessage;
memset(incomingMessage, NULL, sizeof(incomingMessage));
}
}
Upvotes: 0