Skip to content

esp32 wifi station dosn't got an IPv6 address #6590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
luckyjeck opened this issue Apr 19, 2022 · 5 comments
Closed
1 task done

esp32 wifi station dosn't got an IPv6 address #6590

luckyjeck opened this issue Apr 19, 2022 · 5 comments
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved

Comments

@luckyjeck
Copy link

Board

NodeMCU-32S

Device Description

NodeMCU-32S,plain module

Hardware Configuration

nothing else.

Version

v2.0.2

IDE Name

Arduion 1.8.19

Operating System

Windows 10

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

921600

Description

esp32 wifi station dosn't got an IPv6 address

when pc and esp32 connected to the same WIFI Router,
the pc got an IPv6 address correctly,
but esp32 wifi station dosn't got an IPv6 address.
how to fix this issue ?

Sketch

#include "WiFi.h"

#define STA_SSID "**********"
#define STA_PASS "**********"
#define AP_SSID  "esp32-v6"

static volatile bool wifi_connected = false;

WiFiUDP ntpClient;

void wifiOnConnect(){
    Serial.println("STA Connected");
    Serial.print("STA IPv4: ");
    Serial.println(WiFi.localIP());
    
    Serial.print("STA IPv6: ");
    Serial.println(WiFi.localIPv6());

    ntpClient.begin(2390);
}

void wifiOnDisconnect(){
    Serial.println("STA Disconnected");
    delay(1000);
    WiFi.begin(STA_SSID, STA_PASS);
}

void wifiConnectedLoop(){
  //lets check the time
  const int NTP_PACKET_SIZE = 48;
  byte ntpPacketBuffer[NTP_PACKET_SIZE];

  IPAddress address;
  WiFi.hostByName("time.nist.gov", address);
  memset(ntpPacketBuffer, 0, NTP_PACKET_SIZE);
  ntpPacketBuffer[0] = 0b11100011;   // LI, Version, Mode
  ntpPacketBuffer[1] = 0;     // Stratum, or type of clock
  ntpPacketBuffer[2] = 6;     // Polling Interval
  ntpPacketBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  ntpPacketBuffer[12]  = 49;
  ntpPacketBuffer[13]  = 0x4E;
  ntpPacketBuffer[14]  = 49;
  ntpPacketBuffer[15]  = 52;
  ntpClient.beginPacket(address, 123); //NTP requests are to port 123
  ntpClient.write(ntpPacketBuffer, NTP_PACKET_SIZE);
  ntpClient.endPacket();

  delay(1000);
  
  int packetLength = ntpClient.parsePacket();
  if (packetLength){
    if(packetLength >= NTP_PACKET_SIZE){
      ntpClient.read(ntpPacketBuffer, NTP_PACKET_SIZE);
    }
    ntpClient.flush();
    uint32_t secsSince1900 = (uint32_t)ntpPacketBuffer[40] << 24 | (uint32_t)ntpPacketBuffer[41] << 16 | (uint32_t)ntpPacketBuffer[42] << 8 | ntpPacketBuffer[43];
    //Serial.printf("Seconds since Jan 1 1900: %u\n", secsSince1900);
    uint32_t epoch = secsSince1900 - 2208988800UL;
    //Serial.printf("EPOCH: %u\n", epoch);
    uint8_t h = (epoch  % 86400L) / 3600;
    uint8_t m = (epoch  % 3600) / 60;
    uint8_t s = (epoch % 60);
    Serial.printf("UTC: %02u:%02u:%02u (GMT)\n", h, m, s);
  }

  delay(9000);
}

void WiFiEvent(WiFiEvent_t event){
    switch(event) {

        case ARDUINO_EVENT_WIFI_AP_START:
            //can set ap hostname here
            WiFi.softAPsetHostname(AP_SSID);
            //enable ap ipv6 here
            WiFi.softAPenableIpV6();
            break;

        case ARDUINO_EVENT_WIFI_STA_START:
            //set sta hostname here
            WiFi.setHostname(AP_SSID);
            break;
        case ARDUINO_EVENT_WIFI_STA_CONNECTED:
            //enable sta ipv6 here
            WiFi.enableIpV6();
            break;
        case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
            Serial.print("STA IPv6: ");
            Serial.println(WiFi.localIPv6());
            break;
        case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
            Serial.print("AP IPv6: ");
            Serial.println(WiFi.softAPIPv6());
            break;
        case ARDUINO_EVENT_WIFI_STA_GOT_IP:
            wifiOnConnect();
            wifi_connected = true;
            break;
        case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
            wifi_connected = false;
            wifiOnDisconnect();
            break;
        default:
            break;
    }
}

