networking - ESP8266 在 WIFI 网络中收不到数据包

标签 networking udp wifi esp8266 netcat

在我的节点 mcu v3.0 上运行 UDP 示例时,我遇到了以下奇怪的问题。

如果我将我的计算机和节点 mcu 连接到由我的手机托管的 WIFI 热点,一切运行正常(我可以通过 netcat 从我的计算机向节点 mcu 发送 udp 数据包并得到答案)。

但是,如果我切换到我居住的学生宿舍提供的 WiFi 网络(我们必须使用相应的 ssid 和密码连接到下一个路由器,就像任何其他正常的 wifi 网络一样),节点 mcu 根本不会收到任何数据包(它仍然打印出一个 IP 地址,所以我猜它可以连接到网络)。我还尝试通过 netcat 将 udp 数据包从我的计算机发送到我的笔记本电脑,它仍然可以正常工作。
这里发生了什么?

这是代码:

/*
  UDPSendReceive.pde:
  This sketch receives UDP message strings, prints them to the serial port
  and sends an "acknowledge" string back to the sender

  A Processing sketch is included at the end of file that can be used to send
  and received messages for testing with a computer.

  created 21 Aug 2010
  by Michael Margolis

  This code is in the public domain.

  adapted from Ethernet library examples
*/


#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#ifndef STASSID
#define STASSID ".."
#define STAPSK  ".."
#endif

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

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE + 1]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged\r\n";       // a string to send back

WiFiUDP Udp;

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(STASSID, STAPSK);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }
  Serial.print("Connected! IP address: ");
  Serial.println(WiFi.localIP());
  Serial.printf("UDP server on port %d\n", localPort);
  Udp.begin(localPort);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.printf("Received packet of size %d from %s:%d\n    (to %s:%d, free heap = %d B)\n",
                  packetSize,
                  Udp.remoteIP().toString().c_str(), Udp.remotePort(),
                  Udp.destinationIP().toString().c_str(), Udp.localPort(),
                  ESP.getFreeHeap());

    // read the packet into packetBufffer
    int n = Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    packetBuffer[n] = 0;
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }

}

/*
  test (shell/netcat):
  --------------------
      nc -u 192.168.esp.address 8888
*/

编辑:从节点 mcu 调用网站(如谷歌)工作正常

最佳答案

您很可能必须添加 IO 防火墙 rules .
查询 This link .

或者通过使用 PowerShell:
PS C:\> New-NetFirewallRule -DisplayName "Allow UDP 8888 over Teredo" -Direction Inbound -Action Allow -EdgeTraversalPolicy Allow -Protocol UDP -LocalPort 8888 -Program "C:\Program Files (x86)\TestIPv6App.exe"

关于networking - ESP8266 在 WIFI 网络中收不到数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59096892/

相关文章:

iphone - 在 iPhone 上使用 bonjour 会自动启用蓝牙吗?

android - TrafficStats 特定应用-特定网络接口(interface)

.net - 如何在.NET中以编程方式选择连接到互联网的网卡

c - 如何每 1 毫秒发送一次 UDP 数据包?

java - 如果服务器收到 0 作为端口号,如何中继 NAT 动态端口号?

android - android 和 vb.net 之间通过套接字进行通信

c# - 如何在 C#.NET/Mono 中使用 HTTP 库来使用请求-响应

linux - Debian Live 无法配置有线网络

c++ - Boost Asio UDP 服务器设置套接字以监听指定 IP

Android:强制数据通过 radio 与 WiFi 发送