5

Wi-Fi ネットワークを介して arduino ボードからコンピューターに情報を送信しようとしています。私のプロジェクトの目的では、UDP 接続である必要があります。「UDP 文字列の送受信」の例 ( http://arduino.cc/en/Tutorial/WiFiSendReceiveUDPString ) をいくつか変更して使用します。

#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>

int status = WL_IDLE_STATUS;
char ssid[] = "itay_net"; //  your network SSID (name) 
char pass[] = "0527414540";    // your network password (use for WPA, or use as key for WEP)

unsigned int localPort = 50505;      // local port to listen on

IPAddress remote_ip(192, 168, 1, 100);
unsigned int remote_port = 50505;


char  ReplyBuffer[] = "acknowledged";       // a string to send back

WiFiUDP Udp;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:    
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  delay(10000);
  printWifiStatus();



  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  Udp.begin(localPort);  
}

void loop() {

  int bite_send;
  Udp.beginPacket(remote_ip, remote_port);
  bite_send = Udp.write("hello");
  Udp.endPacket();
  Serial.println("the packet was sent");
  Serial.println(bite_send);



  delay(1000);
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

コンパイルしてネットワークに接続します。唯一の問題は、Wireshark でパケットの痕跡が見られないため、パケットが送信されたかどうかがわからないことです。また、ポート(50505)をリッスンし、パケットからのメッセージを表示する必要があるJavaのソケットを作成しましたが、どちらも機能しませんでした。(ここに Java コードをコピーできますが、別の Java サーバーでテストして動作したため、問題ではないことを保証できます。したがって、問題は Arduino 側にあるはずです)

絞り込むためのいくつかの詳細:「リモートIP」は正しいと思いますが、そうでなくても、Wiresharkで見たはずなので、問題になることはありません. Wi-Fi シールドが機能していることに言及する必要があります。ping を正常に送信し、他の例 (SimpleWebServerWifi など) を実行しました。

オリジナルの Arduino Uno R3 ボードとオリジナルの Wi-Fi シールドを使用しています。arduino IDE は最新バージョンです。GitHub で見つけた最新の更新プログラムで Wi-Fi シールドを更新しました。

また、イーサネット シールドで同じ「UDP 文字列の送受信」コードを (必要な変更を加えて) 実行したところ、機能しました。

他に何を試すべきかわかりません - 助けてください。どんな助けでも大歓迎です。

イタイ

4

1 に答える 1

0

返信バッファ パケットがあるとは思いません。google arduino wifisendrecieve を実行すると、「acknowledged」というラベルの付いた応答パケットを持つ例が表示されます。お役に立てれば

于 2013-12-31T22:04:16.167 に答える