7 years, 2 months ago.

BLE_GAP_EXAMPLE, problem with received data

Dear all,

I have been building an application in which I receive a string from an android application and then process it.

At the moment I am just printing the value, but I have noticed a bizarre behavior that I cannot quite understand.

My message is received, I extract the bytes in a vector (the message is not of fixed size, although it is taken care that it doesn't exceed the byte restriction).

So far so good. But sometimes it seems that the data received and extracted are left inside the BLE stack and when a new message is received the same data appear again. I may have to send my data two or even 3 times in order to print the correct ones. But this doesn't happen all the time. So I would like to know if there is any way to flush the BLE stack every time I read my data form it, so that I can extract my new data.

My advertisement callback is the following:

include the mbed library with this snippet

void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) {
    myvector.clear();
    if(params->type == 3){
        for(int i = 0; i < params->advertisingDataLen; i++){
            if(params->advertisingData[i] == 0x16){
                if(params->advertisingData[i+1] == 0x34 && params->advertisingData[i+2] == 0x23){
                    for(int index = i+3; index < params->advertisingDataLen; index++){
                        myvector.push_back(params->advertisingData[index]);
                    }
                }
            }    
        }  
    }
}

I am not sure how I an flush this params object.

Be the first to answer this question.