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

Interrupt when advertisement received

Hello,

I'm working on a project where I would like to use two nRF52810, one as broadcaster and one as observer. The idea is that the broadcaster sends an advertisement in a random interval. The observer should receive this advertisement. The problem I have is that this is time critical, so I would need an interrupt when the BLE package was sent on the sending device and an interrupt when the package was received on the observer. I do not want to connect the two devices since more than only these two should be added later. Is this possible? How would I set up an interrupt that fires when the advertisement was received? Ideally I would just get an interrupt on every ble advertisement arriving and filter then if it was from my sender or another device.

Thanks in advance.

  • Hello,

    I am not quire sure what you mean by time critical. Could you please elaborate?

    When you are scanning, you will get the BLE_GAP_EVT_ADV_REPORT from the softdevice. This event is usually ignored in the softdevice event handler in main.c (at least in the later SDKs), but you may add it there, to monitor the advertising packets, to check if the advertisement was from one of your devices or not.

    Just add the event to the 

    switch (p_ble_evt->header.evt_id)

    in ble_evt_handler() in main.c:

            case BLE_GAP_EVT_ADV_REPORT:
                //check the advertising packet here, like it is done in nrf_ble_scan.c
                break;

    Do you need events when you transmit an advertisement as well? This is not as straight forward, because the softdevice doesn't generate any events for this. It is probably possible to use the radio notification module, but this will give you an event a given time before the packet will be sent.

    Please be aware that advertisements is no "safe" way for data communication, because:

    1: it is not encrypted (may not be a problem for your case)

    2: There is no ACKing, meaning that there is no way to know if anyone has actually scanned your advertisement. 

    Best regards,

    Edvin

  • Hello thank you for your response.

    1. Time Critical: If I understand correctly I can send a get an interrupt before sending a bluetooth advertisement, say at t_sender. Then this advertisement will propagate in t_prop to the receiver. There I would like to have an interrupt as well at t_receiver. Now, assuming that the two microcontrollers would have the exact same time reference, I would like t_receiver - (t_sender + t_prop) which in an optimal case would be exactly zero to be < ~100μs. Hope this makes the clear what I mean by "time critical".

    2. Observer: So if I have the scanner activated continuously, I will get an interrupt of type BLE_GAP_EVT_ADV_REPORT every time I receive an advertisement? How does this work with the three advertisement channels? Are they scanned simultaneously?

    3. Broadcaster: I already managed to implement the sending interrupt using the radio notification module but it is very good to know the it gives the interrupt before the sending. Can I assume that the time between the interrupt and the sending of the advertisement is constant if the payload is of the same size?

    4. No ACK: I am aware that there are no acknowledgements and therefore no guarantees. Assuming I have a setup as described above (Both devices close to each other) I would assume that I would still get an interrupt for every advertisement sent? If not can you maybe give me an idea of around what percentage these messages would be received? Something like 75% of received messages would be fine in our application.

    Thanks again  

  • 1. The interrupt will happen at a given time (configureable) before the advertisement is sent, so in theory, you can know exactly when the advertisement will be sent. I guess ~100µs is reasonable. Depends on the advertising type, I assume, and the receivers application as well. If it is a scannable advertisement, it will take a bit longer before you get the advertising report, because the scanner has to scan for the scan response as well, and there is no time to involve the application between these two events.

    2. Yes. You will get the BLE_GAP_EVT_ADV_REPORT on every successfully scanned advertisement. Note that due to noise and external factors (such as WiFi), there is no guarantee that you will receive all the packets. And when you are advertising, there is no retransmit mechanism, like there is in BLE.

    3. Yes. You can assume that the time is constant.

    4. It is impossible to give this number. It has too many factors. Output power, antenna design, environment, noise, etc.

     

    kleinl said:
    Now, assuming that the two microcontrollers would have the exact same time reference

     That is a nice assumption, but a bit harder to actually implement. Do you have any mechanism to sync up the clocks? 

    Just as a note, before you start implementing your own wireless protocol on top of the BLE advertisements. Please note that even though there is something called an advertising interval, there is a random delay between 0 and 10ms added to each advertising interval in order to prevent consistent overlap between two advertising devices.

     

    kleinl said:
    How does this work with the three advertisement channels? Are they scanned simultaneously?

     No. They are advertised "simultaneously", but the scanner can only scan on one channel at the time. So you have some time difference here as well. But you know that the advertiser will always use channel 37, 38, 39, in that order. So you can check the channel on the adv_report on the scanner what channel the advertisement was picked up on. Depending on the advertising packet, this will add some delay. For timing based on advertising packet payload size, please check out:

    https://devzone.nordicsemi.com/nordic/power

    For how advertising and scanning works, since the device only has one radio, please see what I mean by "simultaneously" advertising on all channels, and how the scanner cycles through the channels in this guide:

    https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/bluetooth-smart-and-the-nordics-softdevices-part-1

    The unnamed figure right above the section: "II. Broadcast topology" is particularly relevant.

    Best regards,

    Edvin

  • Thank you so much for this detailed response.

    I did not find an option to configure the time of the interrupt before sending, how does one set this value?

    I am aware of the synchronization problem, there will be another signal and the relative time between these signals will be relevant for my application.

    I read somewhere about this random delay to increase robustness, it is very helpful to know that these devices are doing this automatically.

    The power tool is a nice visualization, I think I do understand the advertising process now far better.

    I will verify your answer, it really helped me a lot. If you could still answer the first question from this response this would be helpful.

    Best regards,

    Lukas

Related