Go Down

Topic: WiFiClient.connect to a web site fails (Read 1 time) previous topic - next topic

St3v3C

I'm trying to connect to Dweet.io (or any web site) with the WiFi Rev 2 board. I have connection to my local  WiFi but connect to an external page fails. Any idea what my problem is?

Here's a sample:
Code: [Select]

#include <SPI.h>
#include <WiFiNINA.h>
#include "ArdUtils.h"
#include "WiFi_secrets.h"

const char* ssid = SECRET_SSID;
const char* pass = SECRET_PASS;
IPAddress ip(192, 168, 1, 50); 
WiFiClient client;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.print("Start...");
 
  //connectToWiFi();
  WiFi.setHostname("UnoWifiRev2"); // Doesn't work. Router says name is arduino-eb3c
  WiFi.config(ip);
  if (WiFi.begin(ssid, pass))
  {
    Serial.print(F("Connected to "));
    Serial.println(WiFi.localIP());
  }
  else
  {
   Serial.println(F("Could not connect to network"));
  }

  if (!client.connect("dweet.io", 80)) // http://34.202.255.213/
  //if (!client.connect("34.202.255.213", 80))
  //if (!client.connect("google.com", 80))
    Serial.println("Dweet Connection failed");
  else
    Serial.println("Connected to Dweet");
}

void loop()
{
  // put your main code here, to run repeatedly:
  blinkLedNoDelay();
}




St3v3C

Oh it looks like I answered by own question! I had to add the full WiFi.config() like this:

Code: [Select]

IPAddress ip(192, 168, 1, 50); 
IPAddress dns(8, 8, 8, 8);  //Google dns 
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

...
Code: [Select]

 WiFi.config(ip, dns, gateway, subnet);
  if (WiFi.begin(ssid, pass))
  {...




Then client.connect() works and the connection to Dweet.io functions.

Go Up