Merge observer firmware and webconfig updates
# Conflicts: # MQTT_INTERNALS.md # build.sh # docs/cli_commands.md # examples/simple_repeater/MyMesh.cpp # examples/simple_repeater/MyMesh.h # examples/simple_repeater/UITask.cpp # examples/simple_room_server/MyMesh.cpp # examples/simple_room_server/MyMesh.h # examples/simple_room_server/UITask.cpp # examples/simple_sensor/SensorMesh.cpp # platformio.ini # scripts/generate_webconfig_html.py # src/MeshCore.h # src/helpers/CommonCLI.cpp # src/helpers/CommonCLI.h # src/helpers/CommonCLI_Observer.cpp # src/helpers/ESP32Board.h # src/helpers/MQTTMessageBuilder.cpp # src/helpers/MQTTPresets.h # src/helpers/NRF52Board.cpp # src/helpers/NRF52Board.h # src/helpers/bridges/MQTTBridge.cpp # src/helpers/bridges/MQTTBridge.h # src/helpers/esp32/WebConfigServer.cpp # src/helpers/esp32/WebConfigServer.h # src/helpers/radiolib/RadioLibWrappers.cpp # src/helpers/radiolib/RadioLibWrappers.h # variants/lilygo_tbeam_SX1262/platformio.ini # variants/lilygo_tbeam_SX1276/platformio.ini # variants/lilygo_tlora_v2_1/platformio.ini # webui/index.html
This commit is contained in:
commit
c1caa5ad81
109 files changed
+14844
-2297
No files matched your search
@@ -50,6 +50,17 @@ PsychicMqttClient &PsychicMqttClient::setKeepAlive(int keepAlive)
|
||||
return *this;
|
||||
}
|
||||
|
||||
PsychicMqttClient &PsychicMqttClient::setNetworkTimeout(int timeoutMs)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR == 5
|
||||
_mqtt_cfg.network.timeout_ms = timeoutMs;
|
||||
#else
|
||||
_mqtt_cfg.network_timeout_ms = timeoutMs;
|
||||
#endif
|
||||
_config_dirty = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PsychicMqttClient &PsychicMqttClient::setAutoReconnect(bool reconnect)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR == 5
|
||||
@@ -61,6 +72,17 @@ PsychicMqttClient &PsychicMqttClient::setAutoReconnect(bool reconnect)
|
||||
return *this;
|
||||
}
|
||||
|
||||
PsychicMqttClient &PsychicMqttClient::setMessageRetransmitTimeout(int timeoutMs)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR == 5
|
||||
_mqtt_cfg.session.message_retransmit_timeout = timeoutMs;
|
||||
#else
|
||||
_mqtt_cfg.message_retransmit_timeout = timeoutMs;
|
||||
#endif
|
||||
_config_dirty = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PsychicMqttClient &PsychicMqttClient::setClientId(const char *clientId)
|
||||
{
|
||||
#if ESP_IDF_VERSION_MAJOR == 5
|
||||
@@ -520,17 +542,44 @@ int PsychicMqttClient::publish(const char *topic, int qos, bool retain, const ch
|
||||
|
||||
if (async)
|
||||
{
|
||||
// QoS0 async publishes are stored in the esp-mqtt outbox (store=true) so that
|
||||
// packet topics keep flowing -- enqueue(store=false) produced false-failure
|
||||
// semantics that stalled the packet path. The outbox has no size bound of its
|
||||
// own (esp-mqtt frees entries only on send-ack or time-based expiry), so on a
|
||||
// stalled uplink QoS0 frames pile up on internal heap without limit. Cap it
|
||||
// here: if the outbox is already at/over _outbox_limit, drop this QoS0 message
|
||||
// and report -2 ("outbox full") so the caller can retry/drop. QoS1/2 (durable,
|
||||
// low-rate) are never gated.
|
||||
if (qos == 0 && _outbox_limit > 0 && _client != nullptr &&
|
||||
esp_mqtt_client_get_outbox_size(_client) >= _outbox_limit)
|
||||
{
|
||||
_outbox_drops++;
|
||||
static unsigned long last_full_log = 0;
|
||||
unsigned long now = millis();
|
||||
if (now - last_full_log > 5000)
|
||||
{
|
||||
ESP_LOGW(TAG, "Outbox at cap (%u bytes); dropping QoS0 message to topic %s",
|
||||
(unsigned)_outbox_limit, topic);
|
||||
last_full_log = now;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Enqueuing message to topic %s with QoS %d", topic, qos);
|
||||
// Hotfix: restore legacy outbox behavior for QoS0 async publishes.
|
||||
// This avoids false-failure semantics from enqueue(store=false) on some
|
||||
// connected paths where packet topics stop flowing.
|
||||
bool store_in_outbox = true;
|
||||
return esp_mqtt_client_enqueue(_client, topic, payload, length, qos, retain, store_in_outbox);
|
||||
int result = esp_mqtt_client_enqueue(_client, topic, payload, length, qos, retain, store_in_outbox);
|
||||
if (result < 0) _publish_err++; else _publish_ok++;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGV(TAG, "Publishing message to topic %s with QoS %d", topic, qos);
|
||||
return esp_mqtt_client_publish(_client, topic, payload, length, qos, retain);
|
||||
// Synchronous write (used for QoS0 packet publishes). A negative result is a real
|
||||
// send failure (socket error / network_timeout on a stalled link), tracked here so
|
||||
// callers can surface delivery health without per-message logging.
|
||||
int result = esp_mqtt_client_publish(_client, topic, payload, length, qos, retain);
|
||||
if (result < 0) _publish_err++; else _publish_ok++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,6 +597,40 @@ esp_mqtt_client_config_t *PsychicMqttClient::getMqttConfig()
|
||||
return &_mqtt_cfg;
|
||||
}
|
||||
|
||||
PsychicMqttClient &PsychicMqttClient::setOutboxLimit(size_t bytes)
|
||||
{
|
||||
_outbox_limit = bytes;
|
||||
return *this;
|
||||
}
|
||||
|
||||
size_t PsychicMqttClient::getOutboxSize()
|
||||
{
|
||||
if (_client == nullptr)
|
||||
return 0;
|
||||
int size = esp_mqtt_client_get_outbox_size(_client);
|
||||
return size > 0 ? (size_t)size : 0;
|
||||
}
|
||||
|
||||
size_t PsychicMqttClient::getOutboxLimit()
|
||||
{
|
||||
return _outbox_limit;
|
||||
}
|
||||
|
||||
unsigned long PsychicMqttClient::getOutboxDrops()
|
||||
{
|
||||
return _outbox_drops;
|
||||
}
|
||||
|
||||
unsigned long PsychicMqttClient::getPublishOk()
|
||||
{
|
||||
return _publish_ok;
|
||||
}
|
||||
|
||||
unsigned long PsychicMqttClient::getPublishErr()
|
||||
{
|
||||
return _publish_err;
|
||||
}
|
||||
|
||||
void PsychicMqttClient::_onMqttEventStatic(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
|
||||
{
|
||||
// Since this is a static function, we need to cast the first argument (void*) back to the class instance type
|
||||
|
||||
@@ -126,6 +126,29 @@ public:
|
||||
*/
|
||||
PsychicMqttClient &setAutoReconnect(bool reconnect = true);
|
||||
|
||||
/**
|
||||
* @brief Sets the network operation timeout in milliseconds. esp-mqtt aborts a
|
||||
* network read/write (including a synchronous publish's socket write) if it does
|
||||
* not complete within this window. A lower value bounds how long a synchronous
|
||||
* QoS0 publish can block on a stalled/half-open socket before failing and letting
|
||||
* the slot flip to disconnected. esp-mqtt's default is 10000.
|
||||
*
|
||||
* @param timeoutMs Network timeout in milliseconds.
|
||||
* @return A reference to the PsychicMqttClient instance.
|
||||
*/
|
||||
PsychicMqttClient &setNetworkTimeout(int timeoutMs);
|
||||
|
||||
/**
|
||||
* @brief Sets the retransmit timeout for unacknowledged QoS 1/2 messages.
|
||||
* esp-mqtt resends an unacked PUBLISH (DUP flag set) every time this
|
||||
* timeout elapses, so a value shorter than the broker's ack latency
|
||||
* produces byte-identical duplicates on the wire.
|
||||
*
|
||||
* @param timeoutMs Retransmit timeout in milliseconds. esp-mqtt's default is 1000.
|
||||
* @return A reference to the PsychicMqttClient instance.
|
||||
*/
|
||||
PsychicMqttClient &setMessageRetransmitTimeout(int timeoutMs);
|
||||
|
||||
/**
|
||||
* @brief Sets the client ID for the MQTT connection.
|
||||
*
|
||||
@@ -399,6 +422,55 @@ public:
|
||||
*/
|
||||
esp_mqtt_client_config_t *getMqttConfig();
|
||||
|
||||
/**
|
||||
* @brief Caps the size of the esp-mqtt outbox for async QoS 0 publishes.
|
||||
*
|
||||
* QoS 0 async publishes are forced into the esp-mqtt outbox (store=true) so
|
||||
* packet topics keep flowing, but the outbox has no size bound of its own --
|
||||
* it only frees entries on send-ack or time-based expiry. On a stalled uplink
|
||||
* the entries accumulate on internal heap without limit. When the current
|
||||
* outbox size is at/over this cap, publish() drops the new QoS 0 message
|
||||
* (returns -2) instead of enqueuing it, applying backpressure. 0 disables the
|
||||
* cap. QoS 1/2 publishes are never gated by this.
|
||||
*
|
||||
* @param bytes Maximum outbox size in bytes, or 0 to disable.
|
||||
* @return A reference to the PsychicMqttClient instance.
|
||||
*/
|
||||
PsychicMqttClient &setOutboxLimit(size_t bytes);
|
||||
|
||||
/**
|
||||
* @brief Returns the current esp-mqtt outbox size in bytes (0 if the client
|
||||
* is not initialized). Useful for diagnostics/backpressure monitoring.
|
||||
*
|
||||
* @return Current outbox size in bytes.
|
||||
*/
|
||||
size_t getOutboxSize();
|
||||
|
||||
/**
|
||||
* @brief Returns the configured outbox cap in bytes (0 = disabled). Lets
|
||||
* callers confirm the cap is actually applied to this client.
|
||||
*/
|
||||
size_t getOutboxLimit();
|
||||
|
||||
/**
|
||||
* @brief Returns the cumulative count of QoS0 messages dropped because the
|
||||
* outbox was at/over the cap. Monotonic; useful for backpressure diagnostics.
|
||||
*/
|
||||
unsigned long getOutboxDrops();
|
||||
|
||||
/**
|
||||
* @brief Cumulative count of publishes that were accepted (enqueued or written
|
||||
* successfully). Monotonic. Pair with getPublishErr() for delivery-health stats.
|
||||
*/
|
||||
unsigned long getPublishOk();
|
||||
|
||||
/**
|
||||
* @brief Cumulative count of publishes that failed (negative return from the
|
||||
* synchronous write or async enqueue -- socket error / network timeout). Monotonic.
|
||||
* A rising value indicates the uplink is dropping publishes.
|
||||
*/
|
||||
unsigned long getPublishErr();
|
||||
|
||||
private:
|
||||
esp_mqtt_client_handle_t _client = nullptr;
|
||||
esp_mqtt_client_config_t _mqtt_cfg;
|
||||
@@ -407,6 +479,15 @@ private:
|
||||
bool _stopMqttClient = false;
|
||||
bool _config_dirty = true;
|
||||
|
||||
// Runtime cap on the esp-mqtt outbox for QoS 0 async publishes (bytes).
|
||||
// 0 = disabled. Enforced in publish(); not an esp-mqtt config field.
|
||||
size_t _outbox_limit = 0;
|
||||
// Cumulative count of QoS0 publishes dropped because the outbox hit the cap.
|
||||
unsigned long _outbox_drops = 0;
|
||||
// Cumulative publish accept/fail counts (any QoS, sync or async path).
|
||||
unsigned long _publish_ok = 0;
|
||||
unsigned long _publish_err = 0;
|
||||
|
||||
// Multipart message reassembly. _buffer is lazily allocated at connect() time
|
||||
// to match the configured buffer size, then reused for the client's lifetime.
|
||||
// _topic is inline storage, never heap-allocated.
|
||||
|
||||
Reference in new issue
Block a user