|
|
@@ -20,11 +20,20 @@
|
|
|
#include "nvs.h"
|
|
|
#include "nvs_flash.h"
|
|
|
#include "protocol_examples_common.h"
|
|
|
-
|
|
|
+#include <sys/socket.h>
|
|
|
#if CONFIG_EXAMPLE_CONNECT_WIFI
|
|
|
#include "esp_wifi.h"
|
|
|
#endif
|
|
|
|
|
|
+#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
|
|
|
+/* The interface name value can refer to if_desc in esp_netif_defaults.h */
|
|
|
+#if CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_ETH
|
|
|
+static const char *bind_interface_name = "eth";
|
|
|
+#elif CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_STA
|
|
|
+static const char *bind_interface_name = "sta";
|
|
|
+#endif
|
|
|
+#endif
|
|
|
+
|
|
|
static const char *TAG = "simple_ota_example";
|
|
|
extern const uint8_t server_cert_pem_start[] asm("_binary_ca_cert_pem_start");
|
|
|
extern const uint8_t server_cert_pem_end[] asm("_binary_ca_cert_pem_end");
|
|
|
@@ -62,12 +71,24 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
|
|
void simple_ota_example_task(void *pvParameter)
|
|
|
{
|
|
|
ESP_LOGI(TAG, "Starting OTA example");
|
|
|
-
|
|
|
+#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
|
|
|
+ esp_netif_t *netif = get_example_netif_from_desc(bind_interface_name);
|
|
|
+ if (netif == NULL) {
|
|
|
+ ESP_LOGE(TAG, "Can't find netif from interface description");
|
|
|
+ abort();
|
|
|
+ }
|
|
|
+ struct ifreq ifr;
|
|
|
+ esp_netif_get_netif_impl_name(netif, ifr.ifr_name);
|
|
|
+ ESP_LOGI(TAG, "Bind interface name is %s", ifr.ifr_name);
|
|
|
+#endif
|
|
|
esp_http_client_config_t config = {
|
|
|
.url = CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL,
|
|
|
.cert_pem = (char *)server_cert_pem_start,
|
|
|
.event_handler = _http_event_handler,
|
|
|
.keep_alive_enable = true,
|
|
|
+#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
|
|
|
+ .if_name = &ifr,
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL_FROM_STDIN
|