Bluetooth SPP stops after ~150 bytes

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Bluetooth SPP stops after ~150 bytes

Postby kbaud1 » Tue Jul 16, 2019 5:26 pm

I am using the ESP32 to communicate with my Windows 10 PC via a Bluetooth classic SPP profile. This creates a com port in windows. I then wrote a simple program on the windows side that tests the connection through the serial port. However, after a 100 bytes or so, the connection freezes. I have to reboot the esp32 and try again to get more data through before it freezes again. It freezes at random points. So it does not appear to be a buffer problem?

The ESP32 code:

Code: Select all

#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include "nvs.h"
#include "nvs_flash.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_bt_device.h"
#include "esp_spp_api.h"

#define SPP_TAG "SPP_ACCEPTOR_DEMO"
#define SPP_SERVER_NAME "SPP_SERVER"
#define EXAMPLE_DEVICE_NAME "ESP_SPP_ACCEPTOR"

static const esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_CB;
static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE;
static const esp_spp_role_t role_slave = ESP_SPP_ROLE_SLAVE;

static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
    switch (event) {
    case ESP_SPP_INIT_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
        esp_bt_dev_set_device_name(EXAMPLE_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");
        break;
    case ESP_SPP_OPEN_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT");
        break;
    case ESP_SPP_CLOSE_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT");
        break;
    case ESP_SPP_START_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_START_EVT");
        break;
    case ESP_SPP_CL_INIT_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_CL_INIT_EVT");
        break;
    case ESP_SPP_DATA_IND_EVT:
    	ets_delay_us (50);
        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) {
            esp_spp_write(param->write.handle, (size_t)param->data_ind.len, (uint8_t *)param->data_ind.data);
        }
        else {
            esp_log_buffer_hex("",param->data_ind.data,param->data_ind.len);
        }
        break;
    case ESP_SPP_CONG_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_CONG_EVT");
        break;
    case ESP_SPP_WRITE_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_WRITE_EVT");
        break;
    case ESP_SPP_SRV_OPEN_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_SRV_OPEN_EVT");
        break;
    default:
        break;
    }
}

void app_main()
{
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );


    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    if (esp_bt_controller_init(&bt_cfg) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s initialize controller failed\n", __func__);
        return;
    }

    if (esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s enable controller failed\n", __func__);
        return;
    }

    if (esp_bluedroid_init() != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed\n", __func__);
        return;
    }

    if (esp_bluedroid_enable() != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s enable bluedroid failed\n", __func__);
        return;
    }

    if (esp_spp_register_callback(esp_spp_cb) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s spp register failed\n", __func__);
        return;
    }

    if (esp_spp_init(esp_spp_mode) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s spp init failed\n", __func__);
        return;
    }
}
The windows Code:

Code: Select all

#include <stdio.h>
#include <windows.h>

int main() {

    char buffer[1];
    HANDLE file;
    COMMTIMEOUTS timeouts;
    DWORD read, written;
    DCB port;
    char send[] = "s"; // char to send

    // open the comm port.
    file = CreateFile("\\\\.\\COM12",										// the slashes and period are only needed for com ports above 9
        GENERIC_READ | GENERIC_WRITE,
        0,
        NULL,
        OPEN_EXISTING,
        0,
        NULL);

    if (file == INVALID_HANDLE_VALUE)
    	printf("Error in opening serial port\n");
	else
		printf("opening serial port successful\n");

    // get the current DCB, and adjust
    memset(&port, 0, sizeof(port));
    port.DCBlength = sizeof(port);
    GetCommState(file, &port);
    BuildCommDCB("baud=9600 parity=n data=8 stop=1", &port);
    SetCommState(file, &port);

    // set short timeouts on the comm port.
    timeouts.ReadIntervalTimeout = 10;
    timeouts.ReadTotalTimeoutMultiplier = 10;
    timeouts.ReadTotalTimeoutConstant = 10;
    timeouts.WriteTotalTimeoutMultiplier = 10;
    timeouts.WriteTotalTimeoutConstant = 10;
    SetCommTimeouts(file, &timeouts);

    WriteFile(file, send, sizeof(send), &written, NULL);					// esp32 echoes only. this first character gets the process started.

    int frame = 200; int y = 0;
    while (frame)
    	{
    	ReadFile(file, buffer, sizeof(buffer), &read, NULL);

    	if (read)
    		{
    		printf("frame:%d", frame);
        	printf(" buffer:%c\n", buffer[0]);

    		WriteFile(file, send, sizeof(send), &written, NULL);
    		frame--; y = 0;
    		}
    	else y++;

    	if (y > 30)															// if after y attempts to read port with no data...
    		{
    		printf("could not communicate with port, exiting...\n");
    		frame = 0;
    		}
    	}

    CloseHandle(file);
}
A test result:

Code: Select all

opening serial port successful
frame:200 buffer:s
frame:199 buffer:
frame:198 buffer:s
frame:197 buffer:
frame:196 buffer:s
frame:195 buffer:
frame:194 buffer:s
frame:193 buffer:
frame:192 buffer:s
frame:191 buffer:
frame:190 buffer:s
frame:189 buffer:
frame:188 buffer:s
frame:187 buffer:
frame:186 buffer:s
frame:185 buffer:
frame:184 buffer:s
frame:183 buffer:
frame:182 buffer:s
frame:181 buffer:
frame:180 buffer:s
frame:179 buffer:
frame:178 buffer:s
frame:177 buffer:
frame:176 buffer:s
frame:175 buffer:
frame:174 buffer:s
frame:173 buffer:
frame:172 buffer:s
frame:171 buffer:
frame:170 buffer:s
frame:169 buffer:
frame:168 buffer:s
frame:167 buffer:
frame:166 buffer:s
frame:165 buffer:
frame:164 buffer:s
frame:163 buffer:
frame:162 buffer:s
frame:161 buffer:
frame:160 buffer:s
frame:159 buffer:
frame:158 buffer:s
frame:157 buffer:
frame:156 buffer:s
frame:155 buffer:
frame:154 buffer:s
frame:153 buffer:
frame:152 buffer:s
frame:151 buffer:
frame:150 buffer:s
frame:149 buffer:
frame:148 buffer:s
frame:147 buffer:
frame:146 buffer:s
frame:145 buffer:
frame:144 buffer:s
frame:143 buffer:
frame:142 buffer:s
frame:141 buffer:
frame:140 buffer:s
frame:139 buffer:
frame:138 buffer:s
frame:137 buffer:
frame:136 buffer:s
frame:135 buffer:
frame:134 buffer:s
frame:133 buffer:
frame:132 buffer:s
frame:131 buffer:
frame:130 buffer:s
frame:129 buffer:
frame:128 buffer:s
frame:127 buffer:
frame:126 buffer:s
frame:125 buffer:
frame:124 buffer:s
frame:123 buffer:
frame:122 buffer:s
frame:121 buffer:
frame:120 buffer:s
frame:119 buffer:
frame:118 buffer:s
frame:117 buffer:
frame:116 buffer:s
frame:115 buffer:
frame:114 buffer:s
frame:113 buffer:
frame:112 buffer:s
frame:111 buffer:
frame:110 buffer:s
frame:109 buffer:
frame:108 buffer:s
frame:107 buffer:
frame:106 buffer:s
frame:105 buffer:
frame:104 buffer:s
frame:103 buffer:
frame:102 buffer:s
frame:101 buffer:
frame:100 buffer:s
frame:99 buffer:
frame:98 buffer:s
frame:97 buffer:
frame:96 buffer:s
frame:95 buffer:
frame:94 buffer:s
frame:93 buffer:
frame:92 buffer:s
frame:91 buffer:
frame:90 buffer:s
frame:89 buffer:
frame:88 buffer:s
frame:87 buffer:
frame:86 buffer:s
frame:85 buffer:
frame:84 buffer:s
frame:83 buffer:
frame:82 buffer:s
frame:81 buffer:
frame:80 buffer:s
frame:79 buffer:
frame:78 buffer:s
frame:77 buffer:
frame:76 buffer:s
frame:75 buffer:
frame:74 buffer:s
frame:73 buffer:
frame:72 buffer:s
frame:71 buffer:
frame:70 buffer:s
frame:69 buffer:
frame:68 buffer:s
frame:67 buffer:
could not communicate with port, exiting...
"make monitor"

Code: Select all

I (31) boot: ESP-IDF v3.2.2-dirty 2nd stage bootloader
I (31) boot: compile time 18:02:48
I (31) boot: Enabling RNG early entropy source...
I (36) boot: SPI Speed      : 40MHz
I (40) boot: SPI Mode       : DIO
I (44) boot: SPI Flash Size : 4MB
I (48) boot: Partition Table:
I (51) boot: ## Label            Usage          Type ST Offset   Length
I (59) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (66) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (74) boot:  2 factory          factory app      00 00 00010000 00100000
I (81) boot: End of partition table
I (85) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x21c78 (138360) map
I (143) esp_image: segment 1: paddr=0x00031ca0 vaddr=0x3ffbdb60 size=0x028e4 ( 10468) load
I (147) esp_image: segment 2: paddr=0x0003458c vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at C:/msys32/home/Peter/esp/esp-idf/components/freertos/xtensa_vectors.S:1779

I (150) esp_image: segment 3: paddr=0x00034994 vaddr=0x40080400 size=0x0b67c ( 46716) load
I (178) esp_image: segment 4: paddr=0x00040018 vaddr=0x400d0018 size=0x7337c (471932) map
0x400d0018: _flash_cache_start at ??:?

I (343) esp_image: segment 5: paddr=0x000b339c vaddr=0x4008ba7c size=0x06bc4 ( 27588) load
0x4008ba7c: r_rwbtdm_isr_wrapper at intc.c:?

I (366) boot: Loaded app from partition at offset 0x10000
I (366) boot: Disabling RNG early entropy source...
I (366) cpu_start: Pro cpu up.
I (370) cpu_start: Starting app cpu, entry point is 0x4008101c
0x4008101c: call_start_cpu1 at C:/msys32/home/Peter/esp/esp-idf/components/esp32/cpu_start.c:246

I (0) cpu_start: App cpu up.
I (380) heap_init: Initializing. RAM available for dynamic allocation:
I (387) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (393) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (399) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (405) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (412) heap_init: At 3FFCCB78 len 00013488 (77 KiB): DRAM
I (418) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (424) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (430) heap_init: At 40092640 len 0000D9C0 (54 KiB): IRAM
I (437) cpu_start: Pro cpu start user code
I (7) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (54) BTDM_INIT: BT controller compile version [d53bd19]
I (54) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (134) phy: phy_version: 4008, 544f89f, Jan 24 2019, 14:54:06, 0, 0
I (464) SPP_ACCEPTOR_DEMO: ESP_SPP_INIT_EVT
I (464) SPP_ACCEPTOR_DEMO: ESP_SPP_START_EVT
W (10314) BT_APPL: new conn_srvc id:26, app_id:255
I (10314) SPP_ACCEPTOR_DEMO: ESP_SPP_SRV_OPEN_EVT
I (10344) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10354) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10354) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10354) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10364) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10364) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10394) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10394) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10394) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10404) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10404) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10414) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10414) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10424) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10424) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10434) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10444) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10444) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10454) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10464) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10464) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10474) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10494) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10494) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10504) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10504) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10514) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10514) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10524) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10524) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10534) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10534) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10544) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10554) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10554) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10564) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10574) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10574) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10584) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10594) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10594) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10604) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10614) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10614) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10624) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10634) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10644) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10644) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10654) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10684) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10684) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10684) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10684) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10694) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10694) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10704) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10704) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10714) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10714) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10724) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10724) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10734) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10744) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10744) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10754) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10764) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10764) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10774) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10784) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10784) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10794) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10804) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10804) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10814) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10824) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10824) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10834) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10844) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10844) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10854) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10854) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10864) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10874) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10874) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10884) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10894) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10894) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10904) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10914) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10914) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10924) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10934) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10944) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10944) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10954) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10954) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (10964) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10974) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10974) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (10984) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (11014) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11014) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11014) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11014) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (11024) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (11034) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11034) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11044) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11044) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11054) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11054) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11064) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11064) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11074) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11084) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11084) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11084) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11094) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11094) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11104) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11104) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11114) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11114) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11124) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11124) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11134) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11134) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11144) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11144) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (11154) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (11164) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (11164) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=2 handle=129
I (11174) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11184) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11184) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11194) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11194) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT
I (11204) SPP_ACCEPTOR_DEMO: ESP_SPP_WRITE_EVT

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Re: Bluetooth SPP stops after ~150 bytes

Postby kbaud1 » Tue Jul 23, 2019 6:24 pm

I also tried this on multiple devices with the same result so it is not a unit problem.

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Re: Bluetooth SPP stops after ~150 bytes

Postby kbaud1 » Fri Jul 26, 2019 5:01 pm

I found it. needed a 1ms delay after the tx on the windows side. Now I am getting 2k bytes through with no crashes. baud rate with 25 bytes per send is about 9600baud. Here's the working program on the windows side (esp32 side is unchanged from above):

Code: Select all

#include <stdio.h>
#include <windows.h>
#include <time.h>

int main() {

    HANDLE file;
    COMMTIMEOUTS timeouts;
    DWORD read, written;
    DCB port;
    char send[] = "srtdeweefr1234567890"; 									// chars to send
    char buffer[sizeof (send)];

    // open the comm port.
    file = CreateFile("\\\\.\\COM14",										// the slashes and period are only needed for com ports above 9
        GENERIC_READ | GENERIC_WRITE,
        0,
        NULL,
        OPEN_EXISTING,
        0,
        NULL);

    if (file == INVALID_HANDLE_VALUE)
    	printf("Error in opening serial port\n");
	else
		printf("opening serial port successful\n");

    // get the current DCB, and adjust
    memset(&port, 0, sizeof(port));
    port.DCBlength = sizeof(port);
    GetCommState(file, &port);
    BuildCommDCB("baud=115200 parity=n data=8 stop=1", &port);
    SetCommState(file, &port);

    // set short timeouts on the comm port.
    timeouts.ReadIntervalTimeout = 10;
    timeouts.ReadTotalTimeoutMultiplier = 10;
    timeouts.ReadTotalTimeoutConstant = 10;
    timeouts.WriteTotalTimeoutMultiplier = 10;
    timeouts.WriteTotalTimeoutConstant = 10;
    SetCommTimeouts(file, &timeouts);

    time_t start = time(0);
    WriteFile(file, send, sizeof(send), &written, NULL);					// esp32 echoes only. this first send gets the process started.

    int frame; int y = 0; int limit = 2000;
    while (frame != limit + 1)
    	{
    	ReadFile(file, buffer, sizeof(buffer), &read, NULL);

    	if (read)
    		{
    		printf("frame:%d", frame);
        	printf(" buffer:%s\n", buffer);

    		WriteFile(file, send, sizeof(send), &written, NULL);
    		frame++; y = 0;
    		Sleep(1);
    		}
    	else y++;

    	if (y > 30)															// if after y attempts to read port with no data...
    		{
    		printf("could not communicate with port, exiting...\n");
    		frame = limit+1;
    		}
    	}

    time_t end = time(0);
    int runtime = end - start;
    printf("%d seconds\n", runtime);
    int speed = (frame * sizeof(send)) / runtime;							 // calculate throughput
    printf("%d bytes/sec\n", speed);

    CloseHandle(file);
}

Nikonov_94
Posts: 5
Joined: Fri Jul 26, 2019 6:20 pm

Re: Bluetooth SPP stops after ~150 bytes

Postby Nikonov_94 » Sun Jul 28, 2019 8:46 am

Thanks for explaining how you got out of that problem, I ran into the same issue and remained stuck until I applied your method. I hope I won't need that forum too often, but with my newbieness, I guess I'll come around a lot :lol:

Who is online

Users browsing this forum: No registered users and 86 guests