How a BLE Server can get the RSSI of received packet from Central Device
Posted: Fri Oct 06, 2017 1:40 pm
Hello everyone!
I am working on my first BLE project and hope to me it through using the awesome ESP-32 module!
I based my work/experiments on the example code of UART implementation by pcbreflux, which can be found in this github.
The basic information I think is important is given below.
Server: ESP-32 module (Huzzah32 board from Adafruit)
Client: Android smartphone with nRF Connect and Toolbox apps
The project requires two characteristics as the UART example:
Excuse me for anything really stupid that you might just saw or for any useful information that I forgot to write.
Thank you!!
I am working on my first BLE project and hope to me it through using the awesome ESP-32 module!
I based my work/experiments on the example code of UART implementation by pcbreflux, which can be found in this github.
The basic information I think is important is given below.
Server: ESP-32 module (Huzzah32 board from Adafruit)
Client: Android smartphone with nRF Connect and Toolbox apps
The project requires two characteristics as the UART example:
- RX characteristic: here writes the Client and reads the Server
- TX characteristic: here writes the Server and reads the Client
Code: Select all
void char1_write_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
//ESP_LOGI(GATTS_TAG, "char1_write_handler %d\n", param->write.handle);
if (gl_char[0].char_val!=NULL) {
//ESP_LOGI(GATTS_TAG, "char1_write_handler char_val %d\n",param->write.len);
gl_char[0].char_val->attr_len = param->write.len;
for (uint32_t pos=0;pos<param->write.len;pos++) {
gl_char[0].char_val->attr_value[pos]=param->write.value[pos];
}
ESP_LOGI(TAG, "[CRYPTO_PS]char1_write_handler %.*s", gl_char[0].char_val->attr_len, (char*)gl_char[0].char_val->attr_value);
}
//ESP_LOGI(GATTS_TAG, "char1_write_handler esp_gatt_rsp_t\n");
notify_gatts_if = gatts_if;
notify_conn_id = param->write.conn_id;
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL);
if (strncmp((const char *)gl_char[0].char_val->attr_value,"LED ON",6)==0) {
gpio_set_level(LED_PIN,HIGH);
} else if (strncmp((const char *)gl_char[0].char_val->attr_value,"LED OFF",7)==0) {
gpio_set_level(LED_PIN,LOW);
} else if(strncmp((const char *)gl_char[0].char_val->attr_value,(const char *)private_Key,4)==0){
//Check RSSI for proximity
esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param;
printf("scan-RSSI: %d\n", p->scan_rst.rssi); //test #1 with data from scan_rst
printf("read-RSSI: %d\n", p->read_rssi_cmpl.rssi); //test #2 with data from read_rssi_cmpl
char2_notify_handle(gatts_if, param->write.conn_id);
}
}
Excuse me for anything really stupid that you might just saw or for any useful information that I forgot to write.
Thank you!!