From 535309233292631d6b84bbf4ef43c0f0bd1e225f Mon Sep 17 00:00:00 2001 From: mlafauci Date: Wed, 8 Jun 2011 00:54:14 +0200 Subject: [PATCH] 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. --- WiFi/WiFi.cpp | 11 +++++------ WiFi/WiFi.h | 2 +- .../Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/WiFi/WiFi.cpp b/WiFi/WiFi.cpp index a7ccc2047..3ed9d686c 100755 --- a/WiFi/WiFi.cpp +++ b/WiFi/WiFi.cpp @@ -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) { diff --git a/WiFi/WiFi.h b/WiFi/WiFi.h index 27380b9d2..ac88bd02a 100755 --- a/WiFi/WiFi.h +++ b/WiFi/WiFi.h @@ -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]; diff --git a/WiFi/examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino b/WiFi/examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino index 5a85b98a6..87c5ffe02 100644 --- a/WiFi/examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino +++ b/WiFi/examples/Wifi_Open_ScanNetworks/Wifi_Open_ScanNetworks.ino @@ -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");