Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When subscribing to a topic whose payload cannot be parsed as a float value, an exception would be triggered in the PowerMeter implementation. The code in this PR catches the exception and handles it gracefully:
Make sure that the timestamp
_lastPowerMeterUpdate
is only updated by the MQTT callback if a topic was processed that actually matches one of the subscribed topics.Upon changing the MQTT settings and submitting the new settings through the web application, PowerMeter::init() is called. That probably makes sense so it can be ensured that the topics are subscribed to using a possible new broker. However, the old subscriptions were not cancelled, resulting in the callback being called
n+1
times aftern
changes to the MQTT settings.This problem is resolved by unsubscribing from all subscribed topics, if any, before resubscribing.
The subscriptions are organized in a std::map, which allows iterating them, which in turn allows for slightly more elegant code and less code overall.
Removed an unused member variable and moved private function to the private section of the class declaration.
Use a switch-case-statement over an if-else construct in
init()
.