This repository was archived by the owner on Mar 27, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,11 @@ import (
3131
3232// Status contains info about the sketches running on the device
3333type Status struct {
34- id string
35- mqttClient mqtt.Client
36- Sketches map [string ]* SketchStatus `json:"sketches"`
37- messagesSent int
34+ id string
35+ mqttClient mqtt.Client
36+ Sketches map [string ]* SketchStatus `json:"sketches"`
37+ messagesSent int
38+ firstMessageAt time.Time
3839}
3940
4041// SketchBinding represents a pair (SketchName,SketchId)
@@ -121,7 +122,18 @@ func (s *Status) Raw(topic, msg string) {
121122 if s .mqttClient == nil {
122123 return
123124 }
125+
126+ if s .messagesSent < 10 {
127+ // first 10 messages are virtually free
128+ s .firstMessageAt = time .Now ()
129+ }
130+
124131 if s .messagesSent > 1000 {
132+ // if started more than one day ago, reset the counter
133+ if time .Since (s .firstMessageAt ) > 24 * time .Hour {
134+ s .messagesSent = 0
135+ }
136+
125137 fmt .Println ("rate limiting: " + strconv .Itoa (s .messagesSent ))
126138 introducedDelay := time .Duration (s .messagesSent / 1000 ) * time .Second
127139 if introducedDelay > 20 * time .Second {
You can’t perform that action at this time.
0 commit comments