Add new MQTT presets for Mesh Core CA and update compile-time defaults
- Introduced two new MQTT presets: `meshcore-ca-1` and `meshcore-ca-2`. - Updated documentation to reflect compile-time configuration options for MQTT defaults, including slot presets, IATA, and timezone settings. - Removed legacy default MQTT settings from the code, now relying on the new configuration approach.
This commit is contained in:
1 parent
3f5ddcac4c
commit
d669d4dbd4
6 files changed
+139
-62
No files matched your search
@@ -17,6 +17,7 @@
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
#include "bridges/MQTTBridge.h"
|
||||
#include "MQTTDefaults.h"
|
||||
|
||||
// Helper function to calculate total size of MQTT fields for file format compatibility
|
||||
// Uses NodePrefs struct to get accurate field sizes
|
||||
@@ -449,25 +450,7 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
// Set default values for MQTT preferences (used when file doesn't exist or is corrupted)
|
||||
static void setMQTTPrefsDefaults(MQTTPrefs* prefs) {
|
||||
memset(prefs, 0, sizeof(MQTTPrefs));
|
||||
// Set sensible defaults matching MQTTBridge expectations
|
||||
prefs->mqtt_status_enabled = 1; // enabled by default
|
||||
prefs->mqtt_packets_enabled = 1; // enabled by default
|
||||
prefs->mqtt_raw_enabled = 0; // disabled by default
|
||||
prefs->mqtt_tx_enabled = 2; // advert: own adverts only, by default
|
||||
prefs->mqtt_rx_enabled = 1; // RX packets enabled by default
|
||||
prefs->mqtt_status_interval = 300000; // 5 minutes default
|
||||
// Slot presets: analyzer-us and analyzer-eu enabled by default, rest = none
|
||||
strncpy(prefs->mqtt_slot_preset[0], "analyzer-us", sizeof(prefs->mqtt_slot_preset[0]) - 1);
|
||||
prefs->mqtt_slot_preset[0][sizeof(prefs->mqtt_slot_preset[0]) - 1] = '\0';
|
||||
strncpy(prefs->mqtt_slot_preset[1], "analyzer-eu", sizeof(prefs->mqtt_slot_preset[1]) - 1);
|
||||
prefs->mqtt_slot_preset[1][sizeof(prefs->mqtt_slot_preset[1]) - 1] = '\0';
|
||||
for (int i = 2; i < MAX_MQTT_SLOTS; i++) {
|
||||
strncpy(prefs->mqtt_slot_preset[i], "none", sizeof(prefs->mqtt_slot_preset[i]) - 1);
|
||||
prefs->mqtt_slot_preset[i][sizeof(prefs->mqtt_slot_preset[i]) - 1] = '\0';
|
||||
}
|
||||
prefs->wifi_power_save = 1; // Default to none (0=min, 1=none, 2=max)
|
||||
// String fields are already zero-initialized by memset
|
||||
applyMQTTDefaults(prefs);
|
||||
}
|
||||
|
||||
void CommonCLI::loadMQTTPrefs(FILESYSTEM* fs) {
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
|
||||
#include <string.h>
|
||||
#include <MeshCore.h>
|
||||
#include "CommonCLI.h"
|
||||
#include "MQTTPresets.h"
|
||||
|
||||
// Compile-time defaults for fresh /mqtt_prefs (override via platformio build_flags).
|
||||
// Example:
|
||||
// -D MQTT_DEFAULT_SLOT1_PRESET='"meshcore-ca-1"'
|
||||
// -D MQTT_DEFAULT_IATA='"YYZ"'
|
||||
// -D MQTT_DEFAULT_TIMEZONE='"America/Toronto"'
|
||||
// -D MQTT_DEFAULT_TIMEZONE_OFFSET=-5
|
||||
|
||||
#ifndef MQTT_DEFAULT_SLOT1_PRESET
|
||||
#define MQTT_DEFAULT_SLOT1_PRESET "analyzer-us"
|
||||
#endif
|
||||
#ifndef MQTT_DEFAULT_SLOT2_PRESET
|
||||
#define MQTT_DEFAULT_SLOT2_PRESET "analyzer-eu"
|
||||
#endif
|
||||
#ifndef MQTT_DEFAULT_SLOT3_PRESET
|
||||
#define MQTT_DEFAULT_SLOT3_PRESET "none"
|
||||
#endif
|
||||
#ifndef MQTT_DEFAULT_SLOT4_PRESET
|
||||
#define MQTT_DEFAULT_SLOT4_PRESET "none"
|
||||
#endif
|
||||
#ifndef MQTT_DEFAULT_SLOT5_PRESET
|
||||
#define MQTT_DEFAULT_SLOT5_PRESET "none"
|
||||
#endif
|
||||
#ifndef MQTT_DEFAULT_SLOT6_PRESET
|
||||
#define MQTT_DEFAULT_SLOT6_PRESET "none"
|
||||
#endif
|
||||
|
||||
#ifndef MQTT_DEFAULT_IATA
|
||||
#define MQTT_DEFAULT_IATA ""
|
||||
#endif
|
||||
|
||||
#ifndef MQTT_DEFAULT_TIMEZONE
|
||||
#define MQTT_DEFAULT_TIMEZONE ""
|
||||
#endif
|
||||
|
||||
#ifndef MQTT_DEFAULT_TIMEZONE_OFFSET
|
||||
#define MQTT_DEFAULT_TIMEZONE_OFFSET 0
|
||||
#endif
|
||||
|
||||
static inline void mqttDefaultSlotPreset(char* dest, size_t dest_size, const char* preset) {
|
||||
const char* resolved = MQTT_PRESET_NONE;
|
||||
if (preset && preset[0] != '\0') {
|
||||
if (strcmp(preset, MQTT_PRESET_NONE) == 0 ||
|
||||
strcmp(preset, MQTT_PRESET_CUSTOM) == 0 ||
|
||||
findMQTTPreset(preset) != nullptr) {
|
||||
resolved = preset;
|
||||
} else {
|
||||
MESH_DEBUG_PRINTLN("MQTT: invalid default preset '%s', using none", preset);
|
||||
}
|
||||
}
|
||||
strncpy(dest, resolved, dest_size - 1);
|
||||
dest[dest_size - 1] = '\0';
|
||||
}
|
||||
|
||||
static inline void applyMQTTDefaults(MQTTPrefs* prefs) {
|
||||
memset(prefs, 0, sizeof(MQTTPrefs));
|
||||
prefs->mqtt_status_enabled = 1;
|
||||
prefs->mqtt_packets_enabled = 1;
|
||||
prefs->mqtt_raw_enabled = 0;
|
||||
prefs->mqtt_tx_enabled = 2;
|
||||
prefs->mqtt_rx_enabled = 1;
|
||||
prefs->mqtt_status_interval = 300000;
|
||||
prefs->wifi_power_save = 1;
|
||||
|
||||
mqttDefaultSlotPreset(prefs->mqtt_slot_preset[0], sizeof(prefs->mqtt_slot_preset[0]),
|
||||
MQTT_DEFAULT_SLOT1_PRESET);
|
||||
mqttDefaultSlotPreset(prefs->mqtt_slot_preset[1], sizeof(prefs->mqtt_slot_preset[1]),
|
||||
MQTT_DEFAULT_SLOT2_PRESET);
|
||||
mqttDefaultSlotPreset(prefs->mqtt_slot_preset[2], sizeof(prefs->mqtt_slot_preset[2]),
|
||||
MQTT_DEFAULT_SLOT3_PRESET);
|
||||
mqttDefaultSlotPreset(prefs->mqtt_slot_preset[3], sizeof(prefs->mqtt_slot_preset[3]),
|
||||
MQTT_DEFAULT_SLOT4_PRESET);
|
||||
mqttDefaultSlotPreset(prefs->mqtt_slot_preset[4], sizeof(prefs->mqtt_slot_preset[4]),
|
||||
MQTT_DEFAULT_SLOT5_PRESET);
|
||||
mqttDefaultSlotPreset(prefs->mqtt_slot_preset[5], sizeof(prefs->mqtt_slot_preset[5]),
|
||||
MQTT_DEFAULT_SLOT6_PRESET);
|
||||
|
||||
if (MQTT_DEFAULT_IATA[0] != '\0') {
|
||||
strncpy(prefs->mqtt_iata, MQTT_DEFAULT_IATA, sizeof(prefs->mqtt_iata) - 1);
|
||||
prefs->mqtt_iata[sizeof(prefs->mqtt_iata) - 1] = '\0';
|
||||
}
|
||||
|
||||
if (MQTT_DEFAULT_TIMEZONE[0] != '\0') {
|
||||
strncpy(prefs->timezone_string, MQTT_DEFAULT_TIMEZONE, sizeof(prefs->timezone_string) - 1);
|
||||
prefs->timezone_string[sizeof(prefs->timezone_string) - 1] = '\0';
|
||||
}
|
||||
prefs->timezone_offset = MQTT_DEFAULT_TIMEZONE_OFFSET;
|
||||
}
|
||||
|
||||
#endif // WITH_MQTT_BRIDGE
|
||||
@@ -119,8 +119,8 @@ static const MQTTPresetDef MQTT_PRESETS[MQTT_PRESET_COUNT] = {
|
||||
{ "coloradomesh", "wss://mqtt.meshcore.coloradomesh.org:1883","mqtt.meshcore.coloradomesh.org", ISRG_ROOT_X1, MQTT_AUTH_JWT, MQTT_TOPIC_MESHCORE, 0, true, 55, nullptr, nullptr },
|
||||
{ "dutchmeshcore-1", "wss://collector1.dutchmeshcore.nl:443/mqtt", "collector1.dutchmeshcore.nl", GTS_ROOT_R4, MQTT_AUTH_JWT, MQTT_TOPIC_MESHCORE, 0, true, 55, nullptr, nullptr },
|
||||
{ "dutchmeshcore-2", "wss://collector2.dutchmeshcore.nl:443/mqtt", "collector2.dutchmeshcore.nl", GTS_ROOT_R4, MQTT_AUTH_JWT, MQTT_TOPIC_MESHCORE, 0, true, 55, nullptr, nullptr },
|
||||
{ "meshcore-ca-1", "wss://mqtt1.meshcore.ca:443/mqtt", "mqtt1.meshcore.ca", ISRG_ROOT_X1, MQTT_AUTH_JWT, MQTT_TOPIC_MESHCORE, 0, true, 55, nullptr, nullptr },
|
||||
{ "meshcore-ca-2", "wss://mqtt2.meshcore.ca:443/mqtt", "mqtt2.meshcore.ca", ISRG_ROOT_X1, MQTT_AUTH_JWT, MQTT_TOPIC_MESHCORE, 0, true, 55, nullptr, nullptr },
|
||||
{ "meshcore-ca-1", "wss://mqtt1.meshcore.ca:443/mqtt", "mqtt1.meshcore.ca", ISRG_ROOT_X1, MQTT_AUTH_JWT, MQTT_TOPIC_MESHCORE, 0, true, 55, nullptr, nullptr },
|
||||
{ "meshcore-ca-2", "wss://mqtt2.meshcore.ca:443/mqtt", "mqtt2.meshcore.ca", ISRG_ROOT_X1, MQTT_AUTH_JWT, MQTT_TOPIC_MESHCORE, 0, true, 55, nullptr, nullptr },
|
||||
};
|
||||
|
||||
// Find a preset by name, returns nullptr if not found
|
||||
|
||||
Reference in new issue
Block a user