Decode specific byte

Hi there,

I am sending text data from a device. This text is contained in the array from Byte 6. Could anyone help me work out how to decode the array after byte 6 please?

the Base64 is:

AwYABgABMTIzNEtn

The code i use at the moment is:

function Decode(fport, bytes) {
  // Decode plain text; for testing only 
  return {
      receivedString: String.fromCharCode.apply(null, bytes)
  };
}

This obviously returns the full byte string in text form as below:

decode

I am not interested in returning the data from the first 5 bytes as these are stop characters etc. I am only interested in extracting the ‘1234Kg’

Any ideas welcome!

Thanks,
Lee

use construction look like this
var some.variable = bytes[offset];

offset = 4 in Your case

P.S. Why You create many topics around your single problem?

1 Like

Hey thanks for the reply, I am up against a deadline to get this coded and I am struggling to get to an answer quickly, hence so many topics in different forms. The first where about getting the data to show, once i did that they were about ignoring the first four bytes.

So presumably if i did something like that in my decoder, the code would then look something like below?:

function Decode(fport, bytes) {
  // Decode plain text; for testing only 
     var weight.value = bytes[4];
  return {
      receivedString: String.fromCharCode.apply(null, weight.value)
  };
}

?

Thank you for your reply by the way, it has been the most helpful so far. As you will have seen on my other posts, I am new to this and everything is a learning curve for me. I really appreciate you replying!

Just test it and You’ll see. The purpose of my posts is to give right direction. :slight_smile:

I tested that and I got this error repeatedly no matter what i seemed to do.

error :"js vm error: TypeError"

It gives me no clue as to what the problem is or how to fix it, that is the only feedback i get.

I am so confused because the raw code i submitted first gives me a string that contains the data i need, I just need to ignore the first few bits but I just can’t figure out how to do it. I know the aim is to give me the direction to head in and let me figure it out but I am in need of a little more guidance if possible?

Thanks,

Try below decoder function

function Decode(fport, bytes) {
  // Decode plain text; for testing only 
     var value = bytes[4];
  return {
      receivedString: String.fromCharCode(value);
  };
}
1 Like

Hi,

Thanks you so much for that, it is the kind of help I have been looking for!

I tried the code and I don’t get any errors with that (apart from one because there was a semi-colon at the end of receivedString: String.fromCharCode(value); that didnt need to be there but sorted that.

When i upload data to the server however. I get the result:

receivedString:"";

Any ideas on why that is? I have tried different byte numbers in the argument too and that didnt work either.

You can try this:
var offset = 4;
var weight = bytes.substr(offset);
return {
receivedString: weight;
};