In general, the loop section should be written in a way that minimize time spent there. This frees up precious processor time needed for other platform management duties, in a non-preemptive multi tasking environment.
A suggestion here specifically is to replace any long delay with a time based condition that checks on every pass of the loop if a delay has been met.
The code below is an example. When the logic enters the if condition, there is a chance that the loop will block for an extended period of time and possibly cause a wdt reset.
if(LMS_addr[0] == 0)
{
Serial.println("Search for LMS server...");
for(int nbSend = 0; nbSend < 10; nbSend++)
{
// start UDP server
//Send udp packet for autodiscovery
udp.flush();
udp.beginPacket("255.255.255.255",UDP_PORT);
udp.printf("e");
udp.endPacket();
delay(2000);
if(udp.parsePacket()> 0)
{
char upd_packet;
upd_packet = udp.read();
if(upd_packet == 'E')
{
LMS_addr = udp.remoteIP();
Serial.print("Found LMS server @ ");
Serial.println(LMS_addr);
//udp.stop();
break; // LMS found we can go to the next step
}
}
else
delay(2000);
}
}
In general, the loop section should be written in a way that minimize time spent there. This frees up precious processor time needed for other platform management duties, in a non-preemptive multi tasking environment.
A suggestion here specifically is to replace any long delay with a time based condition that checks on every pass of the loop if a delay has been met.
The code below is an example. When the logic enters the if condition, there is a chance that the loop will block for an extended period of time and possibly cause a wdt reset.