Page 1 of 1

Need help converting GATT_Server example in ESP-IDF to CPP

Posted: Tue Nov 09, 2021 6:51 am
by raja sumant
I am facing an issue converting gatt_server example to cpp.

Steps to replicate the error:

Step 1:

I copied gatt_server directory to another directory.

Step 2:
I added

extern "C"
{
void app_main();
}

to the gatt_server.c and renamed it gatt_server.cpp

Step 3:
I built the project as
idf.py build.

I get a lot of error messages like [See the attachment for the build log to know all the errors.]

"crosses initialization of 'esp_err_t add_char_ret'"

./main/main.cpp:305:12: error: enumeration value 'ESP_GATTS_WRITE_EVT' not handled in switch [-Werror=switch]
../main/main.cpp:305:12: error: enumeration value 'ESP_GATTS_EXEC_WRITE_EVT' not handled in switch [-Werror=switch]
../main/main.cpp:305:12: error: enumeration value 'ESP_GATTS_MTU_EVT' not handled in switch [-Werror=switch]
../main/main.cpp:305:12: error: enumeration value 'ESP_GATTS_CONF_EVT' not handled in switch [-Werror=switch]

etc.

I want to know if there is any example cpp project that can be provided?

If not please guide me into removing these errors.

I know that this answers the cross initialization erros:

https://stackoverflow.com/questions/115 ... tion-error

I want to understand the rest.

Re: Need help converting GATT_Server example in ESP-IDF to CPP

Posted: Tue Nov 16, 2021 8:25 am
by raja sumant
I solved this issue by adding break to the case statements.

Cross initialization was avoided by following the tip in the link above:

switch(k)
{
case 1:
{
int t = 4;
}
break;
default:
break;
}