I'm currently using ble_advdata_set to update the ble advert data packet. Before transmission I use the ble_radio_notification event. In this event for test purposes a single byte counter is incremented and transmitted.
The notification settings are below.
ble_radio_notification_init(...LOW,..5500US, ble_on_radio_active_event)
At the receiver end, even though the counter/transmitted data is incremented before each transmission, I sometimes see the same counter value twice.
For test purposes I tried a range of transmission rates, 20ms -> 100ms etc... However I still see the same result.
My next step was to raise the priority of the radio notifier.
ble_radio_notification_init(...HIGH,..5500US, ble_on_radio_active_event)
In the ble_on_radio_active_event, I place the ble packet update function in the app scheduler event queue using app_sched_event_put. The test results were similar to the previous results with duplicate counter values.
For the next experiment, I used the radio notify event to start a timer.
For example for a 100ms transmission rate, the radio notify event occurs for example 5.5ms before the transmission. Then a timer triggers a ble packet update 10ms later. The idea is there should be about 90ms of time to update the packet.
However even this strategy failed.
The timing of the duplicate values appears to be erratic. The app scheduler queue, is always 0 or 1 in length.
The base of the code is invensense ble_app_inv, This initialises the ble stack, the software device handler and various callbacks. I so far can see no evidence of the ble events (using the debugger). My initial thoughts was a high priority interrupt was delaying the packet update and hence the transmission of the duplicate packet. I think this is still a possibility.
I can carried out further tests. Placing the counter increment and ble packet update function directly in the radio notify event (With a low priority). I noticed at the test receiver end, with a transmission rate set at 100ms, the receive time was always just over 100ms. When a packet was received twice this time would become 3ms. I don't think it is possible for a packet to be transmitted with such a small time gap unless there is a problem. On the receiver end, the Android ble stack is known to have various problems, however I'm using Linux. Again there is the possibility the problem is on the receiver end.