espressif / esp-homekit-sdk

544 stars 98 forks source link

Bug in esp_netif_t declaration at app_wifi/app_wifi.c #39

Closed GoRo33 closed 3 years ago

GoRo33 commented 3 years ago

Hi! I have checkout on lates develop on:

and I'm developing on ESP8285(Gsound SP111 smart plug). When trying to compile i get this error:

In file included from /Volumes/Programowanie/ESP/ESP8266_RTOS_SDK/components/heap/include/esp_heap_caps.h:21,
                 from /Volumes/Programowanie/ESP/ESP8266_RTOS_SDK/components/freertos/include/freertos/private/portable.h:92,
                 from /Volumes/Programowanie/ESP/ESP8266_RTOS_SDK/components/freertos/include/freertos/FreeRTOS.h:62,
                 from /Users/grzegorz/Programowanie/ESP/esp-homekit-sdk/examples/common/app_wifi/app_wifi.c:26:
/Users/grzegorz/Programowanie/ESP/esp-homekit-sdk/examples/common/app_wifi/app_wifi.c: In function 'app_wifi_init':
/Users/grzegorz/Programowanie/ESP/esp-homekit-sdk/examples/common/app_wifi/app_wifi.c:261:94: error: 'wifi_netif' undeclared (first use in this function); did you mean 'wifi_ant_t'?
     ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, wifi_netif));
                                                                                              ^~~~~~~~~~
/Volumes/Programowanie/ESP/ESP8266_RTOS_SDK/components/esp_common/include/esp_err.h:117:31: note: in definition of macro 'ESP_ERROR_CHECK'
         esp_err_t __err_rc = (x);                                       \
                               ^
/Users/grzegorz/Programowanie/ESP/esp-homekit-sdk/examples/common/app_wifi/app_wifi.c:261:94: note: each undeclared identifier is reported only once for each function it appears in
     ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, wifi_netif));
                                                                                              ^~~~~~~~~~
/Volumes/Programowanie/ESP/ESP8266_RTOS_SDK/components/esp_common/include/esp_err.h:117:31: note: in definition of macro 'ESP_ERROR_CHECK'
         esp_err_t __err_rc = (x);

After my investigation I see that in file link_to_file at line 261, you are trying to pass wifi_netif object to event handler initialization function. This is problem when you are trying to compile for target that don't support new netif abstraction. I suppose fix should look like in my patch.

diff --git a/examples/common/app_wifi/app_wifi.c b/examples/common/app_wifi/app_wifi.c
index 286d957..2d24b1d 100644
--- a/examples/common/app_wifi/app_wifi.c
+++ b/examples/common/app_wifi/app_wifi.c
@@ -255,10 +255,14 @@ void app_wifi_init(void)
     /* Initialize Wi-Fi including netif with default config */
 #ifdef ESP_NETIF_SUPPORTED
     esp_netif_t *wifi_netif = esp_netif_create_default_wifi_sta();
 #endif

     /* Register our event handler for Wi-Fi, IP and Provisioning related events */
+#ifdef ESP_NETIF_SUPPORTED
     ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, wifi_netif));
+#else
+    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
+#endif
     ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
     ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &event_handler, NULL));

Maybe you should not pass wifi_netif object, because it's not used as far as I see.

Please check that.