arduino-libraries / WiFiNINA

136 stars 105 forks source link

WiFi Rev 2 - connecting to local network? #61

Closed kunwookimm closed 5 years ago

kunwookimm commented 5 years ago

I am using Airport Extreme Base Station as a WLAN router. I wanted to add my Arduino Uno WiFi rev 2 units to this local area network. When the router is connected to internet via ethernet cable to router from the wall, the Arduinos using WiFiNINA establish connection reliably.

However, when the router is disconnected from the internet to create a WLAN, my Arduinos keep repeating "Attempting to connect to SSID: XXXXXX", and never establishes connection. I am using WiFiUdpSendReceiveString example. I want to have Arduinos communicating in local network environment, so that latencies are faster and more reliable.

I am a noob in networking, and searched a lot of information. Things I have tried:

Please help! This is very important to me.

#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>

int status = WL_IDLE_STATUS;
#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/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)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

unsigned int localPort = 2390;      // local port to listen on
unsigned int sendPort = 2391; // local port to send msg

char packetBuffer[255]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged";       // a string to send back

IPAddress ip(192, 168, 0, 177);
WiFiUDP Udp;

void setup() {
  //Initialize serial and wait for port to open:
  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 < "1.0.0") {
    Serial.println("Please upgrade the firmware");
  }

  //WiFi.end();
  //WiFi.disconnect();
  WiFi.config(ip);

  // 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);

    //Serial.println(status);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  Udp.begin(localPort);

  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
    clock_prescale_set(clock_div_1);
  #endif
    // END of Trinket-specific code.
  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  blinkLights();
}

void loop() {
...
}
kunwookimm commented 5 years ago

[Solved] I changed the router to EERO and local network works! It wasn't compatible with the old AirPort Extreme, that's all.