Networking Arduino Wi-Fi屏蔽-can';不要发送UDP数据包
我正试图通过Wi-Fi网络将信息从arduino板发送到我的计算机。 就我的项目而言,它必须是UDP连接 我使用“发送和接收UDP字符串”示例() 有一些变化:Networking Arduino Wi-Fi屏蔽-can';不要发送UDP数据包,networking,arduino,Networking,Arduino,我正试图通过Wi-Fi网络将信息从arduino板发送到我的计算机。 就我的项目而言,它必须是UDP连接 我使用“发送和接收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
#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");
}
#包括
#包括
#包括
int状态=WL\U空闲\U状态;
char ssid[]=“itay_net”;//您的网络SSID(名称)
字符传递[]=“0527414540”//您的网络密码(用于WPA,或用作WEP的密钥)
unsigned int localPort=50505;//要侦听的本地端口
ip地址远程ip(192、168、1100);
无符号int远程_端口=50505;
char ReplyBuffer[]=“已确认”//要发回的字符串
WiFiUDP-Udp;
无效设置(){
//初始化串行端口并等待端口打开:
Serial.begin(9600);
而(!串行){
;//等待串行端口连接。仅Leonardo需要
}
//检查是否存在屏蔽:
如果(WiFi.status()=无线无屏蔽){
Serial.println(“不存在WiFi屏蔽”);
//不要继续:
虽然(正确);
}
//尝试连接到Wifi网络:
当(状态!=WL_已连接){
Serial.print(“试图连接到WPA SSID:”);
序列号println(ssid);
//连接到WPA/WPA2网络:
状态=WiFi.begin(ssid,通过);
//等待10秒钟以进行连接:
延迟(10 000);
}
//您现在已连接,请打印数据:
Serial.print(“您已连接到网络”);
延迟(10 000);
printWifiStatus();
Serial.println(“\n正在启动与服务器的连接…”);
//如果您获得连接,请通过串行方式报告:
开始(localPort);
}
void循环(){
int bite_send;
Udp.beginPacket(远程ip、远程端口);
bite_send=Udp.write(“你好”);
Udp.endPacket();
Serial.println(“数据包已发送”);
串行打印LN(咬合发送);
延迟(1000);
}
void printWifiStatus(){
//打印您连接到的网络的SSID:
序列号。打印(“SSID:”);
Serial.println(WiFi.SSID());
//打印您的WiFi屏蔽的IP地址:
ip地址ip=WiFi.localIP();
串行打印(“IP地址:”);
序列号println(ip);
//打印接收到的信号强度:
长rssi=WiFi.rssi();
串行打印(“信号强度(RSSI):”;
串行打印(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屏蔽
我还在我的Ethernet shield上运行了相同的“发送和接收UDP字符串”代码(进行了必要的更改),它确实起了作用
我不知道还能尝试什么-请帮忙。
任何帮助都将不胜感激。
Itay我想你没有回复缓冲包。google arduino wifisendrecieve,您将看到他们的示例,其中有一个回复包标记为“已确认”。希望这有帮助我这里也有同样的问题,你现在找到什么了吗?