arduino-libraries / WiFiNINA

136 stars 105 forks source link

Static IP config not working (v1.8.14) #280

Closed Wout-VDWG closed 3 months ago

Wout-VDWG commented 3 months ago

This issue seems similar to #5 , but since that issue is 6 years old and based on v1.0, I would assume it is unrelated.

In short, I am trying to set a static IP, without relying on DHCP. The address in this code is not in use by any other client on the network. My code:

#include <WiFiNINA.h>

const char* ssid = "xxx";
const char* pass = "xxx";
IPAddress ip(192, 168, 0, 250);
int status = WL_IDLE_STATUS;

WiFi.config(ip);

void setup() {
  Serial.begin(9600);

  // attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.print("Connected to WiFi, IP address: ");
  Serial.println(WiFi.localIP());
}

Result: Connected to WiFi, IP address: 192.168.0.216 So the config get ignored completely, and the IP comes from DHCP.

If I set WiFi.config(ip) AFTER the while-loop: Result: Connected to WiFi, IP address: 192.168.0.250 This seems correct, BUT! This reading is incorrect. The ACTUAL ip is still .216 from DHCP, NOT .250. WiFi.localIP() is misleading here.

It seems impossible to set a static IP. Also, the behavior of WiFi.localIP() seems bugged.

Wout-VDWG commented 3 months ago

My bad, I am new to Arduino and didn't realize the difference between firmware version and library version. The key was to update the firmware to at least 1.1.0, it works correctly now.