2013-06-02 54 views
1

我的项目是一个Arduino遥控车与Android控制。为此,我购买了Arduino Uno R3和Arduino WiFi shield。问题在于wifiShield没有收听客户端,也无法接收数据。我不知道如何解决这个问题,也不能在设备之间建立连接。Arduino Wifi盾不通信

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

什么可能导致我的问题,我怎样才能解决这些问题?

+0

你看到的输出是什么?它打印什么状态消息?为什么连接失败的无限循环? – Bart

回答

3

有这个确切的相同的问题。确保你使用的是Arduino 1.0.3而不是1.0.5,这对我来说是这样:)

0

我可以确认使用Arduino IDE 1.0.5 WiFi屏蔽不起作用。用1.0.3它工作得很好。