0
byte bytes[] = {0x04,0x08,0x0F,0x66,(byte)0x99,0x41,0x52,0x43,0x55,(byte)0xAA};
ch.setValue(bytes);

If I log the output of this array I get (note the negative values):

[4, 8, 15, 102, -103, 65, 82, 67, 85, -86]

But in theory this should only be java's representation of the values and shouldn't affect the perceived values when they hit the Bluetooth device but this doesn't seem to be the case

These values are required by the manufacturer so cannot be changed, however, 2 of the values are out of the range of an unsigned byte/int and it appears that this is the reason the device isn't recognizing the command.

When I write this command to the characteristic I get a success. But the device doesn't act upon the command.

So, my question is, am I sending this in the correct way, or should I be formatting/processing the byte array in order to maintain the perceived values contained within?

Any advice greatly appreciated!!!

Rkreddy
  • 41
  • 3
  • `If I log the output of this array I get (note the negative values):`. Then your log code has interpreted the byte values as signed. Interprete them as unsigned. Or print the hex value. Further it is unclear if you log at sender or receiver side. And when. – greenapps Aug 20 '18 at 12:08
  • `ch.setValue(bytes);` Should we know what this statement does? – greenapps Aug 20 '18 at 12:08
  • `am I sending this in the correct way,` ??? I see no code where you send those bytes. Nor code that receives them. – greenapps Aug 20 '18 at 12:09
  • `2 of the values are out of the range of an unsigned byte/int` ?? Which ones? – greenapps Aug 20 '18 at 12:11
  • @greenapps ch.setValue(bytes) actually send the byte array to the intended characteristic. – Rkreddy Aug 20 '18 at 12:15
  • @greenapps -103, -86 are the out of range – Rkreddy Aug 20 '18 at 12:17
  • You cannot say as such. 0x99 is 153 dec. And 153 is out of range when you interprete the bytes as signed. As then the max value is 127. – greenapps Aug 20 '18 at 12:21
  • `How to send Hex string as a unsigned byte[] ` You have no hex string. You have a byte array. Every byte has a value. Just send the byte array as you do now. But look at the receiver side what you get. Print the bytes hexadecimal. – greenapps Aug 20 '18 at 12:27
  • @greenapps Yeah, I know. How can I send byte[] to BLE characteristic as unsigned byte[]? – Rkreddy Aug 20 '18 at 12:29
  • Nonsense. `Just send the byte array as you do now.`. There is no unsigned byte[]. There is only byte[]. So go at receiver side and print the values of the bytes in the received byte array hexadecimal. – greenapps Aug 20 '18 at 12:30

0 Answers0