Arduino Wi-Fi屏蔽 - 无法发送UDP数据包

use*_*864 5 networking arduino

我正试图通过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");
}
Run Code Online (Sandbox Code Playgroud)

它编译并连接到网络就好了.唯一的问题是我无法判断数据包是否已发送,因为我在Wireshark上看不到它的痕迹.我还在java上编写了一个监听端口(50505)的套接字,并且应该显示来自数据包的消息,但它也不起作用.(我可以在这里复制java代码,但我可以向你保证这不是问题'因为我用不同的java服务器测试它并且它有效,所以问题应该在Arduino方面)

缩小范围的一些细节:我相信"远程ip"是正确的,但即使它不是 - 我仍然应该在Wireshark中看到它,所以它不是问题.我应该提到Wi-Fi屏蔽工作,我成功发送ping并运行其他示例(如SimpleWebServerWifi).

我使用的是原装Arduino Uno R3板和原装Wi-Fi屏蔽.arduino IDE是最新版本.我用GitHub上发现的最新更新更新了Wi-Fi屏蔽.

我还在我的以太网屏蔽上运行了相同的"发送和接收UDP字符串"代码(带有必要的更改),它确实有效.

我不知道还有什么可以尝试 - 请帮助.任何帮助将不胜感激.

伊泰

ENG*_*024 0

我认为你没有回复缓冲区数据包。google arduino wifisendrecieve,您将看到他们的示例,其中有一个标记为“已确认”的回复数据包。希望这可以帮助