Android Question Unsigned bytes array

quique

Member
Licensed User
Longtime User
Hi there!

I am trying to send an array of bytes as an MQTT payload.

The first byte of my payload needs to be value 255 ...

My payload is a string (everything but that byte). So suppose:

Dim command as String ="?THIS IS MY MQTT MESSAGE"
Dim payload() as byte = command.GetBytes("ASCII")
payload(0) = 255

ok ... this does not work. And if I do a log (payload(0)) I get -1 (signed byte!).

Could it be that the MQTT library bombs because of it ?

If I change that 255 value into any ascii value, it gets sent. But when I insert a 255 value, nothing happens with MQTT.

Any help is appreciated,

Enrique
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
I think a Java Byte data type (which is what the B4A Byte is) has a value range of -127 to 127. If you try your code with any value in that range it will work.

- Colin.
 
Upvote 0

quique

Member
Licensed User
Longtime User
Hi, Thanks Colin! Actually I feel embarrassed as I did repeat what I posted first, and now it works fine ! I did reset my machine, between tries, tho.
 
Upvote 0
Top