1

I have problems with the Wi-Fi shield example code.

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "*****";          //  your network SSID (name) 
char pass[] = "*****";   // your network password

int status = WL_IDLE_STATUS;
char servername[]="google.com";  // remote server we will connect to

WiFiClient client;

void setup() {
    Serial.begin(9600);
    //disable SD SPI
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);

    Serial.println("Attempting to connect to WPA network...");
    Serial.print("SSID: ");
    Serial.println(ssid);

    status = WiFi.begin(ssid, pass);
    if ( status != WL_CONNECTED) { 
        Serial.println("Couldn't get a wifi connection");
        // don't do anything else:
        while(true);
        } 
     else {
     Serial.println("Connected to wifi");
     Serial.println("\nStarting connection...");
     // if you get a connection, report back via serial:
     if (client.connect(servername, 80)) {
         Serial.println("connected");
         // Make a HTTP request:
         client.println("GET /search?q=arduino HTTP/1.0");
         client.println();
      }
    }
}

 void loop() {

}

The Wi-Fi Shield has connected with the internet Wi-Fi, but the last printing was "Starting connection..." I can't get to connect to (google.com), why?

1
  • insert a Serial.println(status); and which WL_status is returned? Did it actually connect (WL_CONNECTED) or is it some other result?
    – Madivad
    May 13 '14 at 11:18
2

Have you upgraded the firmware in your wifi shield? If not, it will have problems connecting. Compile and upload this sketch. If it shows the firmware version as 1.0.0, then you need to upgrade the firmware. If it shows 1.1.0, then it is current as of today.

#include <SPI.h>
#include <WiFi.h>

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

  Serial.print("Firmware version: ");
  Serial.println(WiFi.firmwareVersion());
}

void loop() {}

Please Note: The chips are numbered differently but run the same Wi-Fi firmware. You can upgrade the firmware without any worries.

0

I had this problem aswell. The problem was a bug with the official editor of arduino. I fixed this by downgrading the editor to version 1.0.3. (from 1.0.5) You can find a download link for it at the Arduino website.

Hope this helped!
-Kad

0
#include <WiServer.h>

#define WIRELESS_MODE_INFRA 1
//#define WIRELESS_MODE_ADHOC   2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {146, 227, 174, 29};      // Indirizzo IP
unsigned char gateway_ip[] = {146, 227, 175, 254};      // Indirizzo gateway IP
unsigned char subnet_mask[] = {255, 255, 248, 0};   // Subnet Mask
const prog_char ssid[] PROGMEM = {"enduroam"};      // SSID access point

unsigned char security_type = 3;    // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"EAP-MSCHAP V2"};  // max 64 characters
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {

    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("Hello World!");
        WiServer.print("</html>");

        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}


void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);

  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}

void loop(){

  // Run WiServer
  WiServer.server_task();

  delay(10);
}
1
  • 2
    Please add information about your code: what does it do? how does it work?
    – sachleen
    Jul 16 '14 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy