【问题标题】:Arduino Wifi Shield is not communicatingArduino Wifi Shield 无法通信
【发布时间】:2013-06-02 13:11:24
【问题描述】:

我的项目是一个用 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);
        }
    }
}

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

【问题讨论】:

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

标签: arduino


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我可以确认使用 Arduino IDE 1.0.5 WiFi shield 将无法正常工作。使用 1.0.3 就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多