mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
fixing mqtt task
This commit is contained in:
parent
3fbed7b963
commit
8d494c0832
|
|
@ -46,29 +46,19 @@ bool MQTTTask::loop(System &system) {
|
||||||
topic = topic + "/";
|
topic = topic + "/";
|
||||||
}
|
}
|
||||||
topic = topic + system.getUserConfig()->callsign;
|
topic = topic + system.getUserConfig()->callsign;
|
||||||
|
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Send MQTT with topic: '%s', data: %s", topic, r);
|
||||||
logPrintD("Send MQTT with topic: \"");
|
|
||||||
logPrintD(topic);
|
|
||||||
logPrintD("\", data: ");
|
|
||||||
logPrintlnD(r);
|
|
||||||
|
|
||||||
_MQTT.publish(topic.c_str(), r.c_str());
|
_MQTT.publish(topic.c_str(), r.c_str());
|
||||||
}
|
}
|
||||||
_MQTT.loop();
|
_MQTT.loop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MQTTTask::connect(const System &system) {
|
bool MQTTTask::connect(System &system) {
|
||||||
logPrintI("Connecting to MQTT broker: ");
|
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker: %s on port %d", system.getUserConfig()->mqtt.server, system.getUserConfig()->mqtt.port);
|
||||||
logPrintI(system.getUserConfig()->mqtt.server);
|
|
||||||
logPrintI(" on port ");
|
|
||||||
logPrintlnI(String(system.getUserConfig()->mqtt.port));
|
|
||||||
|
|
||||||
if (_MQTT.connect(system.getUserConfig()->callsign.c_str(), system.getUserConfig()->mqtt.name.c_str(), system.getUserConfig()->mqtt.password.c_str())) {
|
if (_MQTT.connect(system.getUserConfig()->callsign.c_str(), system.getUserConfig()->mqtt.name.c_str(), system.getUserConfig()->mqtt.password.c_str())) {
|
||||||
logPrintI("Connected to MQTT broker as: ");
|
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to MQTT broker as: %s", system.getUserConfig()->callsign);
|
||||||
logPrintlnI(system.getUserConfig()->callsign);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
logPrintlnI("Connecting to MQTT broker faild. Try again later.");
|
system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker failed. Try again later.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ private:
|
||||||
WiFiClient _client;
|
WiFiClient _client;
|
||||||
PubSubClient _MQTT;
|
PubSubClient _MQTT;
|
||||||
|
|
||||||
bool connect(const System &system);
|
bool connect(System &system);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue