Skip to content

Commit

Permalink
Clear map for recieved key, value pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Oct 4, 2022
1 parent 9c71652 commit ba3183e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/VeDirectFrameHandler/VeDirectFrameHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void VeDirectFrameHandler::rxData(uint8_t inbyte)
void VeDirectFrameHandler::frameEndEvent(bool valid) {
if ( valid ) {
veMap = _tmpMap;
_tmpMap.clear();
setLastUpdate();
}
}
Expand Down
13 changes: 3 additions & 10 deletions src/MqttVedirectPublishing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,13 @@ void MqttVedirectPublishingClass::loop()
key = it->first;
value = it->second;

// Add new key, value pairs to map and update changed values.
// Mark changed values
auto a = _kv_map.find(key);
bChanged = true;
if (a != _kv_map.end()) {
if (_kv_map[key] == value) {
bChanged = false;
}
else {
_kv_map[key] = value;
bChanged = true;
}
}
else {
_kv_map.insert(std::make_pair(key, value));
bChanged = true;
}
}

// publish only changed key, values pairs
Expand All @@ -57,6 +49,7 @@ void MqttVedirectPublishingClass::loop()
MqttSettings.publish(topic.c_str(), value.c_str());
}
}
_kv_map = VeDirect.veMap;
_lastPublish = millis();
}
}

0 comments on commit ba3183e

Please sign in to comment.