简体   繁体   中英

Arduino Wifi Shield is not communicating

My project is an Arduino RC car controlled with Android. For that I bought the Arduino Uno R3 and the Arduino WiFi shield . The problem is that the wifiShield not listening to the client and can't receive data. I don't know how to solve the problem, and cannot setup a connection between the devices.

Arduino Code:

char ssid[] = "***";         
char pass[] = "***";   
int status = WL_IDLE_STATUS;

WiFiServer server(1991);


boolean alreadyConnected = false; 

void setup() {
    Serial.begin(9600);
    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");
        while(true);
    } 
    else {
        server.begin();
        server.status();
        Serial.print("Connected to wifi. My address:");
        IPAddress myAddress = WiFi.localIP();
        IPAddress inetAddress=WiFi.gatewayIP();
        Serial.println( myAddress);

        Serial.println("Inet: ");
        Serial.println(inetAddress);
    }
}

void loop() {

    WiFiClient client = server.available();

    if(client) {
        if (!alreadyConnected) {

            client.flush();    
            Serial.println("We have a new client");
            client.println("Hello, client!"); 
            alreadyConnected = true;
        } 

        if (client.available() > 0) {
            // read the bytes incoming from the client:
            char thisChar = client.read();
            // echo the bytes back to the client:
            server.write(thisChar);
            // echo the bytes to the server as well:
            Serial.write(thisChar);
        }
    }
}

What might cause my problems and how can I solve them?

Had this EXACT same issue. Make sure you're using Arduino 1.0.3 instead of 1.0.5, that's what did it for me :)

I can just confirm that working with Arduino IDE 1.0.5 WiFi shield will not work. With 1.0.3 it work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM