bphermansson / EspSparsnasGateway

Reads data from Ikea Sparsnäs energy meter and publish via Mqtt.
MIT License
39 stars 27 forks source link

Fix issue where client.loop floods the hardware #33

Closed dogmatic69 closed 5 years ago

dogmatic69 commented 5 years ago

As noted in this comment, there should be a delay in the client.loop calls. As the sparsnas seems to only publish every 15 seconds a 2.5 second delay should be sufficient whilst leaving plenty free cycles to do other stuff.

This will fix the issue in #30

dogmatic69 commented 5 years ago

Paging @kalj for a little review :)

kalj commented 5 years ago

Looks fine. I'm a little confused by the concurrency execution model of the ESP8266. Apparently things can get problematic if you spin too tightly in loop since you need to explicitly defer execution for background things to get done, typically by calling yield(). However, it also seems like the main.cpp for ESP8266 defers implicitly during each iteration of loop() (https://www.esp8266.com/viewtopic.php?p=59073#p59073), so perhaps it is fine like this. Let's keep this in the back of our heads if something goes bad later. :)