XU XUv0.13.1
EN

#embedded/mqtt

导入方式: #embedded/mqtt

公开 API: 1 函数, 8 方法, 2 类型, 2 常量, 0 方法集

标准库包 `#embedded/mqtt`。

struct Message

XuAPI
pub struct Message {
    pub valid bool
    pub payload string
    pub retained bool
}

用途

承载 valid、payload、retained 等属性的结构体。

公开字段

valid bool
字段(bool)
payload string
字段(string)
retained bool
字段(bool)

struct Client

XuAPI
pub struct Client {
    pub error int
    pub received int
    pub published int
    pub retransmits int
}

用途

Mqtt 客户端会话实例,维护与服务端的连接并提供操作接口。

公开字段

error int
字段(int)
received int
字段(int)
published int
字段(int)
retransmits int
字段(int)

create

XuAPI
pub fn create(id string, command_topic string, will_topic string, now int) Client

用途

创建新的文件、目录或资源。

参数

id string
id(string)
command_topic string
command_topic(string)
will_topic string
will_topic(string)
now int
now(int)

返回值

Client — 该类型的值

(&Client) ready

XuAPI
pub fn (c &Client) ready() bool

用途

在 &Client 上执行 ready 操作。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

(&Client) failed

XuAPI
pub fn (c &Client) failed() bool

用途

在 &Client 上执行 failed 操作。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

(&Client) can_publish

XuAPI
pub fn (c &Client) can_publish() bool

用途

&Client 上的操作:执行 can publish 操作。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

($&Client) publish

XuAPI
pub fn (c $&Client) publish(topic &string, payload &string, retain bool) bool

用途

向指定的消息主题或频道广播发布消息。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
topic &string
topic(只读借用,调用方仍持有原值;类型 &string)
payload &string
payload(只读借用,调用方仍持有原值;类型 &string)
retain bool
retain(bool)

返回值

bool — 是否成立

($&Client) feed

XuAPI
pub fn (c $&Client) feed(bytes &string, now int) bool

用途

在 $&Client 上执行 feed 操作。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
bytes &string
bytes(只读借用,调用方仍持有原值;类型 &string)
now int
now(int)

返回值

bool — 是否成立

($&Client) read

XuAPI
pub fn (c $&Client) read() Message

用途

$&Client 上的操作:读出最多 max 字节。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

Message — 该类型的值

($&Client) poll

XuAPI
pub fn (c $&Client) poll(now int) string

用途

在 $&Client 上执行 poll 操作。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
now int
now(int)

返回值

string — 结果字符串

($&Client) reset

XuAPI
pub fn (c $&Client) reset(id string, command_topic string, will_topic string, now int)

用途

$&Client 上的操作:清空内部状态,可再写入或读取。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
id string
id(string)
command_topic string
command_topic(string)
will_topic string
will_topic(string)
now int
now(int)

返回值

不返回值。

const MAX_PACKET

XuAPI
pub const MAX_PACKET = 2048

用途

常量 MAX_PACKET,定义了相关的协议或算法配置参数。

const MAX_PAYLOAD

XuAPI
pub const MAX_PAYLOAD = 768

用途

常量 MAX_PAYLOAD,定义了相关的协议或算法配置参数。