Skip to content

IP networking not working with static IP address and manual BSSID configuration #1305

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
francescolavra opened this issue Apr 10, 2018 · 3 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@francescolavra
Copy link

Hardware:

Board: ESP32_Core_board_V2
Core Installation/update date: 10/apr/2018
IDE name: Arduino IDE
Flash Frequency: 80Mhz
Upload Speed: 115200

Description:

A Wi-Fi network is set up with two access points using the same SSID; each access point is configured to use a different subnet (10.38.0.0/255.255.255.0 for the first access point, with IP address 10.38.0.1, 10.38.1.0/255.255.255.0 for the second access point, with IP address 10.38.1.1). Each access point runs a TCP server listening at port 5555.
ESP32 is configured to connect to one of the 2 access points by specifying the corresponding BSSID, and is set up with a static IP address. After a Wi-Fi connection, ESP32 connects to the TCP server running in the current access point. A procedure is also in place to make ESP32 switch from one access point to the other (reconfiguring the static IP address so that it belongs to the same subnet as the access point being connected to).
The problem is that upon switching access point, most of the times ESP32 is unable to connect to the TCP server (the errno value set by lwip_connect_r() is 113, which means "no route to host").
Sometimes it works, but most of the times the TCP connection attempt fails with the above errno (the Wi-Fi connection is always successful); and when it fails, any subsequent attempts to connect fail as well.
The sketch below, which reproduces the problem, switches from one access point to the other when something is received on the serial port.
I also noticed that if I reset the board (with the hardware reset button) when the ESP32 is configured to connect to access point #0, at the next reboot most of the times it is unable to connect to the TCP server of access point #1 (which is the first access point chosen by ESP32 after a reset); if I reset again, it can successfully connect; so it seems the last configuration before the reset affects the ability of the ESP32 to connect after the reset.

Sketch:

#include <esp_wifi.h>
#include <WiFi.h>

static int currentAP;

static void switchAP()
{
  WiFi.disconnect(false);
  currentAP = !currentAP;
  uint8_t bssid[6];
  if (currentAP == 0) {
    bssid[0] = 0x24;
    bssid[1] = 0x0a;
    bssid[2] = 0xc4;
    bssid[3] = 0x04;
    bssid[4] = 0x26;
    bssid[5] = 0x05;
  }
  else {
    bssid[0] = 0x24;
    bssid[1] = 0x0a;
    bssid[2] = 0xc4;
    bssid[3] = 0x04;
    bssid[4] = 0x25;
    bssid[5] = 0x01;
  }
  if (!WiFi.config(IPAddress(10, 38, currentAP, 2),
      IPAddress(10, 38, currentAP, 1), IPAddress(255, 255, 255, 0))) {
    Serial.println("STA Failed to configure");
  }
  WiFi.begin("mySSID", "myPWD", 4, bssid, true);
}

void setup() {
  Serial.begin(115200);
  switchAP();
}

void loop() {
  static wl_status_t wifi_status;

  if (WiFi.status() != wifi_status) {
    wifi_status = WiFi.status();
    Serial.printf("WiFi status: %d\r\n", wifi_status);
    if (wifi_status == WL_CONNECTED) {
      Serial.println("WiFi connected");
      WiFiClient client;
      IPAddress server(10, 38, currentAP, 1);
      if (client.connect(server, 5555)) {
        Serial.println("TCP connected");
      }
      else {
        Serial.println("TCP error");
      }
    }
  }
  if (Serial.available()) {
    do {
      Serial.read();
    } while (Serial.available());
    switchAP();
  }
}
@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
@policeman0077
Copy link

any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

2 participants