How to include nvs_flash component in custom outbox implementation

anantgaur
Posts: 8
Joined: Sat Jul 08, 2023 11:15 am

How to include nvs_flash component in custom outbox implementation

Postby anantgaur » Sat Jul 08, 2023 11:30 am

Hello,

I am new to ESP-IDF and wanted to make a custom outbox implementation for the MQTT client.

I have imported the file as suggested and this is in my main CMakeLists file

Code: Select all

idf_component_get_property(mqtt mqtt COMPONENT_LIB)
set_property(TARGET ${mqtt} PROPERTY SOURCES ${CMAKE_CURRENT_LIST_DIR}/path/custom_outbox.c APPEND)
this works, however I can't include the nvs_flash.h file in my custom_outbox.c.

I tried using

Code: Select all

idf_component_set_property(mqtt REQUIRES nvs_flash APPEND )
but it didn't work.

Adding nvs_flash to REQUIRES for esp-mqtt component directly in the idf directory works though, I don't know why appending it through CMake instead doesn't work. I would have assumed it does the same thing.

Any help appreciated. I am using ESP-IDF on vscode.

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

Re: How to include nvs_flash component in custom outbox implementation

Postby MicroController » Sat Jul 08, 2023 4:48 pm

AFAIR, you cannot "dynamically" change the dependencies of a component this way.

It seems that the easiest way to get what you want is to copy the MQTT component (e.g. into the components directory of your project) and modify code and cmake file there.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: How to include nvs_flash component in custom outbox implementation

Postby ESP_igrr » Sat Jul 08, 2023 7:28 pm

Please give the following a try:

target_link_libraries(idf::mqtt PRIVATE idf::nvs_flash)

anantgaur
Posts: 8
Joined: Sat Jul 08, 2023 11:15 am

Re: How to include nvs_flash component in custom outbox implementation

Postby anantgaur » Sun Jul 09, 2023 9:28 am

ESP_igrr wrote:
Sat Jul 08, 2023 7:28 pm
Please give the following a try:

target_link_libraries(idf::mqtt PRIVATE idf::nvs_flash)
I tried it and doesn't work- gives me the following error-

Code: Select all

CMake Error at main/CMakeLists.txt:13 (target_link_libraries):
  target_link_libraries can not be used on an ALIAS target.
I'll try to see if I can get target_link_libraries to work somehow.

I thought it would be easier to do since the tooltip in menuconfig mentions storing persistent messages in NVS, has no one else tried to do it before?

Thanks for the response.

anantgaur
Posts: 8
Joined: Sat Jul 08, 2023 11:15 am

Re: How to include nvs_flash component in custom outbox implementation

Postby anantgaur » Sun Jul 09, 2023 9:30 am

MicroController wrote:
Sat Jul 08, 2023 4:48 pm
AFAIR, you cannot "dynamically" change the dependencies of a component this way.

It seems that the easiest way to get what you want is to copy the MQTT component (e.g. into the components directory of your project) and modify code and cmake file there.
I would like to avoid using that if possible, but I guess that will be the last solution I would have to go for. I thought it would be simpler since the menuconfig tooltip specifically mentions persistent messages saved on NVS.

anantgaur
Posts: 8
Joined: Sat Jul 08, 2023 11:15 am

Re: How to include nvs_flash component in custom outbox implementation

Postby anantgaur » Sun Jul 09, 2023 1:57 pm

ESP_igrr wrote:
Sat Jul 08, 2023 7:28 pm
Please give the following a try:

target_link_libraries(idf::mqtt PRIVATE idf::nvs_flash)
Got it to work using target_link_libraries, thanks, just had to use COMPONENT_LIB to get name instead of using the alias.

This was the code that got it to work-

Code: Select all

idf_component_get_property(mqtt mqtt COMPONENT_LIB)
idf_component_get_property(nvs_flash nvs_flash COMPONENT_LIB)

target_link_libraries(${mqtt} ${nvs_flash})

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: How to include nvs_flash component in custom outbox implementation

Postby ESP_igrr » Mon Jul 10, 2023 9:13 am

Ah yes, of course. Sorry, I should have actually tried this line before suggesting. What you did is correct!

Who is online

Users browsing this forum: Google [Bot] and 365 guests