Skip to content

Commit

Permalink
set mqtt autoreconnect to true
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetancollaud committed Feb 3, 2024
1 parent 4f4a8ec commit af62c78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions docs/api/zones.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @no-cookie-jar
GET {{host}}/api/v1/apartment/zones
Authorization: Bearer {{api-key}}

###

// @no-cookie-jar
GET {{host}}/api/v1/apartment/zones/status
Authorization: Bearer {{api-key}}


###
// @no-cookie-jar
PATCH {{host}}/api/v1/apartment/zones/5/status
Authorization: Bearer {{api-key}}
Content-Type: application/json

[
{
"op": "replace",
"path": "/applications/temperature/setpoint",
"value": 20
}
]


7 changes: 6 additions & 1 deletion pkg/mqtt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func NewClient(options *ClientOptions) Client {
SetClientID("digitalstrom-mqtt-" + uuid.New().String()).
SetOrderMatters(false).
SetUsername(options.Username).
SetPassword(options.Password)
SetPassword(options.Password).
SetAutoReconnect(true).
SetReconnectingHandler(func(client mqtt.Client, options *mqtt.ClientOptions) {
log.Info().Msg("Reconnecting to MQTT server.")
})

return &client{
mqttClient: mqtt.NewClient(mqttOptions),
Expand All @@ -64,6 +68,7 @@ func NewClient(options *ClientOptions) Client {
}

func (c *client) Connect() error {

t := c.mqttClient.Connect()
<-t.Done()
if t.Error() != nil {
Expand Down

0 comments on commit af62c78

Please sign in to comment.