ESP32 Bluetooth SPP with bidirectional communication (send and receive)

chegewara
Posts: 1174
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: 24
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.

Who is online

Users browsing this forum: No registered users and 48 guests