Do you have a simple uno R3 to try the code on, just to rule out any issue with the wifi piece?
That will help you dig in the right place
Yes I have an Arduino UNO, I will test on this but it seems like the issue is with the USB library
[EDIT:] I have tested and the behavior persists with the Arduino UNO
Ok - then indeed need to dig into the USB behavior
Have you tried an active wait with a while loop + millis and calling Usb.Task() within the while to see if indeed that needs to be called "often enough"
For example calling this function instead of delay()
void hackedDelay(unsigned long duration)
{
unsigned long t0 = millis();
while (millis() - t0 < duration) {
Usb.Task();
}
}