Obtention de références non définies pour les fonctions C lors de la création du projet ESP8266

J’ai suivi ce tutoriel pour installer une application Kaa sur un ESP8266 et cela a fonctionné après quelques modifications: https://kaaproject.github.io/kaa/docs/v0.10.0/Programming-guide/Using-Kaa-endpoint-SDKs / C / SDK-ESP8266 /

Une des modifications que j’ai eu à faire a été de déplacer une ligne de code dans eagle.app.v6.ld à cause d’un débordement d’octets (la flèche indique le changement que j’ai fait):

... .irom0.text : ALIGN(4) { _irom0_text_start = ABSOLUTE(.); *(.literal.* .text.*) --> moved from ".text : ALIGN(4){...}" ... } ... 

Après cela, il me restait encore un débordement d’octets. J’ai donc modifié la commande cmake originale de la documentation pour désactiver les extensions cmake occupant de l’espace:

 cmake \ -DCMAKE_TOOLCHAIN_FILE=../kaa/toolchains/esp8266.cmake \ -DKAA_PLATFORM=esp8266 \ -DCMAKE_BUILD_TYPE=MinSizeRel \ -DWITH_EXTENSION_CONFIGURATION=OFF \ -DWITH_EXTENSION_EVENT=OFF \ -DWITH_EXTENSION_LOGGING=OFF \ -DWITH_EXTENSION_NOTIFICATION=OFF \ -DWITH_EXTENSION_USER=OFF \ -DWITH_ENCRYPTION=OFF \ -DKAA_MAX_LOG_LEVEL=3 .. 

Enfin, lorsque j’ai exécuté la commande make. ça a marché. J’ai ensuite créé et flashé les fichiers binarys dans mon ESP. Ensuite, j’ai réinitialisé mon ESP avec GPIO0 élevé (afin qu’il puisse démarrer à partir de Flash) et l’ESP a envoyé “Bonjour Kaa!” dans le port série auquel j’étais connecté.

Maintenant, cependant. J’essaie de faire en sorte que mon ESP8266 se connecte à mon serveur Kaa et génère un profil de sharepoint terminaison. J’ai donc besoin du code pour créer un canal de transport afin de communiquer à la fois avec le serveur Bootstrap et le serveur Operations.

Pour ce faire, j’ai essayé d’utiliser le code de Your First Kaa Application qui génère de fausses lectures de température, reçoit le schéma de configuration et envoie les données à mon serveur Cassandra via log appender: https://kaaproject.github.io/kaa/docs/v0 .10.0 / Guide de programmation / Votre première application Kaa /

Donc, dans ma tentative, j’ai laissé le même répertoire:

 CMakeLists.txt driver/ uart.h uart.c ld/ eagle.app.v6.ld eagle.rom.addr.v6.ld kaa/  --> replaced with new SDK with log and configuration schema user/ user_main.c src/ kaa_demo.c --> replaced with new code from "Your First Kaa Application" 

J’ai ensuite remplacé ce code dans mon fichier kaa_demo.c:

 #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  static int32_t sample_period; static time_t last_sample_time; extern kaa_error_t ext_unlimited_log_storage_create(void **log_storage_context_p, kaa_logger_t *logger); /* Resortingeves current temperature. */ static int32_t get_temperature_sample(void) { /* For the sake of example, random data is used */ return rand() % 10 + 25; } /* Periodically called by Kaa SDK. */ static void example_callback(void *context) { time_t current_time = time(NULL); /* Respect sample period */ if (difftime(current_time, last_sample_time) >= sample_period) { int32_t temperature = get_temperature_sample(); printf("Sampled temperature: %i\n", temperature); last_sample_time = current_time; kaa_user_log_record_t *log_record = kaa_logging_data_collection_create(); log_record->temperature = temperature; kaa_logging_add_record(kaa_client_get_context(context)->log_collector, log_record, NULL); } } /* Receives new configuration data. */ static kaa_error_t on_configuration_updated(void *context, const kaa_root_configuration_t *conf) { (void) context; printf("Received configuration data. New sample period: %i seconds\n", conf->sample_period); sample_period = conf->sample_period; return KAA_ERR_NONE; } int main(void) { /* Init random generator used to generate temperature */ srand(time(NULL)); /* Prepare Kaa client. */ kaa_client_t *kaa_client = NULL; kaa_error_t error = kaa_client_create(&kaa_client, NULL); if (error) { return EXIT_FAILURE; } /* Configure notification manager. */ kaa_configuration_root_receiver_t receiver = { .context = NULL, .on_configuration_updated = on_configuration_updated }; error = kaa_configuration_manager_set_root_receiver( kaa_client_get_context(kaa_client)->configuration_manager, &receiver); if (error) { return EXIT_FAILURE; } /* Obtain default configuration shipped within SDK. */ const kaa_root_configuration_t *dflt = kaa_configuration_manager_get_configuration( kaa_client_get_context(kaa_client)->configuration_manager); printf("Default sample period: %i seconds\n", dflt->sample_period); sample_period = dflt->sample_period; /* Configure data collection. */ void *log_storage_context = NULL; void *log_upload_strategy_context = NULL; /* The internal memory log storage dissortingbuted with Kaa SDK. */ error = ext_unlimited_log_storage_create(&log_storage_context, kaa_client_get_context(kaa_client)->logger); if (error) { return EXIT_FAILURE; } /* Create a strategy based on timeout. */ error = ext_log_upload_strategy_create( kaa_client_get_context(kaa_client), &log_upload_strategy_context, KAA_LOG_UPLOAD_BY_TIMEOUT_STRATEGY); if (error) { return EXIT_FAILURE; } /* Strategy will upload logs every 5 seconds. */ error = ext_log_upload_strategy_set_upload_timeout(log_upload_strategy_context, 5); if (error) { return EXIT_FAILURE; } /* Specify log bucket size constraints. */ kaa_log_bucket_constraints_t bucket_sizes = { .max_bucket_size = 32, /* Bucket size in bytes. */ .max_bucket_log_count = 2, /* Maximum log count in one bucket. */ }; /* Initialize the log storage and strategy (by default, they are not set). */ error = kaa_logging_init(kaa_client_get_context(kaa_client)->log_collector, log_storage_context, log_upload_strategy_context, &bucket_sizes); if (error) { return EXIT_FAILURE; } /* Start Kaa SDK's main loop. example_callback is called once per second. */ error = kaa_client_start(kaa_client, example_callback, kaa_client, 1); /* Should get here only after Kaa stops. */ kaa_client_destroy(kaa_client); if (error) { return EXIT_FAILURE; } return EXIT_SUCCESS; } 

J’ai laissé le fichier CMakeLists.txt le même:

 cmake_minimum_required(VERSION 3.0.2) project(kaa_demo C) # Add Kaa SDK directory add_subdirectory(kaa) # Add source files add_library(kaa_demo_s STATIC user/user_main.c driver/uart.c src/kaa_demo.c) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") if(NOT DEFINED ESP_RTOS_SDK) set(ESP_RTOS_SDK /opt/Espressif/esp-rtos-sdk) endif() # specify include directories target_include_directories(kaa_demo_s PUBLIC driver) target_include_directories(kaa_demo_s PUBLIC .) target_include_directories(kaa_demo_s PUBLIC ${ESP_RTOS_SDK}/extra_include ${ESP_RTOS_SDK}/include ${ESP_RTOS_SDK}/include/lwip ${ESP_RTOS_SDK}/include/lwip/ipv4 ${ESP_RTOS_SDK}/include/lwip/ipv6 ${ESP_RTOS_SDK}/include/espressif/ ) exec_program(xtensa-lx106-elf-gcc . ARGS -print-libgcc-file-name OUTPUT_VARIABLE ESP8266_LIBGCC ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/ld) target_link_libraries(kaa_demo_s PUBLIC kaac ${ESP_RTOS_SDK}/lib/libfreertos.a ${ESP_RTOS_SDK}/lib/libhal.a ${ESP_RTOS_SDK}/lib/libpp.a ${ESP_RTOS_SDK}/lib/libphy.a ${ESP_RTOS_SDK}/lib/libnet80211.a ${ESP_RTOS_SDK}/lib/libwpa.a ${ESP_RTOS_SDK}/lib/liblwip.a ${ESP_RTOS_SDK}/lib/libmain.a ${ESP_RTOS_SDK}/lib/libssl.a ${ESP_RTOS_SDK}/lib/libhal.a ${ESP8266_LIBGCC} -Teagle.app.v6.ld ) file(WRITE ${CMAKE_BINARY_DIR}/blank.c "") add_executable(kaa_demo ${CMAKE_BINARY_DIR}/blank.c) target_link_libraries(kaa_demo kaa_demo_s) 

J’ai quitté le fichier user_main.c le même:

 #include  #include  #include "uart.h" extern int main(void); static void main_task(void *pvParameters) { (void)pvParameters; main(); for (;;); } void user_init(void) { uart_init_new(); UART_SetBaudrate(UART0, 115200); UART_SetPrintPort(UART0); portBASE_TYPE error = xTaskCreate(main_task, "main_task", 512, NULL, 2, NULL ); if (error < 0) { printf("Error creating main_task! Error code: %ld\r\n", error); } } 

J’ai quitté eagle.app.v6.ld (à l’exception de la modification décrite au début) et eagle.rom.addr.ld, uart.h et uart.c les mêmes (obtenus de github)

