device address ble eddystone tlm

yemred
Posts: 7
Joined: Tue Nov 16, 2021 6:37 am

device address ble eddystone tlm

Postby yemred » Thu Dec 02, 2021 12:37 pm

Hello, i am using exactly same example of ble eddystone. there is a function

Code: Select all

esp_log_buffer_hex("EDDYSTONE_DEMO: Device address:", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
for printing device address but i want to assign device address to a variable. are there any one else who can show me the way. because i tried lots of ways.
this function doesnt works for me,

Code: Select all

esp_bt_dev_get_address(void)
there must be an other way to get it.
thanks a lot for reading

yemred
Posts: 7
Joined: Tue Nov 16, 2021 6:37 am

Re: device address ble eddystone tlm

Postby yemred » Fri Dec 03, 2021 6:01 am

i wanna ansver my own question instead of admins (:

if you wanna get all advertised data in hex combination then code is this

Code: Select all

uint8_t adv_data_len  = scan_result->scan_rst.adv_data_len;
uint8_t *adv_data     = scan_result->scan_rst.ble_adv;
for(int i = 0; i < ESP_BD_ADDR_LEN; ++i){
    printf("%02X ", adv_addr[i]);
}
if you wanna get advertiser device address then code is this

Code: Select all

uint8_t *adv_addr     = scan_result->scan_rst.bda;
for(int i = 0; i < ESP_BD_ADDR_LEN; ++i){     //ESP_BD_ADDR_LEN = 6 and given by example ble_eddystone
    printf("%02X ", adv_addr[i]);
}
all code where to placed is this

Code: Select all

//esp_eddystone_demo.c
case ESP_GAP_SEARCH_INQ_RES_EVT: {
                    
                    esp_eddystone_result_t eddystone_res;
                    memset(&eddystone_res, 0, sizeof(eddystone_res));
                    esp_err_t ret = esp_eddystone_decode(scan_result->scan_rst.ble_adv, scan_result->scan_rst.adv_data_len, &eddystone_res);
                    if (ret) {
                        // error:The received data is not an eddystone frame packet or a correct eddystone frame packet.
                        // just return
                        return;
                    } else {
                        // The received adv data is a correct eddystone frame packet.
                        // Here, we get the eddystone infomation in eddystone_res, we can use the data in res to do other things.
                        // For example, just print them:
                        ESP_LOGI(TAG, "--------Eddystone Found----------");
                        //esp_log_buffer_hex("EDDYSTONE_DEMO: Device address", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
                        
                        uint8_t adv_data_len  = scan_result->scan_rst.adv_data_len;
                        uint8_t *adv_data     = scan_result->scan_rst.ble_adv;
                        for(int i = 0; i < adv_data_len; ++i){
                            printf("%02X ", adv_data[i]);
                        }
                        uint8_t *adv_addr     = scan_result->scan_rst.bda;
                        for(int i = 0; i < ESP_BD_ADDR_LEN; ++i){
                            printf("%02X ", adv_addr[i]);
                        }
                        
                        ESP_LOGI(TAG, "RSSI of packet:%d dbm", scan_result->scan_rst.rssi);
                        esp_eddystone_show_inform(&eddystone_res);
                    }
                    break;
                }
i love you all who read my post.

User avatar
666hjk
Posts: 47
Joined: Wed Jan 12, 2022 3:09 am
Location: 小红点

Re: device address ble eddystone tlm

Postby 666hjk » Tue Nov 08, 2022 2:55 am

yemred wrote:
Fri Dec 03, 2021 6:01 am
i wanna ansver my own question instead of admins (:

if you wanna get all advertised data in hex combination then code is this

Code: Select all

uint8_t adv_data_len  = scan_result->scan_rst.adv_data_len;
uint8_t *adv_data     = scan_result->scan_rst.ble_adv;
for(int i = 0; i < ESP_BD_ADDR_LEN; ++i){
    printf("%02X ", adv_addr[i]);
}
if you wanna get advertiser device address then code is this

Code: Select all

uint8_t *adv_addr     = scan_result->scan_rst.bda;
for(int i = 0; i < ESP_BD_ADDR_LEN; ++i){     //ESP_BD_ADDR_LEN = 6 and given by example ble_eddystone
    printf("%02X ", adv_addr[i]);
}
all code where to placed is this

Code: Select all

//esp_eddystone_demo.c
case ESP_GAP_SEARCH_INQ_RES_EVT: {
                    
                    esp_eddystone_result_t eddystone_res;
                    memset(&eddystone_res, 0, sizeof(eddystone_res));
                    esp_err_t ret = esp_eddystone_decode(scan_result->scan_rst.ble_adv, scan_result->scan_rst.adv_data_len, &eddystone_res);
                    if (ret) {
                        // error:The received data is not an eddystone frame packet or a correct eddystone frame packet.
                        // just return
                        return;
                    } else {
                        // The received adv data is a correct eddystone frame packet.
                        // Here, we get the eddystone infomation in eddystone_res, we can use the data in res to do other things.
                        // For example, just print them:
                        ESP_LOGI(TAG, "--------Eddystone Found----------");
                        //esp_log_buffer_hex("EDDYSTONE_DEMO: Device address", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
                        
                        uint8_t adv_data_len  = scan_result->scan_rst.adv_data_len;
                        uint8_t *adv_data     = scan_result->scan_rst.ble_adv;
                        for(int i = 0; i < adv_data_len; ++i){
                            printf("%02X ", adv_data[i]);
                        }
                        uint8_t *adv_addr     = scan_result->scan_rst.bda;
                        for(int i = 0; i < ESP_BD_ADDR_LEN; ++i){
                            printf("%02X ", adv_addr[i]);
                        }
                        
                        ESP_LOGI(TAG, "RSSI of packet:%d dbm", scan_result->scan_rst.rssi);
                        esp_eddystone_show_inform(&eddystone_res);
                    }
                    break;
                }
i love you all who read my post.


thanks for sharing this, and enhancing my understanding. :)
学习中找战友。

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 122 guests