Error: GetOverlappedResult failed (PermissionError(13,...

TomasCZ
Posts: 39
Joined: Tue Apr 25, 2023 5:19 am

Error: GetOverlappedResult failed (PermissionError(13,...

Postby TomasCZ » Fri Dec 08, 2023 10:26 pm

HI guys, I have a broblem with code for getting MAC address of WiFi and BT of ESP32 board:

The terminal shows the following:

Code: Select all

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6940
ho 0 tail 12 room 4
load:0x40078000,len:15500
load:0x40080400,len:3844
0x40080400: _init at ??:?

entry 0x4008064c
I (29) boot: ESP-IDF v5.0.2 2nd stage bootloader
I (29) boot: compile time 23:08:38
I (29) boot: chip revision: v3.0
I (32) boot.esp32: SPI Speed      : 40MHz
I (37) boot.esp32: SPI Mode       : DIO
I (41) boot.esp32: SPI Flash Size : 2MB
I (46) boot: Enabling RNG early entropy source...
I (51) boot: Partition Table:
I (55) boot: ## Label            Usage          Type ST Offset   Length
I (62) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (70) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (77) boot:  2 factory          factory app      00 00 00010000 00177000
I (85) boot: End of partition table
I (89) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=38b40h (232256) map
I (181) esp_image: segment 1: paddr=00048b68 vaddr=3ffbdb60 size=0504ch ( 20556) load
I (189) esp_image: segment 2: paddr=0004dbbc vaddr=40080000 size=0245ch (  9308) load
I (193) esp_image: segment 3: paddr=00050020 vaddr=400d0020 size=e6b64h (944996) map
I (537) esp_image: segment 4: paddr=00136b8c vaddr=4008245c size=1c06ch (114796) load
I (599) boot: Loaded app from partition at offset 0x10000
I (599) boot: Disabling RNG early entropy source...
I (611) cpu_start: Pro cpu up.
I (611) cpu_start: Starting app cpu, entry point is 0x40081414
0x40081414: call_start_cpu1 at C:/Users/konec/esp/esp-idf/components/esp_system/port/cpu_start.c:141

I (597) cpu_start: App cpu up.
I (628) cpu_start: Pro cpu start user code
I (628) cpu_start: cpu freq: 160000000 Hz
I (628) cpu_start: Application information:
I (632) cpu_start: Project name:     ESP32_BT_WIFI_MAC_ADD
I (639) cpu_start: App version:      1
I (643) cpu_start: Compile time:     Dec  8 2023 23:10:43
I (649) cpu_start: ELF file SHA256:  2fec272580b93529...
I (655) cpu_start: ESP-IDF:          v5.0.2
I (660) cpu_start: Min chip rev:     v0.0
I (665) cpu_start: Max chip rev:     v3.99
I (669) cpu_start: Chip rev:         v3.0
I (674) heap_init: Initializing. RAM available for dynamic allocation:
I (682) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (687) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (693) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (700) heap_init: At 3FFCD4A0 len 00012B60 (74 KiB): DRAM
I (706) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (712) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (719) heap_init: At 4009E4C8 len 00001B38 (6 KiB): IRAM
I (726) spi_flash: detected chip: generic
I (729) spi_flash: flash io: dio
W (733) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (748) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (798) MAIN: Value of ret: 0
I (808) wifi:wifi driver task: 3ffbd854, prio:23, stack:6656, core=0
I (808) system_api: Base MAC address is not set
I (808) system_api: read default base MAC address from EFUSE
I (818) wifi:wifi firmware version: 57982fe
I (818) wifi:wifi certification version: v7.0
I (818) wifi:config NVS flash: enabled
I (818) wifi:config nano formating: disabled
I (828) wifi:Init data frame dynamic rx buffer num: 32
I (828) wifi:Init management frame dynamic rx buffer num: 32
I (838) wifi:Init management short buffer num: 32
I (838) wifi:Init dynamic tx buffer num: 32
I (848) wifi:Init static rx buffer size: 1600
I (848) wifi:Init static rx buffer num: 10
I (848) wifi:Init dynamic rx buffer num: 32
I (858) wifi_init: rx ba win: 6
I (858) wifi_init: tcpip mbox: 32
I (868) wifi_init: udp mbox: 6
I (868) wifi_init: tcp mbox: 6
I (868) wifi_init: tcp tx win: 5744
I (878) wifi_init: tcp rx win: 5744
I (878) wifi_init: tcp mss: 1440
I (888) wifi_init: WiFi IRAM OP enabled
I (888) wifi_init: WiFi RX IRAM OP enabled
I (888) MAIN: Value of ret: 0
I (898) BTDM_INIT: BT controller compile version [2c56073]
ESP_ERROR_CHECK failed: esp_err_t 0x102 (ESP_ERR_INVALID_ARG) at 0x400d854a
0x400d854a: app_main at C:/Users/konec/ESP-IDF/ESP32_BT_WIFI_MAC_ADD/main/main.c:38 (discriminator 1)

file: "./main/main.c" line 38
func: app_main
expression: ret

abort() was called at PC 0x40091c67 on core 0
0x40091c67: _esp_error_check_failed at C:/Users/konec/esp/esp-idf/components/esp_system/esp_err.c:47



Backtrace: 0x40081f1a:0x3ffbba30 0x40091c71:0x3ffbba50 0x4009855e:0x3ffbba70 0x40091c67:0x3ffbbae0 0x400d854a:0x3ffbbb10 0x401b4e7b:0x3ffbbc50 0x40094e01:0x3ffbbc80
0x40081f1a: panic_abort at C:/Users/konec/esp/esp-idf/components/esp_system/panic.c:423

0x40091c71: esp_system_abort at C:/Users/konec/esp/esp-idf/components/esp_system/esp_system.c:153

0x4009855e: abort at C:/Users/konec/esp/esp-idf/components/newlib/abort.c:38

0x40091c67: _esp_error_check_failed at C:/Users/konec/esp/esp-idf/components/esp_system/esp_err.c:47

0x400d854a: app_main at C:/Users/konec/ESP-IDF/ESP32_BT_WIFI_MAC_ADD/main/main.c:38 (discriminator 1)

GetOverlappedResult failed (PermissionError(13, 'P????stup byl odep??en0x4.0'1,b 4Neo7nbe:,  m5a)i)n_t
asWka at C:/itiUnsge frosr/ kotnheec/ edsepv/icee stpo- idrfeconne/ctcomponents/freertos/FreeRTOS-Kernel/portable/port_common.c:131 (discriminator 2)

0x40094e01: vPortTaskWrapper at C:/Users/konec/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154





ELF file SHA256: 2fec272580b93529

Rebooting...
The looks like this:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "esp_gap_bt_api.h"
#include "string.h"

void app_main()
{
    // Inicializace NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);
    ESP_LOGI("MAIN", "Value of ret: %d", ret);

    // Inicializace WiFi
    esp_netif_init();
    esp_event_loop_create_default();
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ret = esp_wifi_init(&cfg);
    ESP_ERROR_CHECK(ret);
    ESP_LOGI("MAIN", "Value of ret: %d", ret);

    // Inicializace Bluetooth
    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ret = esp_bt_controller_init(&bt_cfg);
    ESP_ERROR_CHECK(ret);
    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
    ESP_ERROR_CHECK(ret);
    ESP_LOGI("MAIN", "Value of ret: %d", ret);

    // Získání MAC adresy WiFi rozhraní
    uint8_t wifi_mac[6];
    ret = esp_wifi_get_mac(ESP_IF_WIFI_STA, wifi_mac);
    ESP_ERROR_CHECK(ret);
    ESP_LOGI("MAIN", "Value of ret: %d", ret);

    // Výpis MAC adresy WiFi na konzoli
    ESP_LOGI("MAC", "WiFi MAC adresa: %02x:%02x:%02x:%02x:%02x:%02x",
             wifi_mac[0], wifi_mac[1], wifi_mac[2], wifi_mac[3], wifi_mac[4], wifi_mac[5]);

    // Získání MAC adresy Bluetooth
    uint8_t bt_mac[6];
    const uint8_t *bt_addr = esp_bt_dev_get_address();
    memcpy(bt_mac, bt_addr, 6);

    // Výpis MAC adresy Bluetooth na konzoli
    ESP_LOGI("MAC", "Bluetooth MAC adresa: %02x:%02x:%02x:%02x:%02x:%02x",
             bt_mac[0], bt_mac[1], bt_mac[2], bt_mac[3], bt_mac[4], bt_mac[5]);
}

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby MicroController » Fri Dec 08, 2023 11:46 pm

Apparently, if you want to esp_bt_controller_enable(ESP_BT_MODE_BTDM) you also have to esp_bt_controller_init(...) before with the same bt_cfg.mode; although this example doesn't do it either...

TomasCZ
Posts: 39
Joined: Tue Apr 25, 2023 5:19 am

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby TomasCZ » Sat Dec 09, 2023 1:15 pm

Hi Guys, I have this code for getting MAC address of BT. FInally I am able to compile it and Flash. But when I run do code I got an error. Pls, see below.

My code:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_bt.h"
#include "esp_log.h"
#include "esp_bt_device.h"

void app_main()
{
    esp_err_t ret;

    // Inicializace konfigurace BT controlleru
    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ret = esp_bt_controller_init(&bt_cfg);
    if (ret != ESP_OK) {
        ESP_LOGE("BT", "Inicializace BT selhala: %s", esp_err_to_name(ret));
        return;
    }
    else
    {
        ESP_LOGE("BT", "Inicializace BT OK !: %s", esp_err_to_name(ret));
    }

    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
    if (ret != ESP_OK) {
        ESP_LOGE("BT", "Nepodařilo se zapnout BT controller: %s", esp_err_to_name(ret));
        return;
    }

    // Získání MAC adresy BT rozhraní
    const uint8_t *bt_mac = esp_bt_dev_get_address();
    if (bt_mac == NULL) {
        ESP_LOGE("BT", "Nepodařilo se získat MAC adresu BT rozhraní");
        return;
    }

    ESP_LOGI("BT", "MAC adresa BT rozhraní: %02x:%02x:%02x:%02x:%02x:%02x",
             bt_mac[0], bt_mac[1], bt_mac[2], bt_mac[3], bt_mac[4], bt_mac[5]);
}
This is the full terminal message:

Code: Select all

PS C:\Users\konec\ESP-IDF\ESP32_BT_GET_MAC_ADDRESS> set IDF_PATH=C:\Users\konec\esp\esp-idf
PS C:\Users\konec\ESP-IDF\ESP32_BT_GET_MAC_ADDRESS> c:\Espressif\python_env\idf5.0_py3.8_env\Scripts\python.exe C:\Users\konec\esp\esp-idf\tools\idf_monitor.py -p COM11 -b 115200 --toolchain-prefix xtensa-esp32-elf- --target esp32 c:\Users\konec\ESP-IDF\ESP32_BT_GET_MAC_ADDRESS\build\ESP32_BT_GET_MAC_ADDRESS.elf
--- WARNING: GDB cannot open serial ports accessed as COMx
--- Using \\.\COM11 instead...
--- idf_monitor on \\.\COM11 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6940
ho 0 tail 12 room 4
load:0x40078000,len:15500
load:0x40080400,len:3844
0x40080400: _init at ??:?

entry 0x4008064c
I (29) boot: ESP-IDF v5.0.2 2nd stage bootloader
I (29) boot: compile time 13:57:32
I (29) boot: chip revision: v3.0
I (32) boot.esp32: SPI Speed      : 40MHz
I (37) boot.esp32: SPI Mode       : DIO
I (41) boot.esp32: SPI Flash Size : 2MB
I (46) boot: Enabling RNG early entropy source...
I (51) boot: Partition Table:
I (55) boot: ## Label            Usage          Type ST Offset   Length
I (62) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (70) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (77) boot:  2 factory          factory app      00 00 00010000 00100000
I (85) boot: End of partition table
I (89) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=25ac0h (154304) map
I (153) esp_image: segment 1: paddr=00035ae8 vaddr=3ffbdb60 size=041a4h ( 16804) load
I (160) esp_image: segment 2: paddr=00039c94 vaddr=40080000 size=06384h ( 25476) load
I (171) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=94514h (607508) map
I (390) esp_image: segment 4: paddr=000d453c vaddr=40086384 size=11f2ch ( 73516) load
I (433) boot: Loaded app from partition at offset 0x10000
I (433) boot: Disabling RNG early entropy source...
I (445) cpu_start: Pro cpu up.
I (445) cpu_start: Starting app cpu, entry point is 0x40081328
0x40081328: call_start_cpu1 at C:/Users/konec/esp/esp-idf/components/esp_system/port/cpu_start.c:141

I (0) cpu_start: App cpu up.
I (461) cpu_start: Pro cpu start user code
I (461) cpu_start: cpu freq: 160000000 Hz
I (461) cpu_start: Application information:
I (466) cpu_start: Project name:     ESP32_BT_GET_MAC_ADDRESS
I (472) cpu_start: App version:      1
I (477) cpu_start: Compile time:     Dec  9 2023 13:57:04
I (483) cpu_start: ELF file SHA256:  d2faacdcf6aaa1a1...
I (489) cpu_start: ESP-IDF:          v5.0.2
I (494) cpu_start: Min chip rev:     v0.0
I (498) cpu_start: Max chip rev:     v3.99
I (503) cpu_start: Chip rev:         v3.0
I (508) heap_init: Initializing. RAM available for dynamic allocation:
I (515) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (521) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (527) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (533) heap_init: At 3FFC9610 len 000169F0 (90 KiB): DRAM
I (540) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (546) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (552) heap_init: At 400982B0 len 00007D50 (31 KiB): IRAM
I (560) spi_flash: detected chip: generic
I (563) spi_flash: flash io: dio
W (567) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (582) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (591) BTDM_INIT: BT controller compile version [2c56073]
I (601) system_api: Base MAC address is not set
I (601) system_api: read default base MAC address from EFUSE
E (611) BT: Inicializace BT OK !: ESP_OK
E (611) BT: Nepodařilo se zapnout BT controller: ESP_ERR_INVALID_ARG
The last two lines say:
BT: Inicialisation was OK !
BT: Unable to turn on BT controller: ESP_ERR_INVALID_ARG

An idea what could be wrong ?

If I check the documentation for ESP_ERR_INVALID_ARG I can only find:
ESP_ERR_INVALID_ARG
Invalid argument

Thank you for any help.

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby MicroController » Sat Dec 09, 2023 1:47 pm

TomasCZ wrote:
Sat Dec 09, 2023 1:15 pm
An idea what could be wrong ?
Yes.

TomasCZ
Posts: 39
Joined: Tue Apr 25, 2023 5:19 am

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby TomasCZ » Sat Dec 09, 2023 6:40 pm

Thank you and can I ask you for help, please ?

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby MicroController » Sat Dec 09, 2023 8:16 pm

Did you try this?

TomasCZ
Posts: 39
Joined: Tue Apr 25, 2023 5:19 am

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby TomasCZ » Sun Dec 10, 2023 7:10 am

Maybe now I get what you mean in your post above. The init should be in the same mode as the enable ?

In other words this row is not correct ?
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby MicroController » Sun Dec 10, 2023 9:13 am

Try this:

Code: Select all

esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
bt_cfg.mode = ESP_BT_MODE_BTDM;

TomasCZ
Posts: 39
Joined: Tue Apr 25, 2023 5:19 am

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby TomasCZ » Sun Dec 10, 2023 9:26 am

Thank you for showing me the way. I checked some other discussions here and on github and was able to get working code. For the init and enable works:

Code: Select all

// Initialization of Bluetooth controller configuration
    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ESP_LOGI("BT", "Call esp_bt_controller_init(&bt_cfg)");
    if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
        ESP_LOGE("BT", "%s initialize controller FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI("BT", "Initialize controller OK");
    }
   
    // Enable Bluetooth controller in CLASSIC Bluetooth mode
    ESP_LOGI("BT", "Call esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)");
    if ((ret = esp_bt_controller_enable(CONFIG_BT_CLASSIC_ENABLED)) != ESP_OK) {
        ESP_LOGE("BT", "%s enable controller FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI("BT", "Enable controller OK");
    }
Also the rest of the code works now so I am able to get the MAC address of BT now.

TomasCZ
Posts: 39
Joined: Tue Apr 25, 2023 5:19 am

Re: Error: GetOverlappedResult failed (PermissionError(13,...

Postby TomasCZ » Sun Dec 10, 2023 7:14 pm

I continue with trying to understand how it works therefore I used the code and step by step I made the BT module visible for my android phone. Now I tryid to start the server but getting an erro while building the project.

The error is:

Code: Select all

[1/9] Performing build step for 'bootloader'
[1/1] cmd.exe /C "cd /D C:\Users\konec\ESP-IDF\BT_ACC_TEST_CODE\build\bootloader\esp-idf\esptool_py && c:\Espressif\python_env\idf5.0_py3.8_env\Scripts\python.exe C:/Users/konec/esp/esp-idf/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x1000 C:/Users/konec/ESP-IDF/BT_ACC_TEST_CODE/build/bootloader/bootloader.bin"
Bootloader binary size 0x6700 bytes. 0x900 bytes (8%) free.
[5/7] Linking CXX executable BT_ACC_TEST_CODE.elf
FAILED: BT_ACC_TEST_CODE.elf 
cmd.exe /C "cd . && C:\Espressif\tools\xtensa-esp32-elf\esp-2022r1-11.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address  @CMakeFiles\BT_ACC_TEST_CODE.elf.rsp -o BT_ACC_TEST_CODE.elf  && cd ."
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj):(.literal.app_main+0x84): undefined reference to `esp_spp_start_srv'
c:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.c.obj): in function `app_main':
C:/Users/konec/ESP-IDF/BT_ACC_TEST_CODE/main/main.c:88: undefined reference to `esp_spp_start_srv'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

 *  The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command ninja " terminated with exit code: 1. 
My testing code is here:

Code: Select all

#include <stdio.h>
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "esp_gap_bt_api.h"
#include "esp_spp_api.h"
#include "esp_log.h"
#include "nvs_flash.h"

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


static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_AUTHENTICATE;                     // Used for Call esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME)
static const esp_spp_role_t role_slave = ESP_SPP_ROLE_SLAVE;                        // Used for Call esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME)

void app_main()
{
    
    //Non-volatile storage (NVS) library is designed to store key-value pairs in flash.
    esp_err_t ret = nvs_flash_init();   //Initialize the default NVS partition.
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );
 
    // Initialization of Bluetooth controller configuration
    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ESP_LOGI(SPP_TAG, "Call esp_bt_controller_init(&bt_cfg)");
    if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s initialize controller FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI(SPP_TAG, "Initialize controller OK");
    }
   
    // Enable Bluetooth controller in CLASSIC Bluetooth mode
    ESP_LOGI(SPP_TAG, "Call esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)");
    if ((ret = esp_bt_controller_enable(CONFIG_BT_CLASSIC_ENABLED)) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s enable controller FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI(SPP_TAG, "Enable controller OK");
    }

    // Initialization of Bluedroid (necessary to be initialzed before calling "esp_bt_dev_get_address()")
    ESP_LOGI(SPP_TAG, "Call esp_bluedroid_init()");
    if ((ret = esp_bluedroid_init()) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s initialize bluedroid FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI(SPP_TAG, "Initialize bluedroid OK!");
    }

    // Eneable Bluedroid
    ESP_LOGI(SPP_TAG, "Call esp_bluedroid_enable()");
    if ((ret = esp_bluedroid_enable()) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s enable bluedroid FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI(SPP_TAG, "Enable bluedroid OK!");
    }


    ESP_LOGI(SPP_TAG, "Setting device name by calling esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME)");
    if ((ret = esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME)) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s Setting device name FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI(SPP_TAG, "Setting device name OK!");
    }



    // Declaration of a variable to store the MAC address
    const uint8_t *bt_mac;
    // Retrieving the the MAC address of the Bluetooth interface
    bt_mac = esp_bt_dev_get_address();
    if (bt_mac == NULL) {
        ESP_LOGE(SPP_TAG, "Unable to retrieve the MAC address of the Bluetooth interface");
        return;
    }

    // Writing the MAC address of the Bluetooth interface to the terminal
    ESP_LOGI(SPP_TAG, "The Bluetooth interface MAC address: %02x:%02x:%02x:%02x:%02x:%02x",
             bt_mac[0], bt_mac[1], bt_mac[2], bt_mac[3], bt_mac[4], bt_mac[5]);

    
    
    /* Zatím nevím, jak nastavit
    ESP_LOGI(SPP_TAG, "Setting SSP mode to ESP_BT_SP_MODE_NONE for security");
    if ((ret = esp_bt_gap_set_security_param(ESP_SPP_SEC_NONE, BTA_SEC_NONE, 0x0000)) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s Set SSP mode to ESP_BT_SP_MODE_NONE FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    } else {
        ESP_LOGI(SPP_TAG, "Set SSP mode to ESP_BT_SP_MODE_NONE OK!");
    }
    */
    
    // Setting the ESP32 Bluetooth device visible and connectable for other devices 
    ESP_LOGI(SPP_TAG, "Call esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE)");
    if ((ret = esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE)) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s Setting ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI(SPP_TAG, "Setting ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE OK!");
    }
    
    // HERE I WANTED TO CALL THE SERVER......
    ESP_LOGI(SPP_TAG, "Call esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME)");
    if ((esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME)) != ESP_OK) {
        ESP_LOGE(SPP_TAG, "%s Call esp_spp_start_srv FAILED!: %s\n", __func__, esp_err_to_name(ret));
        return;
    }
    else{
        ESP_LOGI(SPP_TAG, "Call esp_spp_start_srv OK!");
    }
}
Please could you help me with this step ?

Who is online

Users browsing this forum: No registered users and 84 guests