Skip to content

Commit ce593ae

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 ce593ae

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Homie/Boot/BootNormal.cpp

+20-5
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) {
@@ -211,13 +212,27 @@ char* BootNormal::_prefixMqttTopic(PGM_P topic) {
211212
}
212213

213214
bool BootNormal::_publishOtaStatus(int status, const char* info) {
214-
String payload(status);
215-
if (info) {
216-
payload.concat(F(" "));
217-
payload.concat(info);
215+
static uint8_t count = 0;
216+
217+
bool send = false;
218+
if (status != 206) {
219+
send = true;
220+
} else if (count == 100) {
221+
count = 0;
222+
send = true;
223+
++count;
218224
}
219225

220-
return Interface::get().getMqttClient().publish(_prefixMqttTopic(PSTR("/$implementation/ota/status")), 0, true, payload.c_str()) != 0;
226+
if (send) {
227+
String payload(status);
228+
if (info) {
229+
payload.concat(F(" "));
230+
payload.concat(info);
231+
}
232+
return Interface::get().getMqttClient().publish(
233+
_prefixMqttTopic(PSTR("/$implementation/ota/status")), 0, true, payload.c_str()) != 0;
234+
}
235+
return false;
221236
}
222237

223238
void BootNormal::_endOtaUpdate(bool success, uint8_t update_error) {

0 commit comments

Comments
 (0)