mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
Moved WiFi driver initialization to default constructor
Moved scanNetworks in the example before wifi connection setup in order to show the list of possible WiFi APs.
This commit is contained in:
parent
f98da1ba55
commit
5353092332
@ -21,6 +21,8 @@ wl_status_t WiFiClass::_status;
|
||||
|
||||
WiFiClass::WiFiClass()
|
||||
{
|
||||
// Driver initialization
|
||||
init();
|
||||
}
|
||||
|
||||
void WiFiClass::init()
|
||||
@ -42,7 +44,8 @@ uint8_t WiFiClass::getSocket()
|
||||
|
||||
int WiFiClass::begin()
|
||||
{
|
||||
init();
|
||||
// Add procedure to read the latest configuration from eeprom/dataflash
|
||||
// and start the wifi connection
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid)
|
||||
@ -50,8 +53,6 @@ int WiFiClass::begin(char* ssid)
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
|
||||
|
||||
begin();
|
||||
|
||||
if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE)
|
||||
{
|
||||
do
|
||||
@ -72,8 +73,7 @@ int WiFiClass::begin(char* ssid, uint8_t key_idx, const char *key)
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
|
||||
|
||||
begin();
|
||||
// set encryption key
|
||||
// set encryption key
|
||||
if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE)
|
||||
{
|
||||
do
|
||||
@ -93,7 +93,6 @@ int WiFiClass::begin(char* ssid, const char *passphrase)
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
|
||||
|
||||
begin();
|
||||
// set passphrase
|
||||
if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ private:
|
||||
static char _passph[WL_WPA_KEY_MAX_LENGTH];
|
||||
static wl_status_t _status;
|
||||
|
||||
void init();
|
||||
static void init();
|
||||
public:
|
||||
static int16_t _state[MAX_SOCK_NUM];
|
||||
static uint16_t _server_port[MAX_SOCK_NUM];
|
||||
|
@ -28,7 +28,11 @@ IPAddress subnet; // the subnet mask
|
||||
void setup() {
|
||||
// initialize serial:
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// scan for existing networks:
|
||||
Serial.println("Scanning available networks...");
|
||||
scanNetworks();
|
||||
|
||||
// attempt to connect using WEP encryption:
|
||||
Serial.println("Attempting to connect to open network...");
|
||||
status = WiFi.begin(ssid);
|
||||
@ -36,10 +40,6 @@ void setup() {
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
|
||||
// scan for existing networks:
|
||||
Serial.println("Scanning available networks...");
|
||||
scanNetworks();
|
||||
|
||||
// if you're not connected, stop here:
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
|
Loading…
x
Reference in New Issue
Block a user