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

Payload for Digital Matter Yabby Edge is not decoded #43

Open
raivisdejus opened this issue May 21, 2022 · 0 comments
Open

Payload for Digital Matter Yabby Edge is not decoded #43

raivisdejus opened this issue May 21, 2022 · 0 comments

Comments

@raivisdejus
Copy link

A decoder for /Digital_Matter/Yabby_LoRaWAN/decoder.js does not work.

The payload received from the Yabby Edge devices is some Base64 encoded string. The current decoder function implementation in the console can't process it as the decoder functions expect the parameter to be in hexadecimal encoding.

This is a sample string we get from the device XR/1IU3kYg4ABcE=
It is properly decoded by a decoder on Digital Matter site https://support.digitalmatter.com/support/solutions/articles/16000077653-decoding-the-yabby-lorawan-payload but does not work with the decoder in the repo, if it is saved in the Helium console as a decoder function.

Digital Matter decoder has this js function to get the value for bytes parameter used In the decoder.

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
      function getBase64(input)
      {
          var output = new Array();
          var chr1, chr2, chr3;
          var enc1, enc2, enc3, enc4;
          var i = 0;

          var orig_input = input;
          input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
          
          if (orig_input != input)
              return null;
              
          if (input.length % 4)
              return null;
          
          var j = 0;
          while (i < input.length)
          {
              enc1 = keyStr.indexOf(input.charAt(i++));
              enc2 = keyStr.indexOf(input.charAt(i++));
              enc3 = keyStr.indexOf(input.charAt(i++));
              enc4 = keyStr.indexOf(input.charAt(i++));

              chr1 = (enc1 << 2) | (enc2 >> 4);
              chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
              chr3 = ((enc3 & 3) << 6) | enc4;
              
              output[j++] = chr1;
              if (enc3 != 64)
                output[j++] = chr2;
              if (enc4 != 64)
                output[j++] = chr3;
          }
          
          return output;
      }

Is there a way to use this function to process the paylod value before it is sent to the decoder?

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

1 participant