I am working with a heltec LoRa32 board. I created a sensor that sends data in the form of a string to this LoRa Board. The data in the string is complete from the sender (I've verified in the serial monitor of that board using a serial.print statement). I have also verified the on the receiver that the data is correct by running another serial.print statement on this board. The issue I'm having is spitting the string up and storing them as variables to be used later. Any suggestions?
#include "heltec.h"
#define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6
int id = 0;
int hourRead = 0;
int minRead = 0;
int secRead = 0;
float latRead = 0;
float lonRead = 0;
float altRead = 0;
int sensorRead = 0;
float voltRead = 0.0;
float percRead = 0.0;
String rc = "";
void setup() {
//WIFI Kit series V1 not support Vext control
Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
Serial.begin(115200);
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.println("Received packet '");
// read packet
while (LoRa.available()) {
rc = LoRa.readString();
int buffer_len = rc.length() + 1;
char buffer[buffer_len];
rc.toCharArray(buffer, buffer_len);
sscanf(buffer, "%d,%d,%d,%d,%f,%f,%d,%f,%f", &id, &hourRead, &minRead, &secRead, &latRead, &lonRead, &altRead, &sensorRead, &voltRead, &percRead);
Serial.println(rc);
showData();
}
}
}
void showData() {
Serial.print("ID: "); Serial.println(id);
Serial.print("Time: "); Serial.print(hourRead); Serial.print(":"); Serial.print(minRead); Serial.print(":"); Serial.println(secRead);
Serial.print("Location: "); Serial.print(latRead); Serial.print(","); Serial.println(lonRead);
Serial.print("Altitude: "); Serial.println(altRead);
Serial.print("Sensor Reading: "); Serial.println(sensorRead);
Serial.print("Voltage: "); Serial.println(voltRead);
Serial.print("Battery: "); Serial.print(percRead); Serial.println("%");
}
this is the output I'm getting( the 0's in the rc serial.println are because the gps module on the sender cant reach the satellites in my apartment, but I went outside with my laptop to verify that it is still reading) It should still give me the data for the sensor reading, voltage and battery percentage in the apartment but it is not.
Received packet '
1,0,0,0,0.000000,0.000000,0.00,-252,14.41,1100.00
ID: 1
Time: 0:0:0
Location: 0.00,0.00
Altitude: 0.00
Sensor Reading: 0
Voltage: 0.00
Battery: 0.00%