giggetto71 Active Member Licensed User Longtime User Aug 28, 2022 #1 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 Is there a way to get an unsigned bytes array ? thanks
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 Is there a way to get an unsigned bytes array ? thanks
DonManfred Expert Licensed User Longtime User Aug 28, 2022 #2 Maybe with this Method? Code: Copy Sub ToUnsigned(b As Byte) As Int Return Bit.And(0xFF, b) End Sub Upvote 0
giggetto71 Active Member Licensed User Longtime User Aug 29, 2022 #3 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
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.
Erel B4X founder Staff member Licensed User Longtime User Aug 29, 2022 #4 giggetto71 said: an HEX array payload Click to expand... I don't know what that means. Please post the code that sends the message. Upvote 0
giggetto71 said: an HEX array payload Click to expand... I don't know what that means. Please post the code that sends the message.
giggetto71 Active Member Licensed User Longtime User Aug 29, 2022 #5 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: on messagearrived side I get: If I try the same array with values higher than 127 this is what I get: thanks for any help. Upvote 0
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: on messagearrived side I get: If I try the same array with values higher than 127 this is what I get: thanks for any help.
Erel B4X founder Staff member Licensed User Longtime User Aug 29, 2022 #6 The client which is probably written in Java, converts the values larger than 127 to shorts = 2 bytes. Upvote 0
The client which is probably written in Java, converts the values larger than 127 to shorts = 2 bytes.