void setup(){
    Serial.begin(115200);
    WiFi.disconnect(true);
    WiFi.onEvent(WiFiEvent);
    WiFi.mode(WIFI_MODE_APSTA);
    WiFi.softAP(AP_SSID);
    WiFi.begin(STA_SSID, STA_PASS);
}

void loop(){
    if(wifi_connected){
        wifiConnectedLoop();
    }
    while(Serial.available()) Serial.write(Serial.read());
}

Debug Message

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:12804
ho 0 tail 12 room 4
load:0x40080400,len:3032
entry 0x400805e4
WiFi Event ID: 3
STA Connected
STA IPv4: 172.20.10.2
STA IPv6: 0000:0000:0000:0000:0000:0000:0000:0000
WiFi connected
IP address: 
172.20.10.2
UTC: 01:49:32 (GMT)
UTC: 01:49:42 (GMT)
UTC: 01:49:52 (GMT)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@luckyjeck luckyjeck added the Status: Awaiting triage Issue is waiting for triage label Apr 19, 2022
@VojtechBartoska VojtechBartoska added the Area: BT&Wifi BT & Wifi related issues label Apr 20, 2022
@srochapimenta
Copy link

srochapimenta commented Apr 20, 2022

Looks like your have problems with DHCP-V6, for me it works great, with few changes...

Note: GOT_IP6 firing two times, one for AP_START and other for STA_CONNECTED.

Debug
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 14 - AP_START
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 14 - AP_START
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 20 - GOT_IP6
STA IPv6: 0000:0000:0000:0000:0000:0000:0000:0000
AP IPv6: fe80:0000:0000:0000:32ae:a4ff:fe02:e489
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 192.168.27.50, MASK: 255.255.255.0, GW: 192.168.27.1
UTC: 19:59:19 (GMT)
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 20 - GOT_IP6
STA IPv6: fe80:0000:0000:0000:32ae:a4ff:fe02:e488
AP IPv6: fe80:0000:0000:0000:32ae:a4ff:fe02:e489
UTC: 19:59:29 (GMT)

`
#include <WiFi.h> // CHANGED!!!

#define STA_SSID ""
#define STA_PASS "
"
#define AP_SSID "esp32-v6"

static volatile bool wifi_connected = false;

WiFiUDP ntpClient;

void wifiOnConnect(){
Serial.println("STA Connected");
//Serial.print("STA IPv4: "); // COMMENT OUT
//Serial.println(WiFi.localIP()); // COMMENT OUT

//Serial.print("STA IPv6: ");  // COMMENT OUT
//Serial.println(WiFi.localIPv6()); // COMMENT OUT

ntpClient.begin(2390);

}

void wifiOnDisconnect(){
Serial.println("STA Disconnected");
delay(1000);
WiFi.begin(STA_SSID, STA_PASS);
}

void wifiConnectedLoop(){
//lets check the time
const int NTP_PACKET_SIZE = 48;
byte ntpPacketBuffer[NTP_PACKET_SIZE];

IPAddress address;
WiFi.hostByName("time.nist.gov", address);
memset(ntpPacketBuffer, 0, NTP_PACKET_SIZE);
ntpPacketBuffer[0] = 0b11100011; // LI, Version, Mode
ntpPacketBuffer[1] = 0; // Stratum, or type of clock
ntpPacketBuffer[2] = 6; // Polling Interval
ntpPacketBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
ntpPacketBuffer[12] = 49;
ntpPacketBuffer[13] = 0x4E;
ntpPacketBuffer[14] = 49;
ntpPacketBuffer[15] = 52;
ntpClient.beginPacket(address, 123); //NTP requests are to port 123
ntpClient.write(ntpPacketBuffer, NTP_PACKET_SIZE);
ntpClient.endPacket();

delay(1000);

int packetLength = ntpClient.parsePacket();
if (packetLength){
if(packetLength >= NTP_PACKET_SIZE){
ntpClient.read(ntpPacketBuffer, NTP_PACKET_SIZE);
}
ntpClient.flush();
uint32_t secsSince1900 = (uint32_t)ntpPacketBuffer[40] << 24 | (uint32_t)ntpPacketBuffer[41] << 16 | (uint32_t)ntpPacketBuffer[42] << 8 | ntpPacketBuffer[43];
//Serial.printf("Seconds since Jan 1 1900: %u\n", secsSince1900);
uint32_t epoch = secsSince1900 - 2208988800UL;
//Serial.printf("EPOCH: %u\n", epoch);
uint8_t h = (epoch % 86400L) / 3600;
uint8_t m = (epoch % 3600) / 60;
uint8_t s = (epoch % 60);
Serial.printf("UTC: %02u:%02u:%02u (GMT)\n", h, m, s);
}

delay(9000);
}

void WiFiEvent(WiFiEvent_t event){
switch(event) {

    //  CHANGED ARDUINO to SYSTEM EVENTS

    case SYSTEM_EVENT_AP_START:
        //can set ap hostname here
        WiFi.softAPsetHostname(AP_SSID);
        //enable ap ipv6 here
        WiFi.softAPenableIpV6();
        break;

    case SYSTEM_EVENT_STA_START:
        //set sta hostname here
        WiFi.setHostname(AP_SSID);
        break;
    case SYSTEM_EVENT_STA_CONNECTED:
        //enable sta ipv6 here
        WiFi.enableIpV6();
        break;
    case SYSTEM_EVENT_GOT_IP6: 
       
        // ADDED PRINT TO DIFERENTMODES

        if ( WiFi.getMode() == WIFI_MODE_STA || WiFi.getMode() == WIFI_MODE_APSTA ) {
          Serial.print("STA IPv6: ");
          Serial.println(WiFi.localIPv6());
        }
        if ( WiFi.getMode() == WIFI_MODE_AP || WiFi.getMode() == WIFI_MODE_APSTA ) {
          Serial.print("AP IPv6: ");
          Serial.println(WiFi.softAPIPv6());
        }
        break;
    case SYSTEM_EVENT_STA_GOT_IP:
        wifiOnConnect();
        wifi_connected = true;
        break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
        wifi_connected = false;
        wifiOnDisconnect();
        break;
    default:
        break;
}

}

void setup(){
Serial.begin(115200);
Serial.println("");
WiFi.disconnect(true);
WiFi.onEvent(WiFiEvent);
WiFi.mode(WIFI_MODE_APSTA);
WiFi.softAP(AP_SSID);
WiFi.begin(STA_SSID, STA_PASS);
}

void loop(){
if(wifi_connected){
wifiConnectedLoop();
}
while(Serial.available()) Serial.write(Serial.read());
}
`

@VojtechBartoska
Copy link
Contributor

Is this still valid?

@VojtechBartoska VojtechBartoska added Resolution: Awaiting response Waiting for response of author and removed Status: Awaiting triage Issue is waiting for triage labels May 5, 2022
nuclearcat added a commit to nuclearcat/esp32-arduino-lib-builder that referenced this issue May 7, 2022
To use IPv6 we need proper SLAAC support which is not possible without this option.
Compile tested on esp32, esp32s2, esp32s3, esp32c3
Functionality tested in esp32 BasicHttpClient with some minor patches, IPv6 start to work.

No significant sketch size increase (probably within rounding bounds):
Before:
Wrote 875328 bytes (558896 compressed) at 0x00010000 in 9.0 seconds (effective 779.4 kbit/s)...
After:
Wrote 875328 bytes (558942 compressed) at 0x00010000 in 9.0 seconds (effective 779.8 kbit/s)...

This patch part of the efforts mentioned in espressif/arduino-esp32#6242

Proper IPv6 support also was requested in:
espressif/arduino-esp32#6626
espressif/arduino-esp32#6590
espressif/arduino-esp32#6283
espressif/arduino-esp32#6703
espressif/arduino-esp32#5624
espressif/arduino-esp32#1261
And many others.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
nuclearcat added a commit to nuclearcat/esp32-arduino-lib-builder that referenced this issue May 10, 2022
To use IPv6 we need proper SLAAC support which is not possible without this option.
Compile tested on esp32, esp32s2, esp32s3, esp32c3
Functionality tested in esp32 BasicHttpClient with some minor patches, IPv6 start to work.

No significant sketch size increase (probably within rounding bounds):
Before:
Wrote 875328 bytes (558896 compressed) at 0x00010000 in 9.0 seconds (effective 779.4 kbit/s)...
After:
Wrote 875328 bytes (558942 compressed) at 0x00010000 in 9.0 seconds (effective 779.8 kbit/s)...

This patch part of the efforts mentioned in espressif/arduino-esp32#6242

Proper IPv6 support also was requested in:
espressif/arduino-esp32#6626
espressif/arduino-esp32#6590
espressif/arduino-esp32#6283
espressif/arduino-esp32#6703
espressif/arduino-esp32#5624
espressif/arduino-esp32#1261
And many others.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
nuclearcat added a commit to nuclearcat/esp32-arduino-lib-builder that referenced this issue May 23, 2022
To use IPv6 we need proper SLAAC support which is not possible without this option.
Compile tested on esp32, esp32s2, esp32s3, esp32c3
Functionality tested in esp32 BasicHttpClient with some minor patches, IPv6 start to work.

No significant sketch size increase (probably within rounding bounds):
Before:
Wrote 875328 bytes (558896 compressed) at 0x00010000 in 9.0 seconds (effective 779.4 kbit/s)...
After:
Wrote 875328 bytes (558942 compressed) at 0x00010000 in 9.0 seconds (effective 779.8 kbit/s)...

This patch part of the efforts mentioned in espressif/arduino-esp32#6242

Proper IPv6 support also was requested in:
espressif/arduino-esp32#6626
espressif/arduino-esp32#6590
espressif/arduino-esp32#6283
espressif/arduino-esp32#6703
espressif/arduino-esp32#5624
espressif/arduino-esp32#1261
And many others.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
me-no-dev pushed a commit to espressif/esp32-arduino-lib-builder that referenced this issue Jun 12, 2022
To use IPv6 we need proper SLAAC support which is not possible without this option.
Compile tested on esp32, esp32s2, esp32s3, esp32c3
Functionality tested in esp32 BasicHttpClient with some minor patches, IPv6 start to work.

No significant sketch size increase (probably within rounding bounds):
Before:
Wrote 875328 bytes (558896 compressed) at 0x00010000 in 9.0 seconds (effective 779.4 kbit/s)...
After:
Wrote 875328 bytes (558942 compressed) at 0x00010000 in 9.0 seconds (effective 779.8 kbit/s)...

This patch part of the efforts mentioned in espressif/arduino-esp32#6242

Proper IPv6 support also was requested in:
espressif/arduino-esp32#6626
espressif/arduino-esp32#6590
espressif/arduino-esp32#6283
espressif/arduino-esp32#6703
espressif/arduino-esp32#5624
espressif/arduino-esp32#1261
And many others.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
@VojtechBartoska
Copy link
Contributor

Closing as solved. If needed, please reopen the issue.

@VojtechBartoska VojtechBartoska added Status: Solved and removed Resolution: Awaiting response Waiting for response of author labels Jun 14, 2022
@VojtechBartoska
Copy link
Contributor

espressif/esp32-arduino-lib-builder#67

It will be available in next release 2.0.4.

@my-dudhwala
Copy link

my-dudhwala commented Aug 17, 2023

Closing as solved. If needed, please reopen the issue.

Hello, I am extreme beginner, and I am trying to understand how to connect ESP WROOM 32(Probably generic) with a IPv6 router, help me please, or provide detailed documentation, thank you very much for all of the info you provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved
Projects
None yet
Development

No branches or pull requests

4 participants