Reciving UDP-messages

I got a code that recive UDP-messages, and it could work for weeks. I recioved it in my void loop() {}, not so fancy but it works mostly.

void loop() {
Udp.beginBroadcastPacket(OSC_UDP_port);
int packetSize = Udp.parsePacket();

if(packetSize) 
{
  //yadayada...
}
}

Sometimes it´s stuck in the if(packetSize) {} and won´t recive next UDP-messages.

What is the easiest way to jumps out of my IF after for example 5 sec and wait for a UDP-messages if it´s in a infinity loop?

that's the wrong question.
The real question is why do you have an infinite loop in the if() in the first place.
can you show us the code that does this infinite loop?

exiting an infinite loop after a certain time is basically something like this

  ...
  const unsigned long timeOut = 20000ul; // 20s in ms
  unsigned long startTimeBeforeInfiniteLoop = millis();
  while (true) { // wannabe infinite loop
    ... // some code, possibly using break to exit the infinite loop
    if (millis() - startTimeBeforeInfiniteLoop >=  timeOut) break; // exit the while loop after 20s max
  }

Thanks for the answer.

I just guess it´s an infinite loop in that part because it could work for weeks and suddenly it stop working. It could even be the communication between Yün Linux-shield and Arduino that´s is the problem. I use #inculde <Bridge.h> and find .releaseBuffer() and see if that could help.

Problem why I can´t see the fault is that i don´t have any computer connected to my Arduino and can monitor the problem when it happens. When I disconnect my USB and connect the computer, it restart and works fine. Because it works in weeks I can´t leave my computer until it happens. Need to try something, one is to brake the loop after x seconds.

OK - hard to debug those things indeed.

what's your arduino?

I use Arduino Yün for this project.

If there was Raspberry Pi to buy 2 years ago in sweden, I probably use one with a small screen so I could debug it whitout computer. This was the only one that I could order with RJ45-port. So I am really newbee on the Yün model. :slight_smile:

OK - I'm not familiar with the Yün model...

Now I found the fault. :face_with_spiral_eyes:

After a software upgrade for our EOS-lighting console it send UDP-commands for every pressed button and every moved fader to my Arduino... for no reason. So it was just to turned that off in the software and it works again. :slight_smile:

glad you solved it!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.