My Arduino rp2040 connect don't connect to wifi. I checkt my SSID and password. I copy thann in connect my laptop scucesfully to the wifi. But with my Arduino rp2040 connect it only returns "WL_CONNECT_FAILED/4"
#include <SPI.h>
#include <WiFiNINA.h>
#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)
int status = WL_IDLE_STATUS;
WiFiServer server(80);
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
}
Serial.println("Access Point Web Server");
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
// set the LED pin mode
// 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);
Serial .println(status);
// wait 10 seconds for connection:
delay(10000);
}
server.begin();
// you're connected now, so print out the status:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop() {
// compare the previous status to the current status
if (status != WiFi.status()) {
// it has changed update the variable
status = WiFi.status();
if (status == WL_AP_CONNECTED) {
// a device has connected to the AP
Serial.println("Device connected to AP");
} else {
// a device has disconnected from the AP, and we are back in listening mode
Serial.println("Device disconnected from AP");
}
}
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("new client"); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
delayMicroseconds(10); // This is required for the Arduino Nano RP2040 Connect - otherwise it will loop so fast that SPI will never be served.
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("Click <a href=\"/RH\">here</a> turn the Red LED on<br>");
client.print("Click <a href=\"/RL\">here</a> turn the Red LED off<br>");
client.print("Click <a href=\"/GH\">here</a> turn the Green LED on<br>");
client.print("Click <a href=\"/GL\">here</a> turn the Green LED off<br>");
client.print("Click <a href=\"/BH\">here</a> turn the Blue LED on<br>");
client.print("Click <a href=\"/BL\">here</a> turn the Blue LED off<br>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
}
else { // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /RH")) {
digitalWrite(LEDR, HIGH); // GET /RH turns the LED on
}
if (currentLine.endsWith("GET /RL")) {
digitalWrite(LEDR, LOW); // GET /RL turns the LED off
}
if (currentLine.endsWith("GET /GH")) {
digitalWrite(LEDG, HIGH); // GET /GH turns the LED on
}
if (currentLine.endsWith("GET /GL")) {
digitalWrite(LEDG, LOW); // GET /GL turns the LED off
}
if (currentLine.endsWith("GET /BH")) {
digitalWrite(LEDB, HIGH); // GET /BH turns the LED on
}
if (currentLine.endsWith("GET /BL")) {
digitalWrite(LEDB, LOW); // GET /BL turns the LED off
}
}
}
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
// Both SSID and password must be 8 characters or longer
#define SECRET_SSID "myssid"
#define SECRET_PASS "mypassword"
that's the code i try but i didn't work. Sorry for my bad english i hope you could understand my problem ;D