Hello my isp is going to be switching to IPv6 addresses instead of ipv4. I was wondering how can I manually assign a IPv6 address instead of an IPV4 in sketch?
I can’t seem to figure out a way or find a way. I only saw ways to do. A standalone webserver with IPv6.please someone help me to figure this out ?
Joseph
There is a post here that seems to accomplish this. The example sets an address starting fe80:: which is link-local address and cannot be routed to another network or the Internet. That might explain why it only worked in "one direction" for the author of that post. You can't just assign any address either although you can use the prefix fc00:: for a local network address similar to the way we use 192.168.x.x addresses on IPv4.. See also the "Special addresses" table in this Wikipedia article.
When IPv6 is enabled on the ESP32, it should generate its own IPv6 address (IPv6 prefix obtained from router + its own mac) via SLAAC. This address can be read with:
Serial.println(WiFi.localIPv6());
There's a bit of example code here that shows how to wait for Wifi to start and obtain its IPv6 address before attempting to print it.
In addition to SLAAC, you can also enable DHCPv6 on your router, assuming that it is supported. This gives you more control than when using SLAAC.
BTW, when your ISP changes to using IPv6 addresses, you should still be able to use IPv4 internally and your router (assuming that its IPv6 capable - most modern ones should be) ought to be able to take care of the routing between your internal network and the router external ISP assigned IPv6 address. One caveat may be if you host services on your network, e.g. such as a web server, in which case some additional configuration may be required for inbound forwarding and firewall rules.
A visit to test-ipv6.com should give you some idea of the state of readiness of your ISP and router. (my setup currently gets a 0 because although my router is IPv6 capable, my ISP does not support it yet!)