Why: MQTT#

class MQTTPublisher#

Public Functions

std::expected<void, MQTTError> publish(const std::string &msg)#

Publish a message to the configured MQTT topic

Parameters:

msg – The message payload to publish

Returns:

void on success, or MQTTError on failure

~MQTTPublisher()#
MQTTPublisher(const MQTTPublisher&) = delete#
MQTTPublisher &operator=(const MQTTPublisher&) = delete#
MQTTPublisher(MQTTPublisher &&other) noexcept#
MQTTPublisher &operator=(MQTTPublisher &&other) noexcept#

Public Static Functions

static std::expected<MQTTPublisher, MQTTError> create(const std::string &topic, const std::string &host, int port = 1883)#

Create an MQTT publisher connected to the specified broker

Parameters:
  • topic – The MQTT topic to publish to

  • host – The MQTT broker hostname or IP address

  • port – The MQTT broker port (default: 1883)

Returns:

MQTTPublisher on success, or MQTTError on failure

class MQTTError : public Why::Internal::Error#

Public Functions

inline MQTTError(const std::string &msg, int mosquitto_error)#
inline int error_number() const#