Hello there,
I have an issue with LinkIt ONE. Look at the code below:
// Time intervals
#define API_DATA_INT 10000
// Define variables
LWiFiClient c;
int request_start = 0;
void setup()
{
// ...some code...
}
void loop()
{
request_start = millis();
Serial.println(String(LBattery.level()));
int request_delay = ((request_start + API_DATA_INT) - millis());
while(request_delay > 0)
{
if(request_delay < 1000) {
delay(request_delay);
} else {
delay(1000);
}
request_delay = request_delay - 1000;
}
}
The idea of the code is to print the battery level every ten seconds. First I tried to execute:
delay(10000);
But I realized that this does not work. That’s why I decided to split the interval of 10000 milliseconds into 10 delays of 1000 milliseconds each. I ran the code and it worked very well for the first 15 to 20 iterations and it suddenly stopped. Seven to eight minutes later the device started again. After about 15-20 and sometimes more iterations, the devices stops and after about 7-8 minutes it starts again. This behaviour continues until the battery is completely exhausted.
So, my questions are:
(1) Why do we have such behaviour? I don’t find any logical explanation.
(2) How can we have a delay of 10000 milliseconds without such interruption of 7-8 minutes?