How to write data from central to peripheral?



I have 2 BLE Nano devices. One is for central and the other is for peripheral device.
The reference code for central device is from “BLE central test example”.
And the reference code for peripheral device is from “Simple Chat”.

Part of main() function in my central code is as follows:


The peripheral can successfully update its value to central via hvxCallBack callback function.
But how to write data from central to peripheral ?
Can you help please?
Thank you !!

[Solved]Write from Central to Peripheral
About Transfer Data Client - Server GATT

Hi frankc,
You can use

ble.gattClient().write(GattClient::GATT_OP_WRITE_CMD,    // op write_cmd
                               chars->getConnHandle(),   // connect handle
                               chars->getValueHandle(),  // value handle
                               2,                        // len    
                               (uint8_t *)&value);       // data

BLE Nano Nordic UART Central Write data to peripheral

Hi jixing,
It works now.
Thank you !



I have another question.
Is there only one service with one characteristic that the central can launch ?

The peripheral has one service with two characteristics.
The central can discover the first one characteristic but can’t discover the second one at the same time.

In the connectionCallBack callback function described as above,ble can launch the service with RX characteristic and it works well but it can’t launch the service with TX characteristic
Please help.
Thank you !

My code is as follows:

_#define TXRX_BUF_LEN                      30_
uint8_t tx_value[TXRX_BUF_LEN] = {0,};
uint8_t rx_value[TXRX_BUF_LEN] = {0,};
GattCharacteristic characteristic1(UARTServiceTXCharacteristicUUID, tx_value, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
GattCharacteristic characteristic2(UARTServiceRXCharacteristicUUID, rx_value, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
GattCharacteristic *uartChars[] = {&characteristic1, &characteristic2};
GattService     uartService(UARTServiceUUID, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));

void connectionCallBack( const Gap::ConnectionCallbackParams_t *params )
ble.gattClient().launchServiceDiscovery(params->handle, ServiceCallBack, CharacteristicCallBack, UARTServiceUUID, UARTServiceRXCharacteristicUUID);

ble.gattClient().launchServiceDiscovery(params->handle, ServiceCallBack_new, CharacteristicCallBack_new, UARTServiceUUID, UARTServiceTXCharacteristicUUID);


Hi frankc,
I will test you problem later. Thanks for you point.


Hi frankc,
Board package V106 has been released.This version solve you question, you could try this.


Hi Jinxing,

This board package V106 solves my problem.
Thanks a lot !

I am trying to build a central device to receive notification from two peripheral devices.
After scanning,connecting then discovering service and characteristics, connect the found devices.
I find out the central can only get the first peripheral notification.
And it can’t get the second one’s notification.

For a central device, how to receive notification from two peripheral devices ?

Part of my code is as follows.
Please help !
Thank you !

static void discoveredDescTerminationCallBack(const CharacteristicDescriptorDiscovery::TerminationCallbackParams_t *params) {
  Serial.println("\r\n----discovery descriptor Termination");
    Serial.println("Open Device notify");
    uint16_t value = 0x0001;

      Serial.println("---check ONE ----");
    ble.gattClient().write(GattClient::GATT_OP_WRITE_REQ, chars_rx.getConnectionHandle(), desc_of_chars_rx.getAttributeHandle(), 2, (uint8_t *)&value);
      Serial.println("---check TWO ----");
    ble.gattClient().write(GattClient::GATT_OP_WRITE_REQ, chars_rx_2.getConnectionHandle(), desc_of_chars_rx_2.getAttributeHandle(), 2, (uint8_t *)&value);


Hi frankc,

You can’t open notify twice at the same time.
When you open notify:

    Serial.println("---check ONE ----");
    ble.gattClient().write(GattClient::GATT_OP_WRITE_REQ,chars_rx.getConnectionHandle(), desc_of_chars_rx.getAttributeHandle(), 2, (uint8_t *)&value);

After this operation finish, would call the function:

void onDataWriteCallBack(const GattWriteCallbackParams *params) 

You should open the second notify in this function.


Hi jinxing,

I put the second connection in the onDataWriteCallBack() function and it works.
Now the central can receive the notification from two peripheral devices at the same time.
Thanks a lot !!

I wonder how many peripherals the central can connect with at the same time?


Hi frankc,

Using S130, you could connect to three peripherals(you best use chip with 32KB RAM).


Hey all!

Thanks for your answers, However, I am still unable to write from central to peripheral.

Can someone give their code, both for central and peripheral for a simple write from central?




Same here, have you succeeded @kartik9k?
@frankc or @jixing, is it possible to have the code of the peripheral and central to make the write from central to peripheral working?

I understood that there is to way to do (notifying the peripheral which subscribe to change on central, or direct write from central to peripheral). But in both attempts, I failed to make it works.

Would that be possible to someone to post a small but complete example of central to peripheral writing?

Thanks in advance for the help!


I use Redbear DUO with SimpleBLECentral as central to write data to Nano2 as peripheral with SimpleChat example. It succeeds in transfer.

    uint8_t temp[] = "abcde";
    if(device.connected_handle != NULL)
      ble.writeValue(device.connected_handle, device.service.chars[0].chars.value_handle, 5, temp);