//Connect to a WiFi network void startWiFi() { // attempt to connect to Wifi network: Serial.print("Attempting to connect to Network named: "); // print the network name (SSID); Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: //Serial.print("IP: "); //Serial.println(WiFi.localIP()); //if(WiFi.localIP() == INADDR_NONE) WiFi.beginNetwork(ssid, password); /* while ( WiFi.status() != WL_CONNECTED) { // print dots while we wait to connect Serial.print("."); delay(300); }*/ Serial.println("\nYou're connected to the network"); Serial.println("Waiting for an ip address"); while (WiFi.localIP() == INADDR_NONE) { // print dots while we wait for an ip addresss Serial.print("."); delay(300); } Serial.println("\nIP Address obtained"); // you're connected now, so print out the status: printWifiStatus(); alreadyConnectedMain = false; }
void setup() { Serial.begin(9600); while (!WiFi.ready()) { Serial.println("Waiting for WIFI connection..."); // wait 2 seconds for connection delay(10000); } Serial.println("Connected to wifi"); printWifiStatus(); }
void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); // 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 10 seconds for connection: delay(10000); } 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 /search?q=arduino HTTP/1.1"); client.println("Host:www.google.com"); client.println("Connection: close"); client.println(); } }
int wifiChat::tryConnect() { // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); // don't continue: return -2; } // attempt to connect to Wifi network: if(server.available() > 0) return 0; short numAttempts = 0; status = WiFi.status(); if(status == WL_CONNECTED) return 0; while ( status != WL_CONNECTED && numAttempts <= NUM_CONNECT_ATTEMPTS) { numAttempts++; Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); //CONNECTION METHOD // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(CONNECTION_DELAY); } // start the server: server.begin(); // you're connected now, so print out the status: printWifiStatus(); return 0; }