LowPowerLab Forum

Software support => Coding questions => Topic started by: MLH on February 06, 2018, 01:41:26 PM

Title: LoRa byte output to TinyGPS [solution]
Post by: MLH on February 06, 2018, 01:41:26 PM
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
Title: Re: LoRa byte output
Post by: LukaQ on February 06, 2018, 02:22:20 PM
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
Title: Re: LoRa byte output
Post by: MLH on February 06, 2018, 04:21:31 PM
TinyGPS++ accepts data one byte at a time, it cannot be fed a string.
Title: Re: LoRa byte output
Post by: Felix on February 06, 2018, 04:55:55 PM
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];
Title: Re: LoRa byte output
Post by: MLH on February 06, 2018, 09:41:10 PM
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
Title: Re: LoRa byte output
Post by: Felix on February 07, 2018, 10:09:57 AM
I wasn't sure how the tinyGPS consumed data hence the little funny part :)
Nice that you got it working ;)
Title: Re: LoRa byte output to TinyGPS [solution]
Post by: perky on February 07, 2018, 11:38:24 AM
Just as an aside, what exactly does the buff[i]; statement in the for loop do? Is this a C++ thing?

Mark.
Title: Re: LoRa byte output to TinyGPS [solution]
Post by: Felix on February 07, 2018, 11:45:01 AM
Mark - yes, see this: https://stackoverflow.com/questions/8454228/how-can-i-get-the-nth-character-of-a-string
Title: Re: LoRa byte output to TinyGPS [solution]
Post by: 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.
Title: Re: LoRa byte output to TinyGPS [solution]
Post by: Felix on February 07, 2018, 01:06:54 PM
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 :)
Title: Re: LoRa byte output to TinyGPS [solution]
Post by: perky on February 07, 2018, 01:12:54 PM
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.
Title: Re: LoRa byte output to TinyGPS [solution]
Post by: Felix on February 07, 2018, 03:51:41 PM
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.
Title: Re: LoRa byte output to TinyGPS [solution]
Post by: MLH on February 08, 2018, 08:42:45 PM
I missed that line, thanks.  Likely the result of a rogue cut and paste.  As expected, the code runs fine without it.

Mike