Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are there separate Chirpstack (v3) and ChirpStack v4 decoders? Single decoder works #38

Closed
danak6jq opened this issue Apr 6, 2024 · 4 comments

Comments

@danak6jq
Copy link

danak6jq commented Apr 6, 2024

There's no need for two different decoders, especially since this creates the chance of error where the actual payload decoding does not match.

Chirpstack v3 calls this function:

// Decode decodes an array of bytes into an object.
//  - fPort contains the LoRaWAN fPort number
//  - bytes is an array of bytes, e.g. [225, 230, 255, 0]
//  - variables contains the device variables e.g. {"calibration": "3.5"} (both the key / value are of type string)
// The function must return an object, e.g. {"temperature": 22.5}
function Decode(fPort, bytes, variables) {
  return {};
}

Chirpstack v4 calls this function:

// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
function decodeUplink(input) {
  return {
    data: {
      temp: 22.5
    }
  };
}

A single decoder file may contain both functions, which call a single actual decoding code.
Thus a single file will serve for both v3 and v4, allowing MileSight to make changes to a single file and users to use a single file, preventing errors.

@milesight-sway
Copy link
Contributor

That's a good idea, thanks for the offer!

@danak6jq
Copy link
Author

danak6jq commented Apr 9, 2024

I'll do a PR today with a suggested change

@milesight-sway
Copy link
Contributor

Thank you for your participation, it has been updated as per your suggestion.

@danak6jq
Copy link
Author

danak6jq commented Apr 9, 2024

This is terrific, thank you! I will test here on v3 and v4 also. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants