API referencestd/mqtt

std/mqtt/hosted

Public declarations, types, methods, and source contracts for std/mqtt/hosted.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/mqtt/hosted"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
bytes core/bytes hosted.dodo
console std/console hosted.dodo
io std/io hosted.dodo
mqtt std/mqtt hosted.dodo
native std/net/native hosted.dodo
net std/net hosted.dodo
operations std/net/operations hosted.dodo
slice core/slice hosted.dodo

WORKSPACE_BYTES

Constant · Source

A blocking MQTT 3.1.1 client over a native TCP connection (mqtt:// URLs). The caller’s workspace holds every packet: its first quarter stages outgoing packets and the rest buffers incoming ones, which bounds the largest message the client can receive. One acknowledged operation is in flight at a time.

pub const WORKSPACE_BYTES: usize = 16384

MIN_WORKSPACE_BYTES

Constant · Source

pub const MIN_WORKSPACE_BYTES: usize = 1024

Options

Struct · Source

Connection settings. Empty username, password and will_topic mean absent.

pub struct Options {
    pub client_id: &[u8]
    pub username: &[u8]
    pub password: &[u8]
    // PINGREQ after this long without sending; 0 disables keep-alive.
    pub keep_alive_s: u16
    pub clean_session: bool
    // Published by the broker if the connection ends without disconnect().
    pub will_topic: &[u8]
    pub will_payload: &[u8]
    pub will_qos: mqtt.QoS
    pub will_retain: bool
    // Resolution, TCP connection and CONNACK together.
    pub connect_timeout_ms: u64
    // Each later write, and each wait for SUBACK, UNSUBACK, PUBACK or PUBCOMP.
    pub timeout_ms: u64
}

Options.new

Function · Source

pub fn new(client_id: &[u8]) -> Options from(client_id)

Location

Struct · Source

pub struct Location {
    pub host: &[u8]
    pub port: u16
}

parse_url

Function · Source

Accepts mqtt://host[:port][/] and bare host[:port]; IPv6 literals use brackets. The port defaults to 1883. Credentials belong in Options.

pub fn parse_url(url: &[u8]) -> Location!mqtt.Error from(url)

Client

Struct · Source

pub struct Client {
    // Private implementation fields omitted.
}

Client.connect

Function · Source

Connects with Options.new(client_id) defaults: clean session, 60 s keep-alive.

pub fn connect(url: &[u8], client_id: &[u8], workspace: &mut[u8]) -> Client!mqtt.Error from(workspace)

Client.connect_with

Function · Source

pub fn connect_with(url: &[u8], options: &Options, workspace: &mut[u8]) -> Client!mqtt.Error from(workspace)

Client.session_present

Function · Source

Whether the broker resumed a stored session (clean_session = false).

pub fn session_present(&self) -> bool

Client.publish

Function · Source

Publishes with QoS 0: no acknowledgement, no retained copy.

pub fn publish(&mut self, topic: &[u8], payload: &[u8]) -> void!mqtt.Error

Client.publish_with

Function · Source

Returns once the message is sent (QoS 0), acknowledged (QoS 1), or released and completed (QoS 2). retain asks the broker to keep it as the topic’s last known value.

pub fn publish_with(&mut self, topic: &[u8], payload: &[u8], qos: mqtt.QoS, retain: bool) -> void!mqtt.Error

Client.subscribe

Function · Source

Returns the QoS the broker granted, which may be lower than requested. A refused subscription fails with Rejected and leaves the client usable.

pub fn subscribe(&mut self, filter: &[u8], qos: mqtt.QoS) -> mqtt.QoS!mqtt.Error

Client.unsubscribe

Function · Source

pub fn unsubscribe(&mut self, filter: &[u8]) -> void!mqtt.Error

Client.receive

Function · Source

Waits for the next message from a subscription. The message borrows the workspace and is acknowledged (QoS 1 and 2) when the client is next used. Keep-alive pings are sent while waiting.

pub fn receive(&mut self) -> mqtt.Message!mqtt.Error from(self)

Client.poll

Function · Source

Like receive, but returns none after timeout_ms without a message; 0 only drains what has already arrived. Call it at least once per keep-alive interval while idle, so the client can answer for itself.

pub fn poll(&mut self, timeout_ms: u64) -> Option<mqtt.Message>!mqtt.Error from(self)

Client.disconnect

Function · Source

Ends the session cleanly: the broker discards the will message.

pub fn disconnect(&mut self) -> void!mqtt.Error

Print

Struct · Source

Handler that writes “topic payload” lines to standard output; app.print() and broker.print() return it.

pub struct Print {

}

Print.handle

Function · Source

pub fn handle(&mut self, message: &mqtt.Message, outbox: &mut mqtt.Outbox) -> void!mqtt.Error

Search every guide, reference page, and API declaration.