Arduino Wi-Fi屏蔽 - 无法发送UDP数据包
问题描述:
我试图通过Wi-Fi网络将信息从arduino板发送到我的电脑。 为我的项目的目的,它必须是一个UDP连接 我使用“发送和接收UDP字符串”例如(http://arduino.cc/en/Tutorial/WiFiSendReceiveUDPString) 有一些变化:Arduino Wi-Fi屏蔽 - 无法发送UDP数据包
#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上看不到它的踪迹。 我也写了一个Java套接字,监听端口(50505),并应显示来自数据包的消息,但它也没有工作。 (我可以在这里复制java代码,但我可以向你保证,这不是问题因为我用不同的java服务器测试它,它的工作,所以问题应该在Arduino方面)
几细节缩小: 我相信“远程IP”是正确的,但即使它不是 - 我仍然应该在Wireshark中看到它,所以它不会是问题。 我应该提到Wi-Fi防护罩的工作原理,我成功发送ping命令并运行其他示例(如SimpleWebServerWifi)。
我使用的是原始的Arduino Uno R3板和原始的Wi-Fi屏蔽层。 arduino IDE是最新版本。 我更新了我在GitHub上找到的最新更新的Wi-Fi屏蔽。
我还在我的以太网盾上运行了相同的“发送和接收UDP字符串”代码(并进行了必要的更改),并且它确实工作了。
我不知道还有什么可以尝试的 - 请帮助。 任何帮助将不胜感激。
伊泰
答
我不认为你有一个答复缓冲包。谷歌arduino wifisendrecieve,你会看到他们有一个回复包标记为“已确认”的例子。希望这有帮助
我在这里有同样的问题,你现在找到什么? – mou