fix: require configured mqtt iata before broker connect
This commit is contained in:
@@ -63,6 +63,9 @@ bool MQTTPrefsStore::load(FILESYSTEM* fs, MQTTPrefs& prefs) {
|
||||
if (prefs.legacy_wifi_powersave > 2) {
|
||||
prefs.legacy_wifi_powersave = 0;
|
||||
}
|
||||
if (prefs.iata[0] == 0) {
|
||||
StrHelper::strncpy(prefs.iata, MQTT_DEFAULT_IATA, sizeof(prefs.iata));
|
||||
}
|
||||
prefs.status_interval_ms = kFixedStatusIntervalMs;
|
||||
prefs.enabled_mask &= 0x07;
|
||||
return true;
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef MQTT_DEFAULT_IATA
|
||||
#define MQTT_DEFAULT_IATA "MEL"
|
||||
#define MQTT_DEFAULT_IATA "UNSET"
|
||||
#endif
|
||||
|
||||
#ifndef MQTT_UNSET_IATA
|
||||
#define MQTT_UNSET_IATA "UNSET"
|
||||
#endif
|
||||
|
||||
struct MQTTPrefs {
|
||||
|
||||
@@ -124,6 +124,10 @@ bool MQTTUplink::hasEnabledBroker() const {
|
||||
return (_prefs.enabled_mask & 0x07) != 0;
|
||||
}
|
||||
|
||||
bool MQTTUplink::isUnsetIataValue(const char* iata) {
|
||||
return iata == nullptr || iata[0] == 0 || strcmp(iata, MQTT_UNSET_IATA) == 0;
|
||||
}
|
||||
|
||||
uint8_t MQTTUplink::normalizeEnabledMask(uint8_t mask) {
|
||||
uint8_t normalized = 0;
|
||||
uint8_t count = 0;
|
||||
@@ -599,7 +603,8 @@ void MQTTUplink::ensureBroker(BrokerState& broker, bool allow_new_connect) {
|
||||
return;
|
||||
}
|
||||
bool enabled = (_prefs.enabled_mask & broker.spec->bit) != 0;
|
||||
if (!enabled) {
|
||||
bool iata_configured = !isUnsetIataValue(_prefs.iata);
|
||||
if (!enabled || !iata_configured) {
|
||||
if (broker.client != nullptr || broker.token != nullptr || broker.connected || broker.connect_announced ||
|
||||
broker.reconnect_pending || broker.next_connect_attempt != 0 || broker.last_connect_attempt != 0 ||
|
||||
broker.reconnect_failures != 0 || broker.token_expires_at != 0) {
|
||||
@@ -828,6 +833,9 @@ void MQTTUplink::formatStatusReply(char* reply, size_t reply_size) const {
|
||||
if ((_prefs.enabled_mask & bit) == 0) {
|
||||
return "off";
|
||||
}
|
||||
if (isUnsetIataValue(_prefs.iata)) {
|
||||
return "invalid iata";
|
||||
}
|
||||
const BrokerState* broker = nullptr;
|
||||
for (const BrokerState& candidate : _brokers) {
|
||||
if (candidate.spec != nullptr && candidate.spec->bit == bit) {
|
||||
@@ -911,6 +919,11 @@ bool MQTTUplink::setIata(const char* iata) {
|
||||
for (size_t i = 0; cleaned[i] != 0; ++i) {
|
||||
cleaned[i] = toupper(static_cast<unsigned char>(cleaned[i]));
|
||||
}
|
||||
if (strcmp(cleaned, MQTT_UNSET_IATA) == 0) {
|
||||
StrHelper::strncpy(_prefs.iata, MQTT_UNSET_IATA, sizeof(_prefs.iata));
|
||||
refreshIdentityStrings();
|
||||
return savePrefs();
|
||||
}
|
||||
StrHelper::strncpy(_prefs.iata, cleaned, sizeof(_prefs.iata));
|
||||
refreshIdentityStrings();
|
||||
return savePrefs();
|
||||
|
||||
@@ -111,6 +111,7 @@ private:
|
||||
static constexpr uint8_t kLetsmeshUsBit = 0x04;
|
||||
static constexpr uint8_t kMaxEnabledBrokers = 2;
|
||||
static const BrokerSpec kBrokerSpecs[3];
|
||||
static bool isUnsetIataValue(const char* iata);
|
||||
|
||||
BrokerState _brokers[3];
|
||||
|
||||
|
||||
Viittaa uudesa ongelmassa
Block a user