I'm trying to do something very similar to this post (https://esp32.com/viewtopic.php?t=5499), and likely experiencing a similar problem, but I just can't seem to get around it.
I'm trying to use the esp_spp_write() function to send data received from UART_NUM_1. I've essentially pulled together the code from the "bt_spp_acceptor" and "uart_echo" examples. I've used xTaskCreate to create a task that runs whenever data is received on the uart,
- xTaskCreate(uart_rx_task, "my_uart_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL);
- static void uart_rx_task() {
- ...
- while (1) {
- const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 10 / portTICK_RATE_MS);
- if (rxBytes > 0) {
- data[rxBytes] = 0;
- if (spp_param->write.cong == 0) {
- #define RX_STRING_LEN 10
- uint8_t RX_STRING[RX_STRING_LEN] = "CHAR RXED";
- esp_spp_write(sppSendHandle, RX_STRING_LEN, RX_STRING);
- }
- }
- }
- free(data);
- }
I should mention that I'm setting the send handle for the bluetooth "sppSendHandle" in the esp_spp_cb() callback function when the "ESP_SPP_SRV_OPEN_EVT" occurs.
- static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
- {
- switch (event) {
- ...
- case ESP_SPP_SRV_OPEN_EVT:
- sppSendHandle = param->srv_open.handle;
- break;
- ...
- }
- }
- static void periodic_timer_callback(void* arg) {
- #define TEST_STRING_LEN 5
- uint8_t TEST_STRING[TEST_STRING_LEN] = "TEST";
- esp_spp_write(sppSendHandle, TEST_STRING_LEN, TEST_STRING);
- }