ESP32 Bluetooth SPP with bidirectional communication (send and receive)

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32 Bluetooth SPP with bidirectional communication (send and receive)

Postby chegewara » Mon Nov 18, 2019 10:08 am

If you are flashing this code, i am guessing it is just echoing received data:

Code: Select all

    case ESP_SPP_DATA_IND_EVT:
#if (SPP_SHOW_MODE == SPP_SHOW_DATA)
        ESP_LOGI(SPP_TAG, "ESP_SPP_DATA_IND_EVT len=%d handle=%d",
                 param->data_ind.len, param->data_ind.handle);
        if (param->data_ind.len < 1023) {
            snprintf(buf, (size_t)param->data_ind.len, (char *)param->data_ind.data);
            printf("%s\n", buf);
            sprintf(spp_data, "Receined characters: %d\n", param->data_ind.len);
            esp_spp_write(param->write.handle, strlen(spp_data), (uint8_t *)spp_data);
        }
        
https://docs.espressif.com/projects/esp ... TA_IND_EVT

kluverp
Posts: 26
Joined: Mon Jun 18, 2018 7:08 am

Re: ESP32 Bluetooth SPP with bidirectional communication (send and receive)

Postby kluverp » Tue Nov 19, 2019 5:40 am

chegewara wrote:
Mon Nov 18, 2019 10:08 am
If you are flashing this code, i am guessing it is just echoing received data:

Code: Select all

    case ESP_SPP_DATA_IND_EVT:
#if (SPP_SHOW_MODE == SPP_SHOW_DATA)
        ESP_LOGI(SPP_TAG, "ESP_SPP_DATA_IND_EVT len=%d handle=%d",
                 param->data_ind.len, param->data_ind.handle);
        if (param->data_ind.len < 1023) {
            snprintf(buf, (size_t)param->data_ind.len, (char *)param->data_ind.data);
            printf("%s\n", buf);
            sprintf(spp_data, "Receined characters: %d\n", param->data_ind.len);
            esp_spp_write(param->write.handle, strlen(spp_data), (uint8_t *)spp_data);
        }
     
https://docs.espressif.com/projects/esp ... TA_IND_EVT

Yes it it is echoing.
But I would expect on calling "esp_spp_write()" that it does not fire the "ESP_SPP_DATA_IND_EVT" event next to the ESP_SPP_WRITE_EVT" event (it does get called once). But only the "ESP_SPP_WRITE_EVT" event.
Do it echos to itself as well.

When I call:

Code: Select all

                char *spp_data = "Hello!";
    		esp_spp_write(myHandle, strlen(spp_data), (uint8_t *)spp_data);
It fires the "ESP_SPP_DATA_IND_EVT" event like so:

Code: Select all

I (278949) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=1 handle=129
H
I (278949) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=1 handle=129
a
I (278959) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=1 handle=129
l
I (278959) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=1 handle=129
l
I (278969) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=1 handle=129
o
I (278979) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=1 handle=129
!

I did not expect that, nor do I understand why.

senudajayalath
Posts: 17
Joined: Sun Jan 03, 2021 8:00 am

Re: ESP32 Bluetooth SPP with bidirectional communication (send and receive)

Postby senudajayalath » Wed Mar 02, 2022 8:47 am

loboris wrote:
Fri Apr 06, 2018 1:11 pm
You just have to combine receiving and sending, like in this simple example based on example_spp_acceptor_demo.c
I have a few questions on this. Where can I find this `example_spp_acceptor_demo.c` file.
The other question is if I pasted the code you have given to the `main.c` file of `BT_SPP_ACCEPTOR` it did not work. Am I missing something here?

Thanks in advance

Who is online

Users browsing this forum: shraiwi and 78 guests