B4J Question messagearrived mqtt payload question about Hex array

giggetto71

Active Member
Licensed User
Longtime User
Hi,
maybe this is a really stupid question and in that case I apologize in advance...
I am trying to receive on B4J mqtt client an HEX array payload. the issue (which I am sure has been already discussed but I did not find a clear answer) is that the method

Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)

has the Payload() input parameter as Byte (signed byte -127 -> 128) so if the HEX number I get is below 128 then I get it right in the function payload : for example if I publish from another client (in this case I am using MqttBox) the Hex number 0x7F (127), the payload() array contains one element and its value is 127 (0x7F).
If from the test client I publish an hex number higher than 127 I get two elements in the array..For example with 0x80 published (128 decimal) the payload byte I get in the messagearrived function is a two elements array with element 0 equal to 0xFFFFFFC2 and element 1 equale to 0xFFFFFF80

1661680047067.png



Is there a way to get an unsigned bytes array ?
thanks
 

giggetto71

Active Member
Licensed User
Longtime User
thanks Don. my problem is not actually convert to unsigned. I would just like to understand why I get two bytes when on the B4j client when I publish a number higher than 129 on the mqttbox side. maybe it's just an issue on the mqttbox client..I have tried to publish from the B4j client and I did not notice any issue...
so really it's just an issue with MqttBox..I will make more tests.
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
HI,
I cannot post the publish code because the client is a 3rd party product called MqttBox that I have been using many times for testing purposes. This product allows to send different types of payload:
- Strings/JSON/XML/Characters
- Binary Array
- Octal Array
- Decimal Array
- Hex Array

if I select the array type (even the decimal) I receive perfectly on B4J if the numbers are lower than 127 for example:
1661758867533.png

on messagearrived side I get:
1661758961047.png


If I try the same array with values higher than 127 this is what I get:

1661759127973.png


thanks for any help.
 
Upvote 0
Top