0

請問我在使用GTimer定時執行UDP廣播訊息發送,

但是執行時卻卡在Udp.beginPacket()或Udp.write(buf),

無法執行下去!

請問要如何解決呢?

 
WiFiUDP Udp;
IPAddress Brocast_IP(255,255,255,255);
unsigned int Brocast_Port = 1234;
char buf[256];

void myhandler(uint32_t data) {
Serial.println("Enter UDP");
Udp.beginPacket(Brocast_IP,Brocast_Port);
Serial.println("Enter UDP2");
Udp.write(buf);
Udp.endPacket();
Serial.println("Exit UDP");
}

void setup() {
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
if (status == WL_CONNECTED) {
break;
}
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
GTimer.begin(0, 5 * 1000 * 1000, myhandler);
}
void loop() {

//myhandler(0);
delay(5000);
}

chengc115 回答了