Add safeguard on thermal sensor failures
This commit is contained in:
parent
9e33f77b3d
commit
c3ecc197cb
1 changed files with 19 additions and 0 deletions
|
@ -34,12 +34,15 @@ var (
|
||||||
// ConfigUpdates receives the list of sensors to read
|
// ConfigUpdates receives the list of sensors to read
|
||||||
ConfigUpdates chan []string
|
ConfigUpdates chan []string
|
||||||
sensors []string
|
sensors []string
|
||||||
|
accErrTrigger int
|
||||||
|
accErrSensor map[string]int
|
||||||
)
|
)
|
||||||
|
|
||||||
func Initialize() {
|
func Initialize() {
|
||||||
sensors = make([]string, 0)
|
sensors = make([]string, 0)
|
||||||
C = make(chan TemperatureReading, 30)
|
C = make(chan TemperatureReading, 30)
|
||||||
ConfigUpdates = make(chan []string, 1)
|
ConfigUpdates = make(chan []string, 1)
|
||||||
|
accErrSensor = make(map[string]int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PollSensors(ctx context.Context, wg *sync.WaitGroup, readingInterval time.Duration) {
|
func PollSensors(ctx context.Context, wg *sync.WaitGroup, readingInterval time.Duration) {
|
||||||
|
@ -59,13 +62,26 @@ func PollSensors(ctx context.Context, wg *sync.WaitGroup, readingInterval time.D
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
if accErrTrigger > 60 {
|
||||||
|
log.Fatal("Thermal bulk read failed 60 times in a row -- terminating")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, sensor := range sensors {
|
||||||
|
if accErrSensor[sensor] > 60 {
|
||||||
|
log.Fatalf("Thermal sensor read of %v failed 60 times in a row -- terminating", sensor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger a bulk read to start conversion on all sensors.
|
// Trigger a bulk read to start conversion on all sensors.
|
||||||
if err := triggerBulkRead(); err != nil {
|
if err := triggerBulkRead(); err != nil {
|
||||||
|
accErrTrigger++
|
||||||
hub.CaptureException(err)
|
hub.CaptureException(err)
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accErrTrigger = 0
|
||||||
|
|
||||||
// Ensure that we wait for sensors to convert data.
|
// Ensure that we wait for sensors to convert data.
|
||||||
deltaSleep := sensorConversionTime - time.Since(start)
|
deltaSleep := sensorConversionTime - time.Since(start)
|
||||||
if deltaSleep > 0 {
|
if deltaSleep > 0 {
|
||||||
|
@ -96,11 +112,14 @@ func readSensors() {
|
||||||
dur := time.Since(start).Seconds()
|
dur := time.Since(start).Seconds()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
accErrSensor[sensor]++
|
||||||
hub.CaptureException(err)
|
hub.CaptureException(err)
|
||||||
log.Printf("Error reading temperature sensor %v: %v", sensor, err)
|
log.Printf("Error reading temperature sensor %v: %v", sensor, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accErrSensor[sensor] = 0
|
||||||
|
|
||||||
r := TemperatureReading{
|
r := TemperatureReading{
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
Sensor: sensor,
|
Sensor: sensor,
|
||||||
|
|
Loading…
Reference in a new issue