Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MQTT outbox limits and get_outbox_size() #560

Merged
merged 6 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Breaking
- Implement MQTT outbox limit and get_outbox_size()

### Fixed
- Fix wrong BT configuration version on the c6 (issue #556)

Expand Down
12 changes: 12 additions & 0 deletions src/mqtt/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct MqttClientConfiguration<'a> {
pub task_stack: usize,
pub buffer_size: usize,
pub out_buffer_size: usize,
pub outbox_limit: Option<usize>,

pub username: Option<&'a str>,
pub password: Option<&'a str>,
Expand Down Expand Up @@ -108,6 +109,7 @@ impl Default for MqttClientConfiguration<'_> {
task_stack: 0,
buffer_size: 0,
out_buffer_size: 0,
outbox_limit: None,

username: None,
password: None,
Expand Down Expand Up @@ -316,6 +318,10 @@ impl<'a> TryFrom<&'a MqttClientConfiguration<'a>>
}
}

if let Some(outbox_limit) = conf.outbox_limit {
c_conf.outbox.limit = outbox_limit as _;
}

#[cfg(all(esp_idf_esp_tls_psk_verification, feature = "alloc"))]
let tls_psk_conf = conf.psk.as_ref().map(|psk| psk.try_into()).transpose()?;
#[cfg(not(all(esp_idf_esp_tls_psk_verification, feature = "alloc")))]
Expand Down Expand Up @@ -625,6 +631,12 @@ impl<'a> EspMqttClient<'a> {
Self::check(unsafe { esp_mqtt_client_set_uri(self.raw_client, uri.as_ptr()) })
}

pub fn get_outbox_size(&self) -> usize {
// this is always positive as internally this is converting uint64_t to int (defaults to 0)
let outbox_size = unsafe { esp_mqtt_client_get_outbox_size(self.raw_client) };
outbox_size.max(0) as usize
}

extern "C" fn handle(
event_handler_arg: *mut c_void,
_event_base: esp_event_base_t,
Expand Down