Donc, quand je change de répertoire de compilation et que j’exécute cette commande cmake:

 cmake \ -DCMAKE_TOOLCHAIN_FILE=../kaa/toolchains/esp8266.cmake \ -DKAA_PLATFORM=esp8266 \ -DCMAKE_BUILD_TYPE=MinSizeRel \ -DWITH_EXTENSION_CONFIGURATION=OFF \ -DWITH_EXTENSION_EVENT=OFF \ -DWITH_EXTENSION_LOGGING=OFF \ -DWITH_EXTENSION_NOTIFICATION=OFF \ -DWITH_EXTENSION_USER=OFF \ -DWITH_ENCRYPTION=OFF \ -DKAA_MAX_LOG_LEVEL=3 .. 

Je reçois ceci: (esp8266 est mon nom d’utilisateur, kaa-app est le répertoire principal qui contient: CMakeLists.txt, la construction, les pilotes, etc.)

 -- Default SDK location will be used: /opt/Espressif/esp-rtos-sdk -- Toolchain path: /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf -- ESP8266 SDK path: /opt/Espressif/esp-rtos-sdk ================================== BUILD_TYPE = MinSizeRel KAA_PLATFORM = esp8266 KAA_MAX_LOG_LEVEL = 3 ================================== BOOTSTRAP ENABLED PROFILE ENABLED KAA WILL BE INSTALLED TO /usr/local -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- Configuring done -- Generating done -- Build files have been written to: /home/esp8266/Documents/kaa-app/build 

Alors, je lance make et j’obtiens cette erreur:

 libkaa_demo_s.a(kaa_demo2.c.obj):(.text.example_callback+0x8): undefined reference to `time' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.example_callback+0xc): undefined reference to `difftime' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.example_callback+0x20): undefined reference to `kaa_logging_add_record' libkaa_demo_s.a(kaa_demo2.c.obj): In function `example_callback': kaa_demo2.c:(.text.example_callback+0x35): undefined reference to `time' kaa_demo2.c:(.text.example_callback+0x42): undefined reference to `difftime' kaa_demo2.c:(.text.example_callback+0x9e): undefined reference to `kaa_logging_add_record' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x10): undefined reference to `srand' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x14): undefined reference to `kaa_configuration_manager_set_root_receiver' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x18): undefined reference to `kaa_configuration_manager_get_configuration' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x1c): undefined reference to `ext_unlimited_log_storage_create' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x20): undefined reference to `ext_log_upload_strategy_create' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x24): undefined reference to `ext_log_upload_strategy_set_upload_timeout' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x28): undefined reference to `kaa_logging_init' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x3a): undefined reference to `time' libkaa_demo_s.a(kaa_demo2.c.obj):(.text.startup.main+0x40): undefined reference to `srand' libkaa_demo_s.a(kaa_demo2.c.obj): In function `main': kaa_demo2.c:(.text.startup.main+0x69): undefined reference to `kaa_configuration_manager_set_root_receiver' kaa_demo2.c:(.text.startup.main+0x7b): undefined reference to `kaa_configuration_manager_get_configuration' kaa_demo2.c:(.text.startup.main+0xa5): undefined reference to `ext_unlimited_log_storage_create' kaa_demo2.c:(.text.startup.main+0xb8): undefined reference to `ext_log_upload_strategy_create' kaa_demo2.c:(.text.startup.main+0xc5): undefined reference to `ext_log_upload_strategy_set_upload_timeout' kaa_demo2.c:(.text.startup.main+0xe6): undefined reference to `kaa_logging_init' collect2: error: ld returned 1 exit status CMakeFiles/kaa_demo.dir/build.make:120: recipe for target 'kaa_demo' failed make[2]: *** [kaa_demo] Error 1 CMakeFiles/Makefile2:107: recipe for target 'CMakeFiles/kaa_demo.dir/all' failed make[1]: *** [CMakeFiles/kaa_demo.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: *** [all] Error 2 

Il semble donc que lorsqu’il tente de lier les fichiers, il ne trouve pas les nouveaux en-têtes que j’ai inclus:

 #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  

Cependant, le répertoire cible inclus dans CMakeLists.txt contient les fichiers d’en-tête dont j’ai besoin (pour les en-têtes C):

 ${ESP_RTOS_SDK}/extra_include 

Donc, je ne sais vraiment pas ce que je dois append ou modifier, je suis complètement bloqué. Toute aide serait très appréciée! Merci!

Pour data_collection, vous devez définir -DWITH_EXTENSION_LOGGING=ON .

Pour esp8266, vous avez une autre bibliothèque “time.h” /kaa/src/kaa/platform-impl/esp8266/platform qui ne supporte pas la fonction time(NULL) , mais supporte

kaa_time_t kaa_esp8266_get_time(void);