mruettgers / SMLReader

ESP8266 based smart meter (SML) to MQTT gateway
GNU General Public License v3.0
292 stars 68 forks source link

[Feature Request] Add interval function #11

Closed tunip closed 3 years ago

tunip commented 3 years ago

Would like to ask for a feature request to add a configurable value to set an interval in seconds for updating the mqtt topics. My meter updates its values every 1-2 seconds. But for my use case, every 15 seonds is more then enough.

Thx

emmrichd commented 3 years ago

For the time being, you could add a delay in the loop, couldn't you? Like delay(15000);

tunip commented 3 years ago

@emmrichd In main.cpp I tried at several places in "void loop" but does not work. As a workaround I added a delay in MqttPublisher.h, which works for me.

    {
      // Something failed
      DEBUG("Connection to MQTT broker failed.");
      DEBUG("Unable to publish a message to '%s'.", topic);
      return;
    }
    DEBUG("Publishing message to '%s':", topic);
    DEBUG("%s\n", payload);
    client.publish(topic, payload);
    delay(1500);
  }
};

#endif
mruettgers commented 3 years ago

I did not have the time to test it by myself yet, but feel free to do so ;-)

https://github.com/mruettgers/SMLReader/tree/feature/interval The interval can be set in config.h

emmrichd commented 3 years ago

Thanks a lot for the quick fix, Michael! However, tunip's way is working, your seems not to. I tried different intervals.

mruettgers commented 3 years ago

Well, that's strange. I just did a test with an interval of 0 and another with 15 and it worked as expected.

emmrichd commented 3 years ago

Ok, I will try again.

mruettgers commented 3 years ago

Please note that the flashing of the LED is not an indicator. The led will continue flashing as usual. Only the MQTT messages are being throttled.

emmrichd commented 3 years ago

Ok, sorry, I confirm, it works like a charm! Thanks a lot!