anthonykirby / lora-packet

LoRa radio packet decoder
MIT License
261 stars 83 forks source link

Construct a packet with no payload #6

Closed larkolab closed 7 years ago

larkolab commented 7 years ago

Hello Anthony,

And first of all, things for this library, it's great! :)

I'm trying to use it with Node-Red do do a minimal LoRaWAN server, and I'm trying to send a downlink packet to respond to a "Confirmed Data Up". This kind of response does not require a FRMPayload, and so does not require a FPort.

But I can't find the way to specify such a packet to the fromFields() function. When I set the 'payload' field empty, I still get the FPort set. Can we avoid it?

My code is like:

var constructedPacket = lora_packet.fromFields(
    {
        payload:'',
        MType: 'Unconfirmed Data Down',
        DevAddr: new Buffer('11223344', 'hex'),
        FCtrl: {
            ADR: false,       // default = false
            ACK: true,        // default = false
            ADRACKReq: false, // default = false
            FPending: false   // default = false
        },
        FCnt: new Buffer('0000', 'hex'), // can supply a buffer or a number
    },
    null,
    new Buffer("2B7E151628AED2A6ABF7158809CF4F3C", 'hex') // NwkSKey
);

And I get the frame: YK8BzAAgAAABmjJuDQ==

( MACPayload = FHDR | FPort | FRMPayload ) FHDR = AF01CC00200000 FPort = 01 FRMPayload =

It's not really critical, but we could avoid this extra-byte for FPort. Is that possible?

Thanks a lot

anthonykirby commented 7 years ago

looking at the LoRa spec 4.3.2 Port field the port field is optional "If the frame payload field is not empty, the port field must be present" so that's a reasonable request!

anthonykirby commented 7 years ago

done - thank you for the suggestion! Ant

larkolab commented 7 years ago

great, thanks! :)