ESP8266 UDP Broadcast Receive Interrupts

I’m working on a project where ESP8266s with neopixels connect to a wifi network and a raspberry pi on the same network sends out UDP broadcast packets which tell the ESP8266 to play a specific pre programmed animation on the neopixels.

My issue is, I want the ESP8266s to display the new animation instantly when the command is received, even if it’s still in the middle of the last one. I don’t have access to post my code right now, but it uses the ESP8266WiFi and WiFiUDP libraries. Right now, the code waits for a packet to be received in the main loop, parses the packet, and then calls a function to display that specific animation.

Right now, if a packet is received in the middle of an animation, it sometimes plays right after the animation is finished. It seems to still be received even while the ESP is displaying the animation and storing it in a buffer somehow? I’m not sure how it all works. Ideally, whenever a UDP packet is received, it would call an interrupt so that the ESP8266 is always currently displaying the animation that was sent out by the pi. Is this possible on the ESP8266? I know I could do it with multithreading on the ESP32, but cost is a big factor here and I would like to keep it as low as possible.

Thanks!

So, change that. Instead of waiting, just check. If there is no packet, go on with the rest of your processing. You don't need interrupts to do that.

I think I didn’t explain that very well. It doesn’t wait per say, the main loop just continually checks for a received packet. If it’s received, it calls a function that corresponds to the received packet. While the function is running, the loop isn’t checking for new packets, from what I understand.

What function? Can you post a reference link? Decoding a packet that is already received, shouldn't take much time.

But it seems to me that this:
"the main loop just continually checks for a received packet"
is something in your own program logic, why not change it?

It’s a custom function. Structured something like this.

void rainbow() {

    strip.setrainbow(10) // display rainbow for 10 seconds

}

So while that function is running obviously nothing else in the code runs

Oh, it's your LED code that is blocking! Okay, make that non-blocking...

Yep! Sorry if I didn’t explain that very well.

That’s my issue, many of the animations require constant change of the led strip. How would I make it non blocking? Any ideas on how I could go about making it non blocking?

What library are you using? I think the FastLed library has non-blocking examples.

That’s what I needed to hear to get me going! Thanks! After a quick search online I saw that there are non blocking versions of FastLED and the Adafruit Neopixel library. I was using the adafruit library, which isn’t the best as is, so I’m probably going to try to implement FastLED.

Thanks again