Hello,
I am trying to parse a Lora package into 3 separate data points. The data comes in like this:
1000.0000000, 1000.000000, 12.34
where the data points represent longitude, latitude, altitude respectively. The data comes in as a string and I would like to separate the them into their own float values. I have tried sending them each on their own line and using getline() to put them into substrings then into floats but I have been unsuccessful. Could anyone please explain where I am going wrong.
Receiver parsing code:
#include "heltec.h"
#include "images.h"
#include<iostream>
#include <string>
using namespace std;
#define BAND 433E6 //you can set band here directly,e.g. 868E6,915E6
String rssi = "RSSI --";
String packSize = "--";
String packet, substr, slat, slon;
float lati, lon;
void LoRaData(){
Heltec.display->clear();
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(0 , 15 , "Received "+ packSize + " bytes");
Heltec.display->drawStringMaxWidth(0 , 26 , 128, packet);
Heltec.display->drawString(0, 0, rssi);
Heltec.display->display();
}
void cbk(int packetSize) {
packet ="";
packSize = String(packetSize,DEC);
for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
rssi = "RSSI " + String(LoRa.packetRssi(), DEC) ;
LoRaData();
}
void setup() {
//WIFI Kit series V1 not support Vext control
Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(0, 0, "Heltec.LoRa Initial success!");
Heltec.display->drawString(0, 10, "Wait for incoming data...");
Heltec.display->display();
delay(1000);
//LoRa.onReceive(cbk);
LoRa.receive();
}
void loop() {
int i = 0;
int packetSize = LoRa.parsePacket();
if (packetSize) { cbk(packetSize); }
while(getline(packet, substr){
if (i==0){
slat = substr;
Serial.println("slat=", slat)
i++;
} else if(i==1{
slon=substr;
Serial.println("slon=", slon)
i++
}else{
salti = substr;
}
}
delay(100);
}
For this example I had the Data coming in as:
1000.000000
1000.000000
12.34
It is not separating the values into their respective strings properly.
Thank you.