ricaun / LoRaWanPacket

LoRaWanPacket Encode / Decoder
MIT License
10 stars 2 forks source link

LoRaWANPacket.print #2

Closed Samuel-ZDM closed 3 years ago

Samuel-ZDM commented 3 years ago

Hello!

It’s me here again with doubts. Sorry for the inconvenience.

I am studying your code and could not find the definition of the LoRaWanPacket.print () function. I'm looking for the definition of it because I wanted to send a byte vector instead of a char vector because I'm using the TTN with the Cayenne payload and I can't get it to work with a char vector.

I believe that the LoRaWanPacket.print (" ") function stores the data in the buffer to be used in the encode function.

Sorry about the questions.

Thank you very much in advance.

ricaun commented 3 years ago

Hello,

Actually, the library uses the Stream class.

To use CayenneLPP check the example below. I usually use https://github.com/ElectronicCats/CayenneLPP

#include <CayenneLPP.h>

void LoRa_sendMessage()
{
  LoRa_TxMode();
  LoRaWanPacket.clear();
  PayloadNow(LoRaWanPacket);
  if (LoRaWanPacket.encode())
  {
    LoRa.beginPacket();
    LoRa.write(LoRaWanPacket.buffer(), LoRaWanPacket.length());
    LoRa.endPacket(true);
  }
}

void PayloadNow(Stream &out)
{
  CayenneLPP lpp(64);

  lpp.addVoltage(1, 3.3);

  out.write(lpp.getBuffer(), lpp.getSize());
}

See yaa!

Samuel-ZDM commented 3 years ago

Very good!

It worked just fine.

Thank you very much for your help!