BLE Scan and obtain RSSI
BLE Scan and obtain RSSI
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
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
Re: BLE Scan and obtain RSSI
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.
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.
-
- Posts: 21
- Joined: Mon Dec 21, 2015 9:30 am
Re: BLE Scan and obtain RSSI
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:
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
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.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
Re: BLE Scan and obtain RSSI
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 .
Once again, thanks for all your help & advice.
Best wishes,
Jordan
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 .
Once again, thanks for all your help & advice.
Best wishes,
Jordan
-
- Posts: 95
- Joined: Tue Feb 21, 2017 10:17 pm
Re: BLE Scan and obtain RSSI
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.
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.
Re: BLE Scan and obtain RSSI
Don't trust the RSSI values, it is mostly complete nonsense
Re: BLE Scan and obtain RSSI
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
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
-
- Posts: 95
- Joined: Tue Feb 21, 2017 10:17 pm
Re: BLE Scan and obtain RSSI
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?neilyoung wrote:Don't trust the RSSI values, it is mostly complete nonsense
Re: BLE Scan and obtain RSSI
https://github.com/espressif/esp-idf/is ... -287391770madscientist_42 wrote: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?neilyoung wrote:Don't trust the RSSI values, it is mostly complete nonsense
Who is online
Users browsing this forum: Bing [Bot] and 95 guests