Hi All
The latest ESP FAQ Handbook says: "If it is a global static IP, both IPv6 and IPv4 support manual configuration"
However I've not been able to discover how to successfully achieve this, particularly to establish a WiFi connection with an ESP32 board.
Rather than static the preference is actually to retrieve a global IPv6 address via dhcp6 (via an Ubuntu 22.04 dnsmasq server, served up according to the client's MAC address using the normal dhcp-host method) but it doesn't look like this is possible right now.
Help would be very much appreciated, either a suitable manual reference(s) or example code. Cheers Ron.
How to set a static global IPV6 address using esp-idf 5.2.1
-
- Posts: 5
- Joined: Mon May 20, 2024 7:55 pm
-
- Posts: 5
- Joined: Mon May 20, 2024 7:55 pm
Re: How to set a static global IPV6 address using esp-idf 5.2.1
Partly answering myself. To enable SLAAC global addresses it is necessary to set a kconfig setting using menuconfig as described here:
https://github.com/espressif/arduino-esp32/issues/6626
"On current ESP-IDF version, I can configure sample projects to receive IPv6 either via SLAAC or DCHP6 via idf.py menuconfig -> Component config ---> LWIP ---> Enable IPV6 stateless address autoconfiguration (SLAAC)"
https://github.com/espressif/arduino-esp32/issues/6626
"On current ESP-IDF version, I can configure sample projects to receive IPv6 either via SLAAC or DCHP6 via idf.py menuconfig -> Component config ---> LWIP ---> Enable IPV6 stateless address autoconfiguration (SLAAC)"
-
- Posts: 5
- Joined: Mon May 20, 2024 7:55 pm
Re: How to set a static global IPV6 address using esp-idf 5.2.1
Responding again in case it helps other.
Eventually I did manage to find an obscure reference (not in the latest esp-idf manual) that enables a static IPV6 address to be configured. The code for the relevant wifi setup function in my code is provided here:
Cheers
Ron
Eventually I did manage to find an obscure reference (not in the latest esp-idf manual) that enables a static IPV6 address to be configured. The code for the relevant wifi setup function in my code is provided here:
- // Static IPv6 configuration
- #define STATIC_IPV6_ADDR "2001:470:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX"
- void wifi_init_sta() {
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- ESP_ERROR_CHECK(esp_wifi_init(&cfg));
- ESP_ERROR_CHECK(esp_netif_init());
- // Initialize the event loop
- ESP_ERROR_CHECK(esp_event_loop_create_default());
- sta_netif = esp_netif_create_default_wifi_sta();
- esp_netif_set_hostname(sta_netif, hostname);
- esp_netif_dhcpc_stop(sta_netif); // Disable DHCP client for IPv4
- if (!sta_netif) {
- ESP_LOGE(TAG, "Failed to create default WiFi station interface");
- return;
- }
- ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
- // Register handler for IPv6 events
- ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &wifi_event_handler, NULL));
- wifi_config_t wifi_config = {
- .sta = {
- .ssid = SSID,
- .password = PASSWORD,
- },
- };
- ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
- ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
- ESP_ERROR_CHECK(esp_wifi_start());
- // Configure static IPV6 address
- esp_netif_ip6_info_t ip6_addr = { 0 };
- ip6addr_aton(STATIC_IPV6_ADDR, (ip6_addr_t *)&ip6_addr.ip);
- struct netif *lwip_netif = esp_netif_get_netif_impl(sta_netif);
- ESP_ERROR_CHECK(netif_add_ip6_address(lwip_netif, (ip6_addr_t *)&ip6_addr.ip, 0));
- // ESP_ERROR_CHECK(esp_netif_set_dns_info(sta_netif), ESP_NETIF_DNS_MAIN, &dns_info));
- }
Ron
Re: How to set a static global IPV6 address using esp-idf 5.2.1
The way HOW you set a static ipv6 address is properly documented. What's not documented is how you should set netmask and gateway.
DHCPv6 is not supported, this also documented. Best use SLAAC then.
DHCPv6 is not supported, this also documented. Best use SLAAC then.
Who is online
Users browsing this forum: No registered users and 86 guests