Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectHandler ¶
ConnectHandler returns a function that logs a message when the MQTT client successfully connects to the broker.
Types ¶
type Mqtt ¶
type Mqtt struct { Topic string MgtUrl string ClientID uuid.UUID // contains filtered or unexported fields }
func NewMqtt ¶
NewMqtt initializes a new Mqtt instance with given configuration, log level, and context. It sets up the logger, client options, and handles connection and reconnection behaviors. It also handles graceful disconnection upon context cancellation and returns the created Mqtt instance or error.
func (*Mqtt) Connect ¶
Connect establishes a connection to the MQTT broker using the provided client options. If the connection fails, it logs the error and returns an aggregated error.
func (*Mqtt) ConnectHandler ¶
ConnectHandler returns a function that logs a message when the MQTT client successfully connects to the broker.
func (*Mqtt) ConnectLostHandler ¶
ConnectLostHandler returns a function that handles MQTT connection loss by logging a warning message with the error details.
func (*Mqtt) Disconnect ¶
func (m *Mqtt) Disconnect()
Disconnect terminates the connection to the MQTT broker, waits up to 500 milliseconds, logs the action, and sets the client to nil.
func (*Mqtt) SendAlarm ¶
func (m *Mqtt) SendAlarm(events model.FCTSDataModel) error
SendAlarm logs an unrecoverable error and indicates that alarm sending is not available over MQTT.
func (*Mqtt) SendAlarmRaw ¶
SendAlarmRaw publishes a byte slice `b` to the configured MQTT topic as a QoS 1 message. It waits for up to 200 milliseconds for the publish operation to complete. If the publish operation exceeds the timeout, the function logs an error message.