I have an application where I would like to feed byte data from the LoRa to TinyGPS++. I'm having difficulty adapting the code which outputs in string format.
void getRadio()
{
if (rf95.available())
buf[RH_RF95_MAX_MESSAGE_LEN];
byte len = sizeof(buf);
if (rf95.recv(buff, &len))
{
Serial.print((char*)buff);
}
Thanks,
Mike
I won't be able to help much, but you have buff and buf. That also can be right, just don't know
why don't you use one of the sketch, that sends string? I think it is Node.ino
TinyGPS++ accepts data one byte at a time, it cannot be fed a string.
The radio is giving you a string (byte array). So you can traverse the byte array one char (ascii byte) at a time and delegate it as needed. I think that's what you need.
for (byte i=0; i<len ; i++)
tinyGps : eat some buff[i];
Felix,
I was for the most part there, just needed a nudge in the right direction. The second line of code was the key " tinyGps : eat some buff;".
Here's the working code I ended up with:
void loop()
{
if (rf95.available())
buf[RH_RF95_MAX_MESSAGE_LEN];
byte len = sizeof(buf);
if (rf95.recv(buff, &len))
{
Serial.println((char*)buff); //send to COM port 4800 baud
for (int i = 0; i < len ; i++)
{
buff[i];
if (gps.encode(buff[i])) // <--- now pass it to TinyGPS
{
index = 0;
if (gps.location.isValid())
{
Serial1.print(F("Location: ")); //send to COM port 19200 baud
Serial1.print(gps.location.lat(), 6); Serial1.print(F(", ")); Serial1.print(gps.location.lng(), 6);
Serial1.print(F(", ")); Serial1.print(gps.altitude.feet(), 1); Serial1.println(F(" Ft."));
}
Thanks,
Mike
I wasn't sure how the tinyGPS consumed data hence the little funny part :)
Nice that you got it working ;)
Just as an aside, what exactly does the buff[i]; statement in the for loop do? Is this a C++ thing?
Mark.
Mark - yes, see this: https://stackoverflow.com/questions/8454228/how-can-i-get-the-nth-character-of-a-string
Sorry, still don't get it from that post Felix. The statement seems to do nothing at all, there's no assignment or anything. Unless C++ interprets that as something special, I'm sure it would be a syntax error in C.
Mark.
Quote from: perky on February 07, 2018, 12:04:36 PM
Sorry, still don't get it from that post Felix. The statement seems to do nothing at all, there's no assignment or anything. Unless C++ interprets that as something special, I'm sure it would be a syntax error in C.
Mark.
It was actually this:
tinyGps : eat some buff[i];Pseudo c++ coding :)
I meant the MLH's code, that has statement in there which is just
buff[i];
in the for loop. What does it do???
Mark.
Oh, from his code block.
It's probably a glitch in his code.
It's actually a perfectly valid statement, does nothing though. I assume the compiler scraps it.
I missed that line, thanks. Likely the result of a rogue cut and paste. As expected, the code runs fine without it.
Mike