3

this question started life here here but this appears to be a red herring!

So, the issue is, I have a byte array of values that need to be written to a BLE device.

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 recognising the command.

When I write this command to the characteristic I get a success code of 0 (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!!!

Community
  • 1
  • 1
Joel Spencer
  • 129
  • 1
  • 8
  • `my question is, am I sending this in the correct way`. We cannot know that of course. Only if we see your code. – greenapps Mar 24 '17 at 13:40
  • Sorry, i mean I was checking to make sure I shouldn't be processing the byte[] at all before sending over the air – Joel Spencer Mar 24 '17 at 14:41

1 Answers1

2

You are doing everything correct. It's just that when you print the byte value you see signed integers in base 10. You still send the correct 8 bits for each byte over the air.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • Thanks Emil, yes Im aware that the logged output will be base10, can you think of any other reason why this command wouldn't be recognised by the BT Device? If I send the same command form the iOS version of this app to the same device from Objective C it all works perfectly – Joel Spencer Mar 24 '17 at 12:41
  • @JoelSpencer did you found out why it works with IOS and not with Android? if so, could you share the solution, because I am facing a similar problem – Allesio Pellicciotta Jan 09 '23 at 09:20