Arduino Nano ESP32-S3无规律死机问题求助
Arduino Nano ESP32-S3运行约13分钟后死机问题求助
我是编程新手,首次发帖求助。目前遇到的问题:用Arduino Uno R4编写代码,每分钟向4台Arduino Nano ESP32-S3发送内容为Temp?的UDP数据包,Nano需返回温湿度传感器采集数据的UDP响应。但代码运行约13分钟后,Nano会出现死机情况。
我观察到死机常发生在UDP请求的间隔期间,推测问题并非出在UDP数据包处理环节。已完成以下排查:
- 内存泄漏:每次UDP请求时打印可用栈和堆内存,未发现明显变化;
- 网络问题:通过路由器确认UDP请求仍在正常发送,串口输出未冻结;
- 硬件故障:更换其他Nano后,相同问题依旧出现。
现在陷入瓶颈,恳请各位技术人士提供帮助。附运行代码如下:
#include <DHT11.h> #include <SPI.h> #include <WiFi.h> #include <WiFiUdp.h> int CNT = 0; int ID = 2; DHT11 dht11(2); char SSID[] = "IOT"; char pass[] = "SSN690am!"; unsigned int localPort = 2390; char packetBuffer[255]; char qryTemp[] = "Temp?"; WiFiUDP Udp; void setup() { // Initialize serial communication to allow debugging and data readout. // Using a baud rate of 9600 bps. Serial.begin(9600); // Connect to WPA/WPA2 network: WiFi.begin(SSID, pass); Udp.begin(localPort); } void loop() { int temp = 0; int humidity = 0; int result = dht11.readTemperatureHumidity(temp, humidity); int packetSize = Udp.parsePacket(); Serial.print(packetSize); if (packetSize) { Serial.printf("\nStack:%d,Heap:%lu\n", uxTaskGetStackHighWaterMark(NULL), (unsigned long)ESP.getFreeHeap()); Serial.print("MSG COUNT:"); Serial.println(CNT); CNT++; Serial.print("Received packet of size "); Serial.println(packetSize); Serial.print("From "); Serial.print(Udp.remoteIP()); Serial.print(", port "); Serial.println(Udp.remotePort()); // read the packet into packetBufffer int len = Udp.read(packetBuffer, 255); if (len > 0) { packetBuffer[len] = 0; } Serial.println("Contents:"); Serial.println(packetBuffer); if(int(packetBuffer[0]) == 84 and int(packetBuffer[1]) == 101 and int(packetBuffer[2]) == 109 and int(packetBuffer[3]) == 112 and int(packetBuffer[4]) == 63){ // send a reply, to the IP address and port that sent us the packet we received Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); Udp.write(char(ID)); Udp.write(char(temp)); Udp.write(char(humidity)); Udp.endPacket(); Udp.flush(); } } }
内容的提问来源于stack exchange,提问作者Andrew Dorchak
相关产品推荐
相关产品推荐

