Skip to content

Activating static IP makes WiFi.status() return WL_CONNECTED #6191

Closed
@aerlon

Description

@aerlon

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: Latest Git as of 2019-06-10
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: NodeMCU 1.0
  • Flash Mode: dio
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

The changes made in PR #6026 by @d-a-v makes WiFi.status() == WL_CONNECTED become true whenever one activates static IP via WiFi.config. This was not the case before the change, and it also seems strange that the status would be connected even when no connection has been made, so it is likely a bug. Calling WiFi.disconnect() after static IP activation makes WiFi.status() return 0 (WL_IDLE_STATUS), as was the case before the PR change.

MCVE Sketch

#include <ESP8266WiFi.h>

void activateStaticIP()
{
  // WiFi mode does not matter 
  WiFi.mode(WIFI_STA);
  //WiFi.mode(WIFI_AP_STA); 
  
  WiFi.config(IPAddress(192,168,4,22), IPAddress(192,168,4,1), IPAddress(255,255,255,0)); 
}

void setup() {
  // put your setup code here, to run once:

  WiFi.persistent(false);
  
  Serial.begin(115200);
  delay(50); // Wait for Serial.

  Serial.println();
  Serial.println();

  WiFi.disconnect();
    
  activateStaticIP();
}

void loop() {
  // put your main code here, to run repeatedly:
  
  Serial.print("status pre " + String(WiFi.status()));
  if(WiFi.status() == WL_CONNECTED)
    Serial.println(", this means WiFi.status() == WL_CONNECTED");
  else
    Serial.println();
    
  WiFi.disconnect(); // Adding this disconnect seems to fix WiFi status.
  Serial.println("status post " + String(WiFi.status()));

  delay(3000);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions