Skip to content

Feature Request: Configurable WiFi Connection Delay #73

@barcaroandrea

Description

@barcaroandrea

Hi,
do you think it's possible adding ability to configure a delay before attempting WiFi connection (es. 0-300s)?
Useful for:

Description:
Add the ability to configure a delay before attempting WiFi connection in Station mode.

Use Case:
Waiting for router to be ready after power cycle (for example router powered by the same power source of the XBee).

Proposed Implementation:

  • Add a configurable parameter in the WiFi Station settings (web interface)
  • Store the delay value (0-300 seconds) in NVS
  • Implement the delay before calling wifi_connect()
  • Display countdown in serial monitor (optional)

Benefits:

  • Increases reliability in unstable power scenarios
  • Provides more control over connection timing
  • Maintains backward compatibility (default: 0 seconds = immediate connection)

The code Claude is suggesting to modify (not tested)

main/include/config.h - Add the new configuration:

// Add to the config_t structure
typedef struct {
    // ... other existing configurations
    uint16_t wifi_connect_delay;  // Delay in seconds before WiFi connection
} config_wifi_sta_t;

main/config.c - Handle save/load configuration:

// In the WiFi configuration load/save function
config->wifi_sta.wifi_connect_delay = nvs_get_u16(handle, "wifi_delay", 0);
nvs_set_u16(handle, "wifi_delay", config->wifi_sta.wifi_connect_delay);

main/wifi.c - Implement the delay:

void wifi_connect() {
    if (config.wifi_sta.wifi_connect_delay > 0) {
        ESP_LOGI(TAG, "Waiting %d seconds before WiFi connection...", 
                 config.wifi_sta.wifi_connect_delay);
        
        // Optional: Display countdown
        for (int i = config.wifi_sta.wifi_connect_delay; i > 0; i--) {
            ESP_LOGI(TAG, "Connecting in %d seconds...", i);
            vTaskDelay(1000 / portTICK_PERIOD_MS);
        }
    }
    
    // Existing connection code continues here
}

www/index.html - Add the field in the web interface:

<!-- In the WiFi Station section -->
<div class="form-group">
    <label for="wifi_delay">Connection Delay (seconds)</label>
    <input type="number" id="wifi_delay" name="wifi_delay" 
           min="0" max="300" value="0">
    <small>Wait before connecting to WiFi (0-300 seconds)</small>
</div>

main/http_server.c - Handle the POST parameter:

// In the POST handler for WiFi configuration save
if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
    char delay_str[4];
    if (httpd_query_key_value(buf, "wifi_delay", delay_str, sizeof(delay_str)) == ESP_OK) {
        int delay = atoi(delay_str);
        // Validate input (0-300 seconds)
        if (delay < 0) delay = 0;
        if (delay > 300) delay = 300;
        config.wifi_sta.wifi_connect_delay = delay;
    }
}

I'm new in Github, thank you for this project and attention, have a nice day.
Andrea

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions