Skip to content

Commit dff3a16

Browse files
authored
Merge pull request #333 from quartiq/minimq-0.13
mqtt: minimq 0.13
2 parents c1e2c11 + 9294a35 commit dff3a16

10 files changed

Lines changed: 237 additions & 206 deletions

File tree

miniconf_mqtt/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [UNRELEASED](https://github.com/quartiq/miniconf/compare/miniconf_mqtt-v0.21.0...HEAD) - DATE
1010

11+
### Changed
12+
13+
* MQTT network operations now take caller-owned `minimq::Connection` handles. `Miniconf::new()`
14+
still returns the durable `minimq::Session` used to establish each connection, and
15+
`Miniconf::startup()` reads the connect event directly from the handle.
16+
1117
## [0.21.0](https://github.com/quartiq/miniconf/compare/miniconf_mqtt-v0.20.0...miniconf_mqtt-v0.21.0) - 2026-06-10
1218

1319
### Changed

miniconf_mqtt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ miniconf = { version = "0.21.0", features = [
2424
"defmt",
2525
"json-core",
2626
], default-features = false, path = "../miniconf" }
27-
minimq = "0.12"
27+
minimq = "0.13"
2828
embassy-time = "0.5.1"
2929
embedded-io = "0.7"
3030
defmt = "1.0.1"

miniconf_mqtt/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
`miniconf_mqtt` exposes a [`miniconf`](../miniconf/README.md) tree over MQTT using
44
[`minimq`](../../minimq/README.md).
5-
It owns Miniconf MQTT protocol state; the caller owns both the MQTT session and the settings tree.
5+
It owns Miniconf MQTT protocol state; the caller owns the MQTT session, live connection, and
6+
settings tree.
67

78
## Quick start
89

910
See the runnable example in [examples/miniconf.rs](examples/miniconf.rs).
1011

1112
For simple services, `miniconf_mqtt` provides two complete unbounded helpers on top:
1213

13-
- `miniconf.startup(&mut session, &settings, connect_event)`
14-
- `miniconf.serve(&mut session, &mut settings, on_unhandled)`
14+
- `miniconf.startup(&mut connection, &settings)`
15+
- `miniconf.serve(&mut connection, &mut settings, on_unhandled)`
1516

1617
They are the easiest way to serve a Miniconf tree over MQTT when you do not need stepwise control,
1718
bounded queued follow-up, or exact control over unrelated inbound traffic during protocol work.
@@ -28,9 +29,9 @@ For precise control, `miniconf_mqtt` exposes four explicit building blocks:
2829
Typical flow:
2930

3031
1. construct Miniconf MQTT state and session with `Miniconf::new(prefix, config)`
31-
2. call `let event = session.connect(io).await?`
32-
3. call `miniconf.startup(&mut session, &settings, event)`
33-
4. in steady state, call `miniconf.serve(&mut session, &mut settings, on_unhandled)`
32+
2. call `let mut connection = session.connect(io).await?`
33+
3. call `miniconf.startup(&mut connection, &settings)`
34+
4. in steady state, call `miniconf.serve(&mut connection, &mut settings, on_unhandled)`
3435
5. use `Publisher::root(Settings::SCHEMA)` or `Publisher::by_key(Settings::SCHEMA, key)` for explicit app-side retained
3536
republish
3637

@@ -40,10 +41,10 @@ Retained settings recovery is a cold-boot step:
4041

4142
```rust
4243
let mut load = miniconf_mqtt::LoadRetained::new();
43-
load.run(&mut miniconf, &mut session, &mut settings).await?;
44+
load.run(&mut miniconf, &mut connection, &mut settings).await?;
4445

4546
let mut startup = miniconf_mqtt::Startup::connected(&mut miniconf);
46-
startup.run(&mut miniconf, &mut session, &settings).await?;
47+
startup.run(&mut miniconf, &mut connection, &settings).await?;
4748
```
4849

4950
`LoadRetained` applies only retained `settings/<leaf>` publications with `auth=""`, waits for
@@ -53,7 +54,7 @@ retained pruning remains a client/tooling operation.
5354

5455
Use it only before the first Miniconf MQTT startup of a device process. On a device reconnect or
5556
network glitch, keep the live settings in RAM authoritative and call
56-
`miniconf.startup(..., connect_event)`:
57+
`miniconf.startup(...)`; it reads the connect event from the live connection:
5758

5859
- `ConnectEvent::Connected`: the broker did not resume the MQTT session, so Miniconf republishes
5960
schema, settings, `set/#`, and `alive`
@@ -103,8 +104,8 @@ Stepwise APIs:
103104

104105
Practical boundary:
105106

106-
- use `Session::poll()` to wait for any later session progress
107-
- use `Session::recv()` when you specifically want the next inbound publish
107+
- use `Connection::poll()` to wait for any later session progress
108+
- use `Connection::recv()` when you specifically want the next inbound publish
108109
- `Startup::step()` may consume and discard inbound publishes while bootstrapping
109110
- `Publisher::step()` must not consume unrelated inbound publishes
110111
- `Service::step()` must not consume unrelated inbound publishes
@@ -118,9 +119,9 @@ Bounded cooperative serving:
118119
let mut service = Service::<4>::new();
119120

120121
loop {
121-
let _empty = service.step(&mut miniconf, &mut session, &settings).await?;
122+
let _empty = service.step(&mut miniconf, &mut connection, &settings).await?;
122123

123-
if let Some(inbound) = session.poll().await? {
124+
if let Some(inbound) = connection.poll().await? {
124125
match service.handle(&mut miniconf, &mut settings, &inbound) {
125126
ServiceEvent::Unhandled => { /* app traffic */ }
126127
ServiceEvent::Changed(_) | ServiceEvent::Busy | ServiceEvent::Idle => {}

miniconf_mqtt/examples/miniconf.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ async fn main() -> Result<(), Box<dyn core::error::Error>> {
3434
loop {
3535
defmt::info!("connecting to mqtt://{=str}", broker.as_str());
3636
let io = tokio::net::TcpStream::connect(&broker).await?;
37-
let event = session.connect(FromTokio::new(io)).await?;
38-
miniconf.startup(&mut session, &settings, event).await?;
39-
defmt::info!("mqtt session ready event={}", defmt::Debug2Format(&event));
37+
let mut connection = session.connect(FromTokio::new(io)).await?;
38+
miniconf.startup(&mut connection, &settings).await?;
39+
defmt::info!(
40+
"mqtt session ready event={}",
41+
defmt::Debug2Format(&connection.connect_event())
42+
);
4043

4144
loop {
42-
match miniconf.serve(&mut session, &mut settings, |_| ()).await {
45+
match miniconf.serve(&mut connection, &mut settings, |_| ()).await {
4346
Ok(Event::Unhandled(())) => {}
4447
Ok(Event::Changed(idx)) => {
4548
defmt::info!("settings updated key={}", idx);

0 commit comments

Comments
 (0)