espressif / esp-at

AT application for ESP32/ESP32-C2/ESP32-C3/ESP32-C6/ESP8266
Apache License 2.0
910 stars 829 forks source link

Cannot enable/disable DHCP for Wifi in ESP32C6 #864

Closed JavierReyes945 closed 2 months ago

JavierReyes945 commented 3 months ago

Answers checklist

AT+GMR

AT version:3.5.0.0-dev(0f91d98 - ESP32C6 - Jul 19 2024 02:57:35) SDK version:v5.1.2-dirty compile time(368f620f):Aug 9 2024 14:25:28 Bin version:v4.1.0.0-dev(ESP32C6-4MB) OK

ESP-AT Firmware Source

Local build from master Branch, also tested with prebuilt Binary for v4.0.0.0/release for ESP32C6

Hardware Information

ESP32C6-DevKitM-1

Power Supply used

USB

What is the expected behavior?

The DCHP client for Wifi interface (as Station) shall be activated or deactivated with the AT command AT+CWDHCP=<operate>,<mode>. DHCP is active by default, but in some cases one needs to assign an IP address statically, so DHCP first needs to be disabled.

What is the actual behavior?

The DHCP cannot be changed (at least not directly) with the AT command. Either before Wifi Station initialization, or after the initialization, or even after the connection to an Access Point. It simply does not allow to change the DHCP.

Strangely, one can indirectly change the DHCP with the command AT+CIPSTA=<"ip">,<"gateway">,<"netmask">, due to the condition documented:

The Set Command correlates with the commands that set DHCP, such as AT+CWDHCP.

  • If static IPv4 address is enabled, DHCP will be disabled;
  • If DHCP is enabled, static IPv4 address will be disabled;
  • The last configuration overwrites the previous configuration.

So, if we set a fixed IP address, we then see that the DHCP has been deactivated for Wifi Station. This would be OK, but then the DHCP is deactivated persistently, and the only way to activate it is to run a factory reset.

Probability of recurrence

Always

AT+SYSRAM?

AT+SYSRAM? +SYSRAM:256860,249408 OK

Steps to reproduce

Either before Wifi Station initialization:

AT
    AT
    OK
ATE0
    ATE0
    OK
AT+GMR
    AT version:3.5.0.0-dev(0f91d98 - ESP32C6 - Jul 19 2024 02:57:35)
    SDK version:v5.1.2-dirty
    compile time(368f620f):Aug  9 2024 14:25:28
    Bin version:v4.1.0.0-dev(ESP32C6-4MB)
    OK
AT+CWDHCP?
    +CWDHCP:3
    OK
AT+CWDHCP=0,0
    ERROR

Or after the initialization:

AT
    AT
    OK
ATE0
    ATE0
    OK
AT+GMR
    AT version:3.5.0.0-dev(0f91d98 - ESP32C6 - Jul 19 2024 02:57:35)
    SDK version:v5.1.2-dirty
    compile time(368f620f):Aug  9 2024 14:25:28
    Bin version:v4.1.0.0-dev(ESP32C6-4MB)
    OK
AT+CWMODE=1,0
    OK
AT+CWDHCP?
    +CWDHCP:3
    OK
AT+CWDHCP=0,0
    ERROR

Or after Wifi connection to external AP:

AT
    AT
    OK
ATE0
    ATE0
    OK
AT+GMR
    AT version:3.5.0.0-dev(0f91d98 - ESP32C6 - Jul 19 2024 02:57:35)
    SDK version:v5.1.2-dirty
    compile time(368f620f):Aug  9 2024 14:25:28
    Bin version:v4.1.0.0-dev(ESP32C6-4MB)
    OK
AT+CWMODE=1,0
    OK
AT+CWDHCP?
    +CWDHCP:3
    OK
AT+CWJAP="<redacted>","<redacted>"
    WIFI CONNECTED
    WIFI GOT IP
    OK
AT+CWDHCP?
    +CWDHCP:3
    OK
AT+CWDHCP=0,0
    ERROR

But indirectly (setting fixed IP when DHCP is on) works (but cannot be enabled again, only with a factory reset):

AT+CWDHCP?
    +CWDHCP:3
    OK
AT+CIPSTA="192.168.11.250","192.168.11.11","255.255.255.0"
    WIFI GOT IP
    OK
AT+CWDHCP?
    +CWDHCP:2
    OK
AT+CIPSTA?
    +CIPSTA:ip:"192.168.11.250"
    +CIPSTA:gateway:"192.168.11.11"
    +CIPSTA:netmask:"255.255.255.0"
    OK
AT+CWDHCP=1,0
    ERROR

AT command port output

Already detailed before

AT log port output

[2024-08-09 15:14:00.886] ESP-ROM:esp32c6-20220919                                                                                             
[2024-08-09 15:14:00.886] Build:Sep 19 2022                                                                                                    
[2024-08-09 15:14:00.887] rst:0xc (SW_CPU),boot:0xc (SPI_FAST_FLASH_BOOT)                                                                      
[2024-08-09 15:14:00.887] Saved PC:0x4001975a                                                                                                  
[2024-08-09 15:14:00.887] SPIWP:0xee                                                                                                           
[2024-08-09 15:14:00.887] mode:DIO, clock div:1                                                                                                
[2024-08-09 15:14:00.888] load:0x4086c410,len:0xd2c                                                                                            
[2024-08-09 15:14:00.888] load:0x4086e610,len:0x2df0                                                                                           
[2024-08-09 15:14:00.889] load:0x40875728,len:0x17d8                                                                                           
[2024-08-09 15:14:00.889] SHA-256 comparison failed:                                                                                           
[2024-08-09 15:14:00.889] Calculated: 63045dfae877bfe6aba67856cf9cd56b6defbda508cb8a0274419830fbca4e24                                         
[2024-08-09 15:14:00.890] Expected: c741a6f3476df9f7051649747915014991fb1693a63114f9c8774552522107fd                                           
[2024-08-09 15:14:00.891] Attempting to boot anyway...                                                                                         
[2024-08-09 15:14:00.891] entry 0x4086c410                                                                                                     
[2024-08-09 15:14:00.891] I (45) boot: ESP-IDF v5.1.2-dirty 2nd stage bootloader                                                               
[2024-08-09 15:14:00.892] I (46) boot: compile time Aug  9 2024 11:05:27                                                                       
[2024-08-09 15:14:00.892] I (47) boot: chip revision: v0.0                                                                                     
[2024-08-09 15:14:00.892] I (49) boot.esp32c6: SPI Speed      : 80MHz                                                                          
[2024-08-09 15:14:00.892] I (53) boot.esp32c6: SPI Mode       : DIO                                                                            
[2024-08-09 15:14:00.892] I (58) boot.esp32c6: SPI Flash Size : 4MB                                                                            
[2024-08-09 15:14:00.893] I (63) boot: Enabling RNG early entropy source...                                                                    
[2024-08-09 15:14:00.893] I (68) boot: Partition Table:                                                                                        
[2024-08-09 15:14:00.894] I (72) boot: ## Label            Usage          Type ST Offset   Length                                              
[2024-08-09 15:14:00.895] I (79) boot:  0 otadata          OTA data         01 00 0000d000 00002000                                            
[2024-08-09 15:14:00.895] I (87) boot:  1 phy_init         RF data          01 01 0000f000 00001000                                            
[2024-08-09 15:14:00.895] I (94) boot:  2 nvs              WiFi data        01 02 00010000 0000e000                                            
[2024-08-09 15:14:00.896] I (101) boot:  3 at_customize     unknown          40 00 0001e000 00042000                                           
[2024-08-09 15:14:00.896] I (109) boot:  4 ota_0            OTA app          00 10 00060000 001d0000                                           
[2024-08-09 15:14:00.896] I (117) boot:  5 ota_1            OTA app          00 11 00230000 001d0000                                           
[2024-08-09 15:14:00.896] I (124) boot: End of partition table                                                                                 
[2024-08-09 15:14:00.896] I (129) esp_image: segment 0: paddr=00060020 vaddr=42150020 size=30670h (198256) map                                 
[2024-08-09 15:14:00.897] I (218) esp_image: segment 1: paddr=00090698 vaddr=40800000 size=0f980h ( 63872) load                                
[2024-08-09 15:14:00.897] I (249) esp_image: segment 2: paddr=000a0020 vaddr=42000020 size=1488d4h (1345748) map                               
[2024-08-09 15:14:00.897] I (797) esp_image: segment 3: paddr=001e88fc vaddr=4080f980 size=0a0e4h ( 41188) load                                
[2024-08-09 15:14:00.897] I (818) esp_image: segment 4: paddr=001f29e8 vaddr=40819a70 size=03bc4h ( 15300) load                                
[2024-08-09 15:14:00.898] I (826) esp_image: segment 5: paddr=001f65b4 vaddr=50000000 size=00068h (   104) load                                
[2024-08-09 15:14:00.898] I (839) boot: Loaded app from partition at offset 0x60000                                                            
[2024-08-09 15:14:00.899] I (840) boot: Disabling RNG early entropy source...                                                                  
[2024-08-09 15:14:00.899] no external 32k oscillator, disable it now.                                                                          
[2024-08-09 15:14:00.899] at param mode: 1                                                                                                     
[2024-08-09 15:14:00.899] AT cmd port:uart1 tx:7 rx:6 cts:5 rts:4 baudrate:115200                                                              
[2024-08-09 15:14:00.900] module_name: ESP32C6-4MB                                                                                             
[2024-08-09 15:14:00.900] max tx power=78, ret=0                                                                                               
[2024-08-09 15:14:00.900] v4.1.0.0-dev                                                                                                         
[2024-08-09 15:14:00.901] BLUFI BLE is not connected yet                                                                                       
[2024-08-09 15:14:00.901] negotiated phy mode: 3                                                                                               
[2024-08-09 15:14:00.901] 192.168.11.250                                                                                                       
[2024-08-09 15:14:00.902] BLUFI BLE is not connected yet                                                                                       
[2024-08-09 15:14:00.902] negotiated phy mode: 3                                                                                               
[2024-08-09 15:14:00.902] wifi disconnected, rc:8                                                                                              
[2024-08-09 15:14:00.902] ESP-ROM:esp32c6-20220919                                                                                             
[2024-08-09 15:14:00.903] Build:Sep 19 2022                                                                                                    
[2024-08-09 15:14:00.903] rst:0xc (SW_CPU),boot:0xc (SPI_FAST_FLASH_BOOT)                                                                      
[2024-08-09 15:14:00.903] Saved PC:0x4001975a                                                                                                  
[2024-08-09 15:14:00.903] SPIWP:0xee                                                                                                           
[2024-08-09 15:14:00.904] mode:DIO, clock div:1                                                                                                
[2024-08-09 15:14:00.904] load:0x4086c410,len:0xd2c                                                                                            
[2024-08-09 15:14:00.904] load:0x4086e610,len:0x2df0                                                                                           
[2024-08-09 15:14:00.904] load:0x40875728,len:0x17d8                                                                                           
[2024-08-09 15:14:00.905] SHA-256 comparison failed:                                                                                           
[2024-08-09 15:14:00.905] Calculated: 63045dfae877bfe6aba67856cf9cd56b6defbda508cb8a0274419830fbca4e24                                         
[2024-08-09 15:14:00.905] Expected: c741a6f3476df9f7051649747915014991fb1693a63114f9c8774552522107fd                                           
[2024-08-09 15:14:00.906] Attempting to boot anyway...                                                                                         
[2024-08-09 15:14:00.906] entry 0x4086c410                                                                                                     
[2024-08-09 15:14:00.906] I (45) boot: ESP-IDF v5.1.2-dirty 2nd stage bootloader                                                               
[2024-08-09 15:14:00.907] I (46) boot: compile time Aug  9 2024 11:05:27                                                                       
[2024-08-09 15:14:00.908] I (47) boot: chip revision: v0.0                                                                                     
[2024-08-09 15:14:00.908] I (49) boot.esp32c6: SPI Speed      : 80MHz                                                                          
[2024-08-09 15:14:00.909] I (53) boot.esp32c6: SPI Mode       : DIO                                                                            
[2024-08-09 15:14:00.909] I (58) boot.esp32c6: SPI Flash Size : 4MB                                                                            
[2024-08-09 15:14:00.909] I (63) boot: Enabling RNG early entropy source...                                                                    
[2024-08-09 15:14:00.910] I (68) boot: Partition Table:                                                                                        
[2024-08-09 15:14:00.910] I (72) boot: ## Label            Usage          Type ST Offset   Length                                              
[2024-08-09 15:14:00.910] I (79) boot:  0 otadata          OTA data         01 00 0000d000 00002000                                            
[2024-08-09 15:14:00.910] I (87) boot:  1 phy_init         RF data          01 01 0000f000 00001000                                            
[2024-08-09 15:14:00.911] I (94) boot:  2 nvs              WiFi data        01 02 00010000 0000e000                                            
[2024-08-09 15:14:00.911] I (101) boot:  3 at_customize     unknown          40 00 0001e000 00042000                                           
[2024-08-09 15:14:00.911] I (109) boot:  4 ota_0            OTA app          00 10 00060000 001d0000                                           
[2024-08-09 15:14:00.911] I (117) boot:  5 ota_1            OTA app          00 11 00230000 001d0000                                           
[2024-08-09 15:14:00.911] I (124) boot: End of partition table                                                                                 
[2024-08-09 15:14:00.911] I (129) esp_image: segment 0: paddr=00060020 vaddr=42150020 size=30670h (198256) map                                 
[2024-08-09 15:14:00.912] I (218) esp_image: segment 1: paddr=00090698 vaddr=40800000 size=0f980h ( 63872) load                                
[2024-08-09 15:14:00.912] I (249) esp_image: segment 2: paddr=000a0020 vaddr=42000020 size=1488d4h (1345748) map                               
[2024-08-09 15:14:00.912] I (797) esp_image: segment 3: paddr=001e88fc vaddr=4080f980 size=0a0e4h ( 41188) load                                
[2024-08-09 15:14:00.912] I (818) esp_image: segment 4: paddr=001f29e8 vaddr=40819a70 size=03bc4h ( 15300) load                                
[2024-08-09 15:14:00.912] I (826) esp_image: segment 5: paddr=001f65b4 vaddr=50000000 size=00068h (   104) load                                
[2024-08-09 15:14:00.912] I (839) boot: Loaded app from partition at offset 0x60000                                                            
[2024-08-09 15:14:00.912] I (840) boot: Disabling RNG early entropy source...                                                                  
[2024-08-09 15:14:00.913] no external 32k oscillator, disable it now.                                                                          
[2024-08-09 15:14:00.913] at param mode: 1                                                                                                     
[2024-08-09 15:14:00.913] AT cmd port:uart1 tx:7 rx:6 cts:5 rts:4 baudrate:115200                                                              
[2024-08-09 15:14:00.913] module_name: ESP32C6-4MB                                                                                             
[2024-08-09 15:14:00.913] max tx power=78, ret=0                                                                                               
[2024-08-09 15:14:00.913] v4.1.0.0-dev                                                                                                         
[2024-08-09 15:14:00.913] BLUFI BLE is not connected yet                                                                                       
[2024-08-09 15:14:00.914] negotiated phy mode: 3                                                                                               
[2024-08-09 15:14:00.914] wifi disconnected, rc:8                                                                                              
[2024-08-09 15:14:00.914]

More Information.

No response

Luxin812 commented 2 months ago

Hi,

It is recommended not to set the parameter of the AT+CWDHCP command to 0, as this value is not supported. If you want to disable DHCP in station mode, please use AT+CWDHCP=0,1. To disable DHCP in softAP mode, use AT+CWDHCP=0,2. If you need to disable DHCP in both station and softAP modes, use AT+CWDHCP=0,3. If you want to enable DHCP in station mode, set it to AT+CWDHCP=1,1. I hope this information is helpful to you.

JavierReyes945 commented 2 months ago

@Luxin812 Thank you for the recommendation. I have tried as you suggested it and works now.

As feedback for maintainers of the repository, official documentation https://docs.espressif.com/projects/esp-at/en/latest/esp32c6/AT_Command_Set/Wi-Fi_AT_Commands.html#at-cwdhcp-enable-disable-dhcp should be updated, as the way it is shown, the parameters for the Set Command are:

Set Command

Function:
Enable/disable DHCP.

Command:
AT+CWDHCP=<operate>,<mode>

Parameters
    <operate>:
        0: disable
        1: enable
    <mode>:
        Bit0: Station DHCP
        Bit1: SoftAP DHCP

But after your feedback, it is clear that the second parameter mode of the Set Command works as documented for the Query Command:

Query Command

Command:
AT+CWDHCP?

Response:
+CWDHCP:<state>
OK

Parameters
    <state>: the status of DHCP
        Bit0:
            0: Station DHCP is disabled.
            1: Station DHCP is enabled.
        Bit1:
            0: SoftAP DHCP is disabled.
            1: SoftAP DHCP is enabled.
        Bit2:
            0: Ethernet DHCP is disabled.
            1: Ethernet DHCP is enabled.