#include <WiFi.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;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
// IPAddress server(93,184,216,34); // IP address for example.com (no DNS)
char server[] = "example.com"; // host name for example.com (using DNS)
WiFiClient client;
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_SHIELD) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
// 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 3 seconds for connection:
delay(3000);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /index.html HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true);
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
I believe that the firmware has been updated properly.
But still, a problem exists, When I try to re-upload the Wi-Fi web client sketch from the Nicla vision examples(with proper SSID and pass) to Nicla vision, It is not connecting to the wifi.
It attempts a lot for connection but its not happening at all. [The below image shows the output from serial monitor]
Sounds like you're doing everything well on the board side.
Your code checks out, just as well as your wifi update, and the printout you are getting while trying to connect.
Unless there is some critical damage to your module, I can't really see what could be wrong, could be a safety feature on your routers/hotspots or some weird character in your SSID or Password. Other than that , I would try:
1: Making sure the Arduino board on the boards manager is updated
2: Updating the Wifi again (just in case)
3: Trying to connect using IP rather than DNS
4: Disarming any firewalls that might be hindering connection
If none of these work, I'd try and contact some customer service and ask for a replacement/buy a new one.
ok forget what I said. getting a connection is a gamble. Somtimes it works somtimes not.
Currently I get a very strange output, when I try to scan for all available networks.
Hi, I have the same problem with my Nicla Vision and the WiFi.h library. I tried the same code with a Nano 33 IoT and the WiFiNina.h library and works like a charm. I also updated the firmware as described above, but problem is still there: message, connection failed.
Hi, i didn't solve the problem yet. Was well assisted by Arduino support and received a new board as well. First tests just had the same problem, so continued with different HW setup and once have some time left will experiment again. BTW found out that every now and then it connects ... but very rarely.
Same code, different days, I can't connect anymore, no way...before nicla Vision connects also if rarely. I've updated again all: bootloader, firmware and attempting for hours...