Apple Mac OS
Arduino IDE 2.2.1,
Arduino Uno WiFi rev 2,
Arduino Motor Shield rev3
WiFiNINA.h version 1.8.14
Please take a look at the following, pretty much identical, files, and their respective outputs;
Program 1:
#include <WiFiNINA.h>
#define STD_WiFiBegin_Delay 10000
//char ssid = "abc";
//char wifiPassword = "12345";
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
Serial.println("entering clientConnect.ino");
Serial.print("pre-network scan= ");
Serial.print(millis());
Serial.println(" milliseconds");
Serial.print("number of networks scanned = ");
Serial.println(WiFi.scanNetworks()); //Scans for available WiFi networks and returns the discovered number
/*Syntax
WiFi.scanNetworks()
Parameters
None
Returns
byte : number of discovered networks
*/
Serial.print("Pre WiFi.begin ");
Serial.print(millis());
Serial.println(" milliseconds");
WiFi.begin("abc", "12345");
//WiFi.begin(ssid, wifiPassword);
/*Initializes the WiFiNINA library’s network settings and provides the current status.
(Apparently it does not create the IP connection.)
Syntax
WiFi.begin(ssid);
WiFi.begin(ssid, pass);
WiFi.begin(ssid, keyIndex, key);
Parameters
ssid: the SSID (Service Set Identifier) is the name of the WiFi network you want to connect to.
keyIndex: WEP encrypted networks can hold up to 4 different keys. This identifies which key you are going to use.
key: a hexadecimal string used as a security code for WEP encrypted networks.
pass: WPA encrypted networks use a password in the form of a string for security.
Returns
WL_CONNECTED when connected to a network
WL_IDLE_STATUS when not connected to a network, but powered on
*/
delay(STD_WiFiBegin_Delay);
Serial.print("clientConnect.ino Post WiFi.begin ");
Serial.print(millis());
Serial.println(" milliseconds");
//Serial.print("number of networks scanned = ");
//Serial.println(WiFi.scanNetworks()); //Scans for available WiFi networks and returns the discovered number
/*Syntax
WiFi.scanNetworks()
Parameters
None
Returns
byte : number of discovered networks
*/
while (WiFi.status() != WL_CONNECTED) {//Return the connection status
// || !delay10sTimer.check()
/* WL_CONNECTED(3): assigned when connected to a WiFi network;
WL_AP_CONNECTED(8): assigned when a device is connected in Access Point mode;
WL_AP_LISTENING(7): assigned when the listening for connections in Access Point mode;
WL_NO_SHIELD(255): assigned when no WiFi shield is present;
WL_NO_MODULE(255): assigned when the communication with an integrated WiFi module fails;
WL_IDLE_STATUS(0): it is a temporary status assigned when WiFi.begin() is called and
remains active until the number of attempts expires (resulting
in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED);
WL_NO_SSID_AVAIL(1): assigned when no SSID are available;
WL_SCAN_COMPLETED(2): assigned when the scan networks is completed;
WL_CONNECT_FAILED(4): assigned when the connection fails for all the attempts;
WL_CONNECTION_LOST(5): assigned when the connection is lost;
WL_DISCONNECTED(6): assigned when disconnected from a network;
*/
delay(500);
//Serial.print(".");
Serial.print(WiFi.status());
Serial.print(" ");
} //while (WiFi.status() != WL_CONNECTED)
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
// put your main code here, to run repeatedly:
}
number of networks scanned = 7
Pre WiFi.begin
5259 milliseconds
clientConnect.ino Post WiFi.begin 16571 milliseconds
WiFi connected
Ln 93, Col 1
Arduino Uno WiFi Rev2
on /dev/cu.usbmodem221402
Program 2:
#include <WiFiNINA.h>
#define STD_WiFiBegin_Delay 10000
char ssid = "abc";
char wifiPassword = "12345";
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
Serial.println("entering clientConnect.ino");
Serial.print("pre-network scan= ");
Serial.print(millis());
Serial.println(" milliseconds");
Serial.print("number of networks scanned = ");
Serial.println(WiFi.scanNetworks()); //Scans for available WiFi networks and returns the discovered number
/*Syntax
WiFi.scanNetworks()
Parameters
None
Returns
byte : number of discovered networks
*/
Serial.print("Pre WiFi.begin ");
Serial.print(millis());
Serial.println(" milliseconds");
//WiFi.begin("abc", "12345");
WiFi.begin(ssid, wifiPassword);
/*Initializes the WiFiNINA library’s network settings and provides the current status.
(Apparently it does not create the IP connection.)
Syntax
WiFi.begin(ssid);
WiFi.begin(ssid, pass);
WiFi.begin(ssid, keyIndex, key);
Parameters
ssid: the SSID (Service Set Identifier) is the name of the WiFi network you want to connect to.
keyIndex: WEP encrypted networks can hold up to 4 different keys. This identifies which key you are going to use.
key: a hexadecimal string used as a security code for WEP encrypted networks.
pass: WPA encrypted networks use a password in the form of a string for security.
Returns
WL_CONNECTED when connected to a network
WL_IDLE_STATUS when not connected to a network, but powered on
*/
delay(STD_WiFiBegin_Delay);
Serial.print("clientConnect.ino Post WiFi.begin ");
Serial.print(millis());
Serial.println(" milliseconds");
//Serial.print("number of networks scanned = ");
//Serial.println(WiFi.scanNetworks()); //Scans for available WiFi networks and returns the discovered number
/*Syntax
WiFi.scanNetworks()
Parameters
None
Returns
byte : number of discovered networks
*/
while (WiFi.status() != WL_CONNECTED) {//Return the connection status
// || !delay10sTimer.check()
/* WL_CONNECTED(3): assigned when connected to a WiFi network;
WL_AP_CONNECTED(8): assigned when a device is connected in Access Point mode;
WL_AP_LISTENING(7): assigned when the listening for connections in Access Point mode;
WL_NO_SHIELD(255): assigned when no WiFi shield is present;
WL_NO_MODULE(255): assigned when the communication with an integrated WiFi module fails;
WL_IDLE_STATUS(0): it is a temporary status assigned when WiFi.begin() is called and
remains active until the number of attempts expires (resulting
in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED);
WL_NO_SSID_AVAIL(1): assigned when no SSID are available;
WL_SCAN_COMPLETED(2): assigned when the scan networks is completed;
WL_CONNECT_FAILED(4): assigned when the connection fails for all the attempts;
WL_CONNECTION_LOST(5): assigned when the connection is lost;
WL_DISCONNECTED(6): assigned when disconnected from a network;
*/
delay(500);
//Serial.print(".");
Serial.print(WiFi.status());
Serial.print(" ");
} //while (WiFi.status() != WL_CONNECTED)
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
// put your main code here, to run repeatedly:
}
pre-network scan= 0 milliseconds
number of networks scanned = 7
Pre WiFi.begin
5264 milliseconds
clientConnect.ino Post WiFi.begin 17679 milliseconds
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Ln 93, Col 1
Arduino Uno WiFi Rev2
on /dev/cu.usbmodem221402 [not connected]
As you can see, the only difference between these programs is which lines I've commented out. In the first, I specify ssid and wifiPassword explicitly, and I get a connection. In the second, ssid and wifiPassword are passed as global variables, and WiFi.begin() won't make the connection.
Is this a problem with WiFiNINA.h?