a lot of thread housekeeping. Switch them off when not needed / disabled.

This commit is contained in:
Thomas Göttgens
2022-12-29 15:45:49 +01:00
parent 1a949b7ca6
commit 41a1dfec79
15 changed files with 102 additions and 59 deletions

View File

@@ -128,12 +128,18 @@ void mqttInit()
MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE)
{
assert(!mqtt);
mqtt = this;
if(moduleConfig.mqtt.enabled) {
pubSub.setCallback(mqttCallback);
assert(!mqtt);
mqtt = this;
// preflightSleepObserver.observe(&preflightSleep);
pubSub.setCallback(mqttCallback);
// preflightSleepObserver.observe(&preflightSleep);
} else {
setInterval(INT32_MAX);
enabled = false;
}
}
bool MQTT::connected()
@@ -238,6 +244,10 @@ bool MQTT::wantsLink() const
int32_t MQTT::runOnce()
{
if(!moduleConfig.mqtt.enabled) {
enabled = false;
return INT32_MAX;
}
bool wantConnection = wantsLink();
// If connected poll rapidly, otherwise only occasionally check for a wifi connection change and ability to contact server