mqtt.publish()
mqtt.publish(topic, message) → number
Publishes a message to an MQTT topic.
Publishes message to topic. Message data can be text or binary: convert
objects with string(obj) first, and pack numeric arrays to binary with
bin.fromArray().
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| topic | string | yes | — | Topic to publish to, e.g. "power_system/battery_voltage". |
| message | string | binary | yes | — | Payload. Objects: string(obj). Numeric arrays: bin.fromArray(). |
Returns
number
0 on success, otherwise an error code.
Example
let ret = mqtt.publish("power_system/battery_voltage", string(14.34));
print("publish:", ret);