ESP32 Bluetooth SPP with bidirectional communication (send and receive)
Posted: Fri Apr 06, 2018 10:40 am
Hi,
I need that ESP can send and receive data over SPP while connected to Android smartphone (let say, using any spp terminal I need to receive and send commands).
In IDF examples there are 2 examples for acceptor and initiator. I have checked acceptor and it works fine. Only one thing - it working only in one directional Android -> ESP.
Is it possible to make comunication bidirectional?
I'm looking over code in both acceptor and initiator and I'm not sure is it even possible, as I see at one example ESP is slave and in another master.
There are essential difference in callbacks for processing SPP events:
acceptor:
initiator
And which role should be Android smartphone in case bidirectional communication with ESP?
Please advice, maybe there are some ready robust solutions for bidirectional communication over SPP?
I need that ESP can send and receive data over SPP while connected to Android smartphone (let say, using any spp terminal I need to receive and send commands).
In IDF examples there are 2 examples for acceptor and initiator. I have checked acceptor and it works fine. Only one thing - it working only in one directional Android -> ESP.
Is it possible to make comunication bidirectional?
I'm looking over code in both acceptor and initiator and I'm not sure is it even possible, as I see at one example ESP is slave and in another master.
There are essential difference in callbacks for processing SPP events:
acceptor:
Code: Select all
static const esp_spp_role_t role_slave = ESP_SPP_ROLE_SLAVE;
// . . .
case ESP_SPP_INIT_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
break;
case ESP_SPP_DISCOVERY_COMP_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_DISCOVERY_COMP_EVT");
// do nothing!!!
break;
case ESP_SPP_OPEN_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT");
// do nothing!!!
break;
Code: Select all
static const esp_spp_role_t role_master = ESP_SPP_ROLE_MASTER;
// . . .
case ESP_SPP_INIT_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
break;
case ESP_SPP_DISCOVERY_COMP_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_DISCOVERY_COMP_EVT status=%d scn_num=%d",param->disc_comp.status, param->disc_comp.scn_num);
if (param->disc_comp.status == ESP_SPP_SUCCESS) {
esp_spp_connect(sec_mask, role_master, param->disc_comp.scn[0], peer_bd_addr);
}
break;
case ESP_SPP_OPEN_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT");
esp_spp_write(param->srv_open.handle, SPP_DATA_LEN, spp_data);
gettimeofday(&time_old, NULL);
break;
Please advice, maybe there are some ready robust solutions for bidirectional communication over SPP?