9 #ifndef _LEAKY_BUCKET_H_
10 #define _LEAKY_BUCKET_H_
14 LeakyBucket_t() : dropsInBucket(0), lastDrop(-DROP_IN_TIME), once(false) {}
19 unsigned long lastDrop;
21 unsigned long lastWarning;
24 bool LeakyBucket_t::addDrop() {
26 unsigned long actualMillis = millis();
28 if (dropsInBucket < BUCKET_SIZE && actualMillis-lastDrop > dropsInBucket + DROP_IN_TIME) {
30 lastDrop = actualMillis;
34 if (dropsInBucket >= BUCKET_SIZE) {
35 if (actualMillis-lastWarning > 1000) {
37 Serial.printf(
"[SinricPro]: WARNING: YOU SENT TOO MUCH EVENTS IN A SHORT PERIOD OF TIME!\r\n - PLEASE CHECK YOUR CODE AND SEND EVENTS ONLY IF DEVICE STATE HAS CHANGED!\r\n");
40 Serial.printf(
"[SinricPro]: EVENTS ARE BLOCKED FOR %lu SECONDS!\r\n",(DROP_OUT_TIME-(actualMillis-lastDrop))/1000);
41 lastWarning = actualMillis;
47 void LeakyBucket_t::leak() {
49 unsigned long actualMillis = millis();
50 int drops_to_leak = (actualMillis - lastDrop) / DROP_OUT_TIME;
51 if (drops_to_leak > 0) {
52 if (dropsInBucket <= drops_to_leak) {
55 dropsInBucket -= drops_to_leak;