Arduino Wifi Shield没有通信

时间:2013-06-02 13:11:24

标签: arduino

我的项目是一款用Android控制的Arduino遥控车。为此我买了Arduino Uno R3和Arduino WiFi shield。问题是wifiShield没有监听客户端而无法接收数据。我不知道如何解决问题,也无法在设备之间建立连接。

Arduino代码:

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);
        }
    }
}

什么可能导致我的问题,我该如何解决?

2 个答案:

答案 0 :(得分:3)

有这个完全相同的问题。确保你使用的是Arduino 1.0.3而不是1.0.5,这就是为我做的:)

答案 1 :(得分:0)

我可以确认使用Arduino IDE 1.0.5 WiFi盾无效。使用1.0.3它可以正常工作。