Skip to main content

Crate ebus_rumqttc

Crate ebus_rumqttc 

Source
Expand description

Bundled rumqttc 0.25 connection for the eBus Homie 5 controller and device on tokio.

controller builds an ebus_homie_tokio controller with its own rumqttc client, device a device tree, and pair both on one connection. The host spawns the task’s run; the SDK spawns nothing. The broker coordinates, client id, credentials and TLS come from the caller’s MqttOptions. A host that found its broker over mDNS gives the task a Reresolve hook (ControllerTask::reresolve), which finds the same broker again when connecting fails, at startup or after a lost link, so a broker whose address changed is reached at its new one.

use ebus_rumqttc::ebus_homie_tokio::ebus_homie::controller::{Config, Event};
use ebus_rumqttc::ebus_homie_tokio::{ControllerOptions, Delivered};

let mqtt = rumqttc::MqttOptions::new(ebus_rumqttc::controller_client_id(), "localhost", 1883);
let run = ebus_rumqttc::controller(mqtt, Config::wildcard(), ControllerOptions::default())?;
tokio::spawn(run.task.run());

let mut events = run.events;
while let Some(d) = events.recv().await {
    match d {
        Delivered::Event(Event::DeviceSynced { device, missing: 0, .. }) => {
            let _values = run.handle.device(&device);
        }
        Delivered::Overflow { .. } => {
            let _all = run.handle.devices();
        }
        _ => {}
    }
}

The transport is MQTT over TCP, or TLS with the rustls or native-tls feature. rumqttc’s default maximum incoming packet size is 10 KiB, and a larger $description fails the connection; raise it with MqttOptions::set_max_packet_size for devices that publish one.

On a clean-session reconnect rumqttc discards the requests it had not sent and restores no subscriptions; the controller resubscribes its filters on every CONNACK. The executor hands rumqttc nothing while the link is down and skips every SUBSCRIBE queued before a clean-session link-up, so none is sent after it, and the controller runs with Config::link_up_discards_queued set.

Re-exports§

pub use ebus_homie_tokio;
pub use rumqttc;

Structs§

ControllerTask
The driver, the rumqttc event loop and the command executor, as one future.
DeviceTask
The device driver, the rumqttc event loop and the command executor, as one future.
PairTask
The pair driver, the rumqttc event loop and the command executor, as one future.
RunningController
A controller with its own connection.
RunningDevice
A device tree with its own connection.
RunningPair
A device tree and a controller sharing one connection.

Enums§

Error
Why ControllerTask::run stopped early.

Functions§

controller
A controller for config that connects with mqtt, with Config::link_up_discards_queued set. Nothing runs until the host spawns ControllerTask::run.
controller_client_id
ebus-controller- and 16 random hex digits, after python-sdk’s homie-controller-{uuid} (homie.py:3870).
device
A device tree that connects with mqtt. The broker coordinates, the client id (by convention the root’s id, homie.py:3379), credentials and TLS are the caller’s; the root’s will, a clean session, the inflight cap and the outgoing packet limit are set here, along with TreeConfig::receipts and DeviceOptions::link_up_discards_queued. Nothing runs until the host spawns DeviceTask::run.
pair
A device tree and a controller for config on one connection, configured as device configures it. Nothing runs until the host spawns PairTask::run.

Type Aliases§

Reresolve
Looks the broker up again when connects to it fail: returns its options at the current address, or None to keep the old ones. See ControllerTask::reresolve.