1

私のプロジェクトは、Android で制御される Arduino RC カーです。そのために、Arduino Uno R3 とArduino WiFi シールドを購入しました。問題は、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);
        }
    }
}

問題の原因とその解決方法

4

2 に答える 2

3

これとまったく同じ問題がありました。Arduino 1.0.5 ではなく 1.0.3 を使用していることを確認してください。

于 2013-06-30T22:36:40.790 に答える