I wrote simple program which listening on one port if data received (Currently ignoring what data come on port) from PC it will blink light. It works properly if device start and I send data continuously from my PC but If I am stop sending data more than 45-50 seconds light not blinking. I don’t understand why? Can anybody check my code and tell me where I am going wrong?
unsigned int localPort = 2201;
int led = D7; // We name pin D1 as led
const int PACKET_SIZE = 12;
byte packetBuffer[PACKET_SIZE];
void setup()
{
pinMode(led, OUTPUT);
Udp.begin(localPort); // start the UDP
}
void loop()
{
int packetSize = Udp.parsePacket();
if(packetSize)
{
digitalWrite(led, HIGH); // Turn ON the LED
delay(100); // Wait for 1000mS = 1 second
digitalWrite(led, LOW); // Turn OFF the LED
delay(100); // Wait for 1 second
Udp.read(packetBuffer,PACKET_SIZE);
IPAddress remote = Udp.remoteIP();
}
}
}
I only call stop after I receive something, not in the loop in general. This worked for me in my application, but it is obviously not a general solution.
Hmm, I wonder if the CC3000 is timing out the UDP listener after 60 seconds of inactivity? Sounds like some community members were talking about that here as well: https://community.spark.io/t/strange-udp-bug/2583/26