Skip to content
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

Setting a DNS address manually breaks hostByName(). #78

Open
iabdalkader opened this issue Jan 4, 2022 · 1 comment
Open

Setting a DNS address manually breaks hostByName(). #78

iabdalkader opened this issue Jan 4, 2022 · 1 comment

Comments

@iabdalkader
Copy link
Contributor

iabdalkader commented Jan 4, 2022

Please see the attached sketch which reproduces the issue. This is the output with and without a manual DNS address:

// With default/GW DNS address.
00:37:09.929 -> Attempting to connect to SSID: ***
00:37:22.549 -> Connected to WiFi
00:37:22.615 -> IP Address: 142.251.37.196

// With manual DNS address.
00:36:10.968 -> Attempting to connect to SSID: ***
00:36:23.673 -> Connected to WiFi
00:36:23.673 -> Setting DNS address
00:36:30.672 -> IP Address: 0.0.0.0

Sketch:

#include <SPI.h>
#include <WiFiNINA.h>
#include "arduino_secrets.h" 
char ssid[] = SECRET_SSID;     // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)

WiFiClient client;
int status = WL_IDLE_STATUS;
char server[] = "www.google.com";    // name address for Google (using DNS)

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  
  Serial.println("Connected to WiFi");
  
  Serial.println("Setting DNS address");
  WiFi.config(IPAddress(192, 168, 1, 200), IPAddress(8, 8, 8, 8));
    
  IPAddress host_ip;
  WiFi.hostByName("www.google.com", host_ip);
  Serial.print("IP Address: ");
  Serial.println(host_ip);
}

void loop() {
  // do nothing forevermore:
  while (true);
}
@iabdalkader
Copy link
Contributor Author

So it seems the issue is that the validParams is ignored in the firmware, which means in my sketch above gateway and and subnet mask are set to 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant