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

Problem with frame length to sent of APP

Hello,
I am developing a system where I have a app and a Rigado BMD-300 Module. I am using, for experiment, the nRF Connect App and in program, I use SDK 14.2 and s132 softdevice.
My question is that I want sending 5 bytes (40 bits) but the App only permite sending 4 bytes (32 bits).
I don't understand if my problem is in APP or in my code.
I believe that it is in APP and/or in definition of parameter GATT because I got following error when I send a frame: error 13 (0xd): GATT INVALID ATTR LEN.
I, also, thought that can to be limitation of Bluetooth but I don't no idea.
I want help for understand the error and I want meet a solution for problem.
Thanks and the best regards,
Daniel Fernandes

Parents
  • Hi Daniel, 

    can you post the snippet from the application code where you add the characteristic that you're trying to write to? I want to make sure that the size of the characteristic is set 5 and not 4.

    Best regards

    Bjørn 

  • I don't know if I understand your question, but I send this short part of my code. 

    static uint32_t our_char_add(ble_os_t * p_our_service, ble_gatts_char_handles_t* p_chandle, uint16_t chuuid, bool notifyenabled, bool writeenabled, uint32_t* p_value)
    {
        uint32_t            err_code;
        ble_uuid_t          char_uuid;
        ble_uuid128_t       base_uuid = BLE_UUID_OUR_BASE_UUID;
    
        char_uuid.uuid = chuuid;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
        APP_ERROR_CHECK(err_code);
    
        // Add read only properties to our characteristic
        ble_gatts_char_md_t char_md;
        memset(&char_md, 0, sizeof(char_md));
        char_md.char_props.read = 1;
        char_md.char_props.write = 0;
        
        if (notifyenabled) {
            // Configuring Client Characteristic Configuration Descriptor metadata
            // for notification and add to char_md structure
            // This should be read/write
            static ble_gatts_attr_md_t cccd_md;
            memset(&cccd_md, 0, sizeof(cccd_md));
            BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
            BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
            cccd_md.vloc                = BLE_GATTS_VLOC_STACK;    
            char_md.p_cccd_md           = &cccd_md;
            char_md.char_props.notify   = 1;   
        }
        
        // Configure the attribute metadata
        ble_gatts_attr_md_t attr_md;
        memset(&attr_md, 0, sizeof(attr_md));  
        attr_md.vloc        = BLE_GATTS_VLOC_USER; // user provided location
        
        // Set read/write security levels to our characteristic
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        if (writeenabled) {
            char_md.char_props.write = 1;
            BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
        } else {
            BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
        }
        
        // Configure the characteristic value attribute
        ble_gatts_attr_t    attr_char_value;
        memset(&attr_char_value, 0, sizeof(attr_char_value));
        attr_char_value.p_uuid      = &char_uuid;
        attr_char_value.p_attr_md   = &attr_md;
        
        // Define characteristic length (in number of bytes) and set
        // initial value to whatever passed to here
        attr_char_value.max_len     = 4;
        attr_char_value.init_len    = 4;
        attr_char_value.p_value     = (uint8_t *)p_value;
    
        // Add our new characteristic to the service
        err_code = sd_ble_gatts_characteristic_add(p_our_service->service_handle,
                                                    &char_md,
                                                    &attr_char_value,
                                                    p_chandle);
        APP_ERROR_CHECK(err_code);
    
        return NRF_SUCCESS;
    }
    

  • Exactly what I wanted. In your code you'll see that the length of the characteristic value is set to 4, i.e. 4 bytes.

    attr_char_value.max_len = 4;
    attr_char_value.init_len = 4;

    If you change this to 

    attr_char_value.max_len = 5;
    attr_char_value.init_len = 5;

    Then you should be able to write 5bytes to the characteristic. 

    Best regards

    Bjørn 

Reply Children
Related