I am sending data over SPP classic bluetooth between esp32 and androïd phone. The ESP32 send 500 bytes every 100ms. My problem is that I am entering in congestion after few minutes and the bluetooth communication fails after that. The problem is the same with multiple android supports (tablet or phone).
Thanks for your help.
My code for init the bluetooth :
Code: Select all
void btc::_initBt()
{
// init nvs flash
if (nvs_flash_init() == ESP_ERR_NVS_NO_FREE_PAGES) {
nvs_flash_erase();
nvs_flash_init();
}
// initialize controller stack (low level)
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
esp_bt_controller_init(&bt_cfg);
esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT);
esp_bredr_tx_power_set(ESP_PWR_LVL_N2, ESP_PWR_LVL_P1);
}
// init bluedroid host stack (high level)
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
esp_bluedroid_init();
esp_bluedroid_enable();
}
// register callback btc event
esp_spp_register_callback(_static_esp_spp_cb);
esp_spp_init(ESP_SPP_MODE_CB);
}
void btc::_static_esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
esp_spp_cb_event_t ev = event;
switch (event) {
case ESP_SPP_INIT_EVT:
// set scan mode
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
esp_bt_dev_set_device_name("ESP_BT");
esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, "SPP_SERVER");
break;
case ESP_SPP_START_EVT:
break;
case ESP_SPP_WRITE_EVT:
break;
case ESP_SPP_SRV_OPEN_EVT:
g_btc->_connected(param->srv_open.handle);
break;
case ESP_SPP_DISCOVERY_COMP_EVT:
break;
case ESP_SPP_OPEN_EVT:
break;
case ESP_SPP_CLOSE_EVT:
g_btc->_disconnected();
break;
case ESP_SPP_CL_INIT_EVT:
break;
case ESP_SPP_DATA_IND_EVT:
break;
case ESP_SPP_CONG_EVT: // CONGESTION
if (param->cong.cong == true) {
g_btc->m_bCongest = true;
}
else {
g_btc->m_bCongest = false;
}
break;
default:
break;
}
}