BLE Scan and obtain RSSI

JordC1995
Posts: 2
Joined: Mon Mar 06, 2017 4:07 pm

BLE Scan and obtain RSSI

Postby JordC1995 » Tue Mar 07, 2017 10:05 am

Hi all,

I'm working on my master's thesis, and using the ESP32 as one of the main hardware components of my research project.

I've been trying to program the ESP to scan for nearby BLE devices check the MAC address and if it matches another address in a list,
return the RSSI value of the BLE device.

What API can be used to complete this particular task?
Also, how can this be implemented in code, I've been searching for examples and haven't had much luck with my understanding of it all.

Best wishes,

Jordan

rene007
Posts: 1
Joined: Tue Mar 07, 2017 11:38 am

Re: BLE Scan and obtain RSSI

Postby rene007 » Tue Mar 07, 2017 11:41 am

Start by looking here.

https://github.com/espressif/esp-idf/bl ... ttc_demo.c

Use the espressif SDK to flash the code in the link above into the chip.

The key thing is to set your ESP32 as a GATT client in order to scan for nearby BLE devices.

torntrousers
Posts: 21
Joined: Mon Dec 21, 2015 9:30 am

Re: BLE Scan and obtain RSSI

Postby torntrousers » Wed Mar 08, 2017 7:37 am

Some (ESP32/Arduino) code is here showing a scan and getting the mac address and RSSI. Described in the article here.

f.h-f.s.
Posts: 214
Joined: Thu Dec 08, 2016 2:53 pm

Re: BLE Scan and obtain RSSI

Postby f.h-f.s. » Wed Mar 08, 2017 4:42 pm

in the "esp_gap_cb" function, case: "ESP_GAP_BLE_SCAN_RESULT_EVT" the param argument is cast to scan_result(in the example). This struct contains all the information you need.

From esp_gap_ble_api.h:

Code: Select all

    struct ble_scan_result_evt_param {
        esp_gap_search_evt_t search_evt;			/*!< Search event type */
        esp_bd_addr_t bda;							/*!< Bluetooth device address which has been searched */
        esp_bt_dev_type_t dev_type;					/*!< Device type */
        esp_ble_addr_type_t ble_addr_type;			/*!< Ble device address type */
		esp_ble_evt_type_t ble_evt_type;			/*!< Ble scan result event type */
        int rssi;									/*!< Searched device's RSSI */
        uint8_t  ble_adv[ESP_BLE_ADV_DATA_LEN_MAX]; /*!< Received EIR */
        int flag;									/*!< Advertising data flag bit */
        int num_resps;								/*!< Scan result number */
    } scan_rst;										/*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */
scan_result->scan_rst.bda is the address (uint8_t array, length 6)
scan_result->scan_rst.ble_adv is the advertisement (uint8_t array, length 31)
scan_result->scan_rst.rssi would be the rssi (int)

The RSSI is not very stable though, i've measured -19 ~ -59 for a distance less than a meter. http://pastebin.com/fHrya27z

JordC1995
Posts: 2
Joined: Mon Mar 06, 2017 4:07 pm

Re: BLE Scan and obtain RSSI

Postby JordC1995 » Wed Mar 08, 2017 5:18 pm

Hi,

Thanks for all the very useful responses from rene007, torntrousers and f.h.f.s.
You've all been of great help to me.

A little update on what I did:

I read the article posted by torntrousers, which was very useful indeed. Step by step guide detailing how to obtain the RSSI and MAC address. The code provided by f.h.f.s has aided my understanding of how this process works and furthermore, I installed the Espressif SDK as mentioned by rene007.

I now have the ESP32 running and it's sampling RSSI values of nearby BLE advertising nodes successfully.

However, one slight problem as highlighted by f.h.f.s, the values are very fluctuant, even when the advertising node is very close to the ESP32. I'm unsure about why this is, but I assume it's a hardware limitation :geek: .

Once again, thanks for all your help & advice.

Best wishes,
Jordan

madscientist_42
Posts: 95
Joined: Tue Feb 21, 2017 10:17 pm

Re: BLE Scan and obtain RSSI

Postby madscientist_42 » Wed Mar 08, 2017 8:00 pm

Much of the GATT Client code is not needed if you're just doing a Scanner.

The pieces are all there, and you only need to keep it running (Restart the scan with the timeout on the completion event on the GAP callback) and clear out the stop and GATT search, etc. code out of the GAP scan result event code. As mentioned, RSSI is in the event result structure.

neilyoung
Posts: 12
Joined: Fri Mar 03, 2017 8:12 pm

Re: BLE Scan and obtain RSSI

Postby neilyoung » Fri Apr 21, 2017 7:35 pm

Don't trust the RSSI values, it is mostly complete nonsense

petcovici
Posts: 1
Joined: Mon Apr 24, 2017 5:14 pm

Re: BLE Scan and obtain RSSI

Postby petcovici » Mon May 08, 2017 6:30 pm

Hello! I work in a similar project, so I need to collect MAC data from multiple readers along a road corridor.
In some point I don't have WI-fi signal, so I need to write data to a SD Card.
Do you think it's possible to add a time stamp to my ESP32 Mac addresses?
Do you think this project it's feasible with ESP 32 and Arduino IDE ?
Where should I start searching for more information?

Thank you

madscientist_42
Posts: 95
Joined: Tue Feb 21, 2017 10:17 pm

Re: BLE Scan and obtain RSSI

Postby madscientist_42 » Mon May 08, 2017 7:12 pm

neilyoung wrote:Don't trust the RSSI values, it is mostly complete nonsense
It is? What basis do you have for this? Did you do the requisite analysis with precision equipment and arrived at this? If not...how can you claim it's nonsense?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: BLE Scan and obtain RSSI

Postby WiFive » Mon May 08, 2017 7:48 pm

madscientist_42 wrote:
neilyoung wrote:Don't trust the RSSI values, it is mostly complete nonsense
It is? What basis do you have for this? Did you do the requisite analysis with precision equipment and arrived at this? If not...how can you claim it's nonsense?
https://github.com/espressif/esp-idf/is ... -287391770

Who is online

Users browsing this forum: No registered users and 62 guests