Skip to content

Commit

Permalink
refacto: improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kpetremann committed Jun 23, 2023
1 parent 0e16554 commit b50dfb2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *Publisher) Publish(sensorName string, payload interface{}) error {
return err
}

log.Printf("publishing new MQTT message: '%s %s'", p.topicRoot+sensorName, data)
log.Debug().Msgf("publishing new MQTT message: '%s %s'", p.topicRoot+sensorName, data)
t := p.client.Publish(p.topicRoot+sensorName, 0, false, data)
if ok := t.Wait(); !ok {
return errors.New("MQTT server did not confirm receiving the message")
Expand Down
4 changes: 2 additions & 2 deletions internal/sensor/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func WatchSensor(ctx context.Context, dht *dht.DHT, ch chan<- Payload) {

select {
case <-timer.C:
if humidity, temperature, err := dht.ReadRetry(2); err != nil {
if humidity, temperature, err := dht.ReadRetry(3); err != nil {
log.Warn().Err(err).Msg("sensor read error")
} else {
log.Info().Msgf("sensor read: temperature='%f' humidity='%f'", temperature, humidity)
log.Debug().Msgf("sensor read: temperature='%f' humidity='%f'", temperature, humidity)
ch <- Payload{Temperature: temperature, Humidity: humidity}
}
case <-ctx.Done():
Expand Down

0 comments on commit b50dfb2

Please sign in to comment.