Author Topic: LoRa byte output to TinyGPS [solution]  (Read 903 times)

MLH

  • Newbie
  • *
  • Posts: 11
LoRa byte output to TinyGPS [solution]
« 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.

Code: [Select]
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
« Last Edit: February 07, 2018, 10:10:26 AM by Felix »

LukaQ

  • Sr. Member
  • ****
  • Posts: 283
  • Country: si
Re: LoRa byte output
« Reply #1 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

MLH

  • Newbie
  • *
  • Posts: 11
Re: LoRa byte output
« Reply #2 on: February 06, 2018, 04:21:31 PM »
TinyGPS++ accepts data one byte at a time, it cannot be fed a string.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5813
  • Country: us
    • LowPowerLab
Re: LoRa byte output
« Reply #3 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.

Code: [Select]
for (byte i=0; i<len ; i++)
   tinyGps : eat some buff[i];

MLH

  • Newbie
  • *
  • Posts: 11
Re: LoRa byte output
« Reply #4 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:

Code: [Select]
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

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5813
  • Country: us
    • LowPowerLab
Re: LoRa byte output
« Reply #5 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 ;)

perky

  • Hero Member
  • *****
  • Posts: 871
  • Country: gb
Re: LoRa byte output to TinyGPS [solution]
« Reply #6 on: February 07, 2018, 11:38:24 AM »
Just as an aside, what exactly does the
Code: [Select]
buff[i];
statement in the for loop do? Is this a C++ thing?

Mark.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5813
  • Country: us
    • LowPowerLab

perky

  • Hero Member
  • *****
  • Posts: 871
  • Country: gb
Re: LoRa byte output to TinyGPS [solution]
« Reply #8 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.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5813
  • Country: us
    • LowPowerLab
Re: LoRa byte output to TinyGPS [solution]
« Reply #9 on: February 07, 2018, 01:06:54 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:

Code: [Select]
tinyGps : eat some buff[i];

Pseudo c++ coding :)

perky

  • Hero Member
  • *****
  • Posts: 871
  • Country: gb
Re: LoRa byte output to TinyGPS [solution]
« Reply #10 on: February 07, 2018, 01:12:54 PM »
I meant the MLH's code, that has statement in there which is just
Code: [Select]
buff[i];
in the for loop. What does it do???

Mark.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5813
  • Country: us
    • LowPowerLab
Re: LoRa byte output to TinyGPS [solution]
« Reply #11 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.

MLH

  • Newbie
  • *
  • Posts: 11
Re: LoRa byte output to TinyGPS [solution]
« Reply #12 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