Skip to content

Commit

Permalink
Set last will (#56)
Browse files Browse the repository at this point in the history
* add last will and comment disconnect

* contribution

* put back manual server offline
  • Loading branch information
gaetancollaud authored Jan 21, 2025
1 parent bb884da commit b4cdb7b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ go install
go run .
```

### Build for docker

```shell
CGO_ENABLED=0 GOOS=linux GOARCH=amd64
docker compose build
```

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ PLATFORM=local

# Build all files.
build:
@echo "==> Building ./dist/sdm"
@echo "==> Building..."
env GOOS=linux GOARCH=amd64 go build -o dist/digitalstrom-mqtt-amd64 ./main.go
.PHONY: build

build-arm:
@echo "==> Building ./dist/sdm"
@echo "==> Building..."
env GOOS=linux GOARCH=arm GOARM=5 go build -o dist/digitalstrom-mqtt-arm ./main.go
.PHONY: build

Expand Down
3 changes: 2 additions & 1 deletion pkg/mqtt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ func NewClient(options *ClientOptions) Client {
}
mqttOptions := mqtt.NewClientOptions().
AddBroker(options.MqttUrl).
SetClientID("digitalstrom-mqtt-" + uuid.New().String()).
SetClientID("digitalstrom-mqtt-"+uuid.New().String()).
SetOrderMatters(false).
SetUsername(options.Username).
SetPassword(options.Password).
SetAutoReconnect(true).
SetWill(serverStatus, Offline, QOS, true).
SetReconnectingHandler(func(client mqtt.Client, opts *mqtt.ClientOptions) {
log.Info().Str("url", options.MqttUrl).Msg("Reconnecting to MQTT server.")
subscriptions.shouldReconnect = true
Expand Down

0 comments on commit b4cdb7b

Please sign in to comment.