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

BLE notification and write value not working

I have followed the well written blog post on how to create custom service on this site. I downloaded the sdk 13 code for the same and i can send and receive values on the Nordic android app.

Blog: devzone.nordicsemi.com/.../

SDK 13 code: devzone.nordicsemi.com/.../15bc9d099b645556b335757c662d3d54

Link: devzone.nordicsemi.com/.../

For me three things are not working as expected:

  1. printf commands are working but NRF_LOG_INFO is not working

  2. iPad is sending cccd value as 0x20002128 instead of 0x0001 to enable notification hence it in not going in the loop as shown below to print "Char cccd Notification enabled"

cccd handle is 0x0011

Putty Text:

Value received on handle 0x0011: 0x20002128

else if(p_ble_evt->evt.gatts_evt.params.write.handle == p_our_service->char_handles.cccd_handle)
    {
        // Get data
        sd_ble_gatts_value_get(p_our_service->conn_handle, p_our_service->char_handles.cccd_handle, &rx_data);
        // Print handle and value 
        printf("\r\nValue received on char cccd handle %#06x: %#06x\r\n", p_ble_evt->evt.gatts_evt.params.write.handle, data_buffer);
        if(data_buffer == 0x0001)
        {
            printf("\r\nChar cccd Notification enabled\r\n");
        }
        else if(data_buffer == 0x0000)
        {
            printf("\r\nChar cccd Notification disabled\r\n");
        }
    }
  1. I can not write the value from iPad. I modified the code here a little bit so when we receive "28\0" it will enable the gpio pin and enable the led. (external not oboard)

    uint8_t ledValue = atoi(rx_data.p_value); if(ledValue >= 28 || ledValue <= 31){ only_enable_led(ledValue); }

When i send "28\0" from Nordic app it works.

But does not work from ipad swift 3 code is below:

  sendValueToBLE("28\0")

  func sendValueToBLE(value: String) {
            let data = value.data(using: String.Encoding.utf8)
            for blePeripheral in devicePeripherals{
                for characteristic in blePeripheral.services?.first?.characteristics as [CBCharacteristic]!
                {
                    let c = characteristic.uuid.uuidString
                    if(characteristic.uuid.uuidString.starts(with: "0000BEE2"))
                    {
                        blePeripheral.writeValue(data!, for: characteristic, type: CBCharacteristicWriteType.withoutResponse)
                    }
                }
            }
        }

i can see in debugger it executes this line:

blePeripheral.writeValue(data!, for: characteristic, type: CBCharacteristicWriteType.withoutResponse)

But it shows this on output window:

WARNING: Characteristic <CBCharacteristic: 0x1c40a58e0, UUID = 0000BEE2-1212-EFDE-1523-785FEF13D123, properties = 0x1A, value = (null), notifying = YES> does not specify the "Write Without Response" property - ignoring response-less write

Also putty does not show any message received. My be this command is failing to send any data to NRF52-DK.

Parents
  • @ Rahul: To answer your third question: In the tutorial, the write without response property for the characteristic is not set. That is probably why you get the "Write Without Response property "-warning. I'm not familiar with Swift, but maybe there is an API call looking something like this: CBCharacteristicWriteType.withResponse (Notice this is with response and not without). You can also try to set the read without response property on the peripheral side when you initiate the characteristic.

Reply
  • @ Rahul: To answer your third question: In the tutorial, the write without response property for the characteristic is not set. That is probably why you get the "Write Without Response property "-warning. I'm not familiar with Swift, but maybe there is an API call looking something like this: CBCharacteristicWriteType.withResponse (Notice this is with response and not without). You can also try to set the read without response property on the peripheral side when you initiate the characteristic.

Children
No Data
Related