Skip to content

Commit 7f2f5c0

Browse files
Nicolas Emilianinemiliani
Nicolas Emiliani
authored andcommitted
(homieiot#648) Tweaks to avoid OTA halting when using TLS.
+ During OTA do not publish any messages that are not OTA related + Publish 1 every 100 206 status messages
1 parent cfb3346 commit 7f2f5c0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Homie/Boot/BootNormal.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void BootNormal::loop() {
139139
return;
140140
}
141141

142+
if (_otaOngoing) return;
142143
// here, we finished the advertisement
143144

144145
if (!_mqttConnectNotified) {
@@ -217,7 +218,8 @@ bool BootNormal::_publishOtaStatus(int status, const char* info) {
217218
payload.concat(info);
218219
}
219220

220-
return Interface::get().getMqttClient().publish(_prefixMqttTopic(PSTR("/$implementation/ota/status")), 0, true, payload.c_str()) != 0;
221+
return Interface::get().getMqttClient().publish(
222+
_prefixMqttTopic(PSTR("/$implementation/ota/status")), 0, true, payload.c_str()) != 0;
221223
}
222224

223225
void BootNormal::_endOtaUpdate(bool success, uint8_t update_error) {
@@ -1025,9 +1027,14 @@ bool HomieInternals::BootNormal::__handleOTAUpdates(char* topic, char* payload,
10251027
Interface::get().event.sizeTotal = _otaSizeTotal;
10261028
Interface::get().eventHandler(Interface::get().event);
10271029

1028-
_publishOtaStatus(206, progress.c_str()); // 206 Partial Content
1030+
static int count = 0;
1031+
if (count == 100) {
1032+
_publishOtaStatus(206, progress.c_str()); // 206 Partial Content
1033+
count = 0;
1034+
}
1035+
++count;
10291036

1030-
// Done with the update?
1037+
// Done with the update?
10311038
if (index + len == total) {
10321039
// With base64-coded firmware, we may have provided a length off by one or two
10331040
// to Update.begin() because the base64-coded firmware may use padding (one or

0 commit comments

Comments
 (0)