Skip to content

Commit

Permalink
Add ESP station reboot detection
Browse files Browse the repository at this point in the history
  • Loading branch information
3cky committed Dec 10, 2021
1 parent b2bf04a commit 5817d25
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion station.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type EspStation struct {

heaterPin int
heaterState HeaterState

lastUptime *time.Duration
}

func NewEspStation(version, host string, port int, heaterPin int, tokenId string) *EspStation {
Expand Down Expand Up @@ -150,10 +152,19 @@ func (es *EspStation) GetData() (*StationData, error) {
}
log.Debugf("token ID: %s", tokenId)

uptime := time.Duration(data.System.Uptime) * time.Minute

if es.lastUptime != nil && uptime < *es.lastUptime {
log.Warn("ESP station reboot detected")
es.heaterState = HeaterOff
}

es.lastUptime = &uptime

return &StationData{
Version: es.version,
TokenId: tokenId,
Uptime: time.Duration(data.System.Uptime) * time.Minute,
Uptime: uptime,
LastMeasurement: m,
}, nil
}
Expand Down

0 comments on commit 5817d25

Please sign in to comment.