This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PCA10056/NRF52840 used android Blinky source code.

If I want to send two byte, how can I do?

I use the https://github.com/NordicSemiconductor/Android-nRF-Blinky sample code.

In BlinkyManage.jave

public void send(final boolean onOff) {
// Are we connected?
if (mLedCharacteristic == null)
return;

final byte[] command = new byte[] {(byte) (onOff ? 1 : 0)};
log(LogContract.Log.Level.VERBOSE, "Turning LED " + (onOff ? "ON" : "OFF") + "...");
writeCharacteristic(mLedCharacteristic, command);
}

Just only send one byte.

Parents
  • Hi Ray

    On the Android side, all you have to do is to initialize the command variable with two bytes instead of one:

    // Set the command buffer to {0x01, 0x02}
    final byte[] command = new byte[]{(byte)0x01, (byte)0x02};

    Please note that the blinky service is only set up to send/receive one byte on each of the two characteristics. To change this you would have to modify the characteristic configuration in ble_lbs.c to increase the max length to more than 1 byte (excerpt from line 119):

    attr_char_value.p_uuid = &ble_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len = sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len = sizeof(uint8_t);
    attr_char_value.p_value = NULL;

    If you do this I would recommend making a copy of the ble_lbs.c and ble_lbs.h files, and change the LBS_UUID_BASE define to avoid mixing your service up with the original blinky service. 

    Best regards
    Torbjørn

Reply
  • Hi Ray

    On the Android side, all you have to do is to initialize the command variable with two bytes instead of one:

    // Set the command buffer to {0x01, 0x02}
    final byte[] command = new byte[]{(byte)0x01, (byte)0x02};

    Please note that the blinky service is only set up to send/receive one byte on each of the two characteristics. To change this you would have to modify the characteristic configuration in ble_lbs.c to increase the max length to more than 1 byte (excerpt from line 119):

    attr_char_value.p_uuid = &ble_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len = sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len = sizeof(uint8_t);
    attr_char_value.p_value = NULL;

    If you do this I would recommend making a copy of the ble_lbs.c and ble_lbs.h files, and change the LBS_UUID_BASE define to avoid mixing your service up with the original blinky service. 

    Best regards
    Torbjørn

Children
Related