For LoRa there is an 0.1% and 1.0% duty cycle per day depending on the channel. 10Hz is high
if you know the packet you receive holds "+RCV=1,4,3996,-34,13" then keep It simple. read the payload into a buffer and use sscanf() to extract the elements. Reading from the "stream" might not be the most effective way to solve this.
if you have a c-string, you could extract the content with sscanf(). the function is pretty versatile and tells you if the parsing was matching the expected format.
here is something to try:
void setup() {
Serial.begin(115200);
int fromID;
int len;
int sonarEcho;
int rssi;
int snr;
char message[] = "+RCV=1,4,3996,-34,13"; // canned response for testing purpose
int pos = 0;
if (sscanf(message, "+RCV=%d,%d,%d,%d,%d", &fromID, &len, &sonarEcho, &rssi, &snr) == 5) {
// we could read the 5 parameters based on the format
Serial.print("fromID: "); Serial.println(fromID);
Serial.print("len: "); Serial.println(len);
Serial.print("sonarEcho: "); Serial.println(sonarEcho);
Serial.print("rssi: "); Serial.println(rssi);
Serial.print("snr: "); Serial.println(snr);
} else {
Serial.print("Error parsing message: "); Serial.println(message);
}
}
void loop() {}
so if you want to apply that to LoRa then just do something like this
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
int fromID;
int len;
int sonarEcho;
int rssi;
int snr;
Serial.print("Received packet '");
char message[packetSize + 1]; // +1 for trailing null char
int pos = 0;
while (LoRa.available()) message[pos++] = (char) LoRa.read();
message[pos] = '\0'; // "+RCV=1,4,3996,-34,13"
if (sscanf(message, "+RCV=%d,%d,%d,%d,%d", &fromID, &len, &sonarEcho, &rssi, &snr) == 5) {
// we could read the 5 parameters based on the format
Serial.print("fromID: "); Serial.println(fromID);
Serial.print("len: "); Serial.println(len);
Serial.print("sonarEcho: "); Serial.println(sonarEcho);
Serial.print("rssi: "); Serial.println(rssi);
Serial.print("snr: "); Serial.println(snr);
} else {
Serial.print("Error parsing message: "); Serial.println(message);
}
}
}