Skip to content

Commit

Permalink
Merge pull request #3 from cliviu74/bugfix/json-api-issue
Browse files Browse the repository at this point in the history
Fixed json  array append issue
  • Loading branch information
cliviu74 authored Apr 26, 2018
2 parents cfda62f + db5dd9e commit ec1b1fa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type sensor struct {
}

var (
sensors = []sensor{}
sensors = make([]sensor, 1, 2)
onewireDevicePath = "/sys/bus/w1/devices/"
onewireDeviceList []string
hostname, _ = os.Hostname()
Expand Down Expand Up @@ -97,14 +97,17 @@ func observeOnewireTemperature() {
log.Fatal("Error getting Onewire device list")
}
for {
sensors = sensors[:len(onewireDeviceList)]
index := 0
for _, deviceID := range onewireDeviceList {
value, err := readOnewireDevicePayload(deviceID)
if err != nil {
log.WithFields(log.Fields{"deviceID": deviceID}).Error("Error reading from device")
}
log.WithFields(log.Fields{"deviceID": deviceID, "value": value, "hostname": hostname}).Info("Value read from device")
onewireTemperatureC.With(prometheus.Labels{"device_id": deviceID, "hostname": hostname}).Set(value)
sensors = append(sensors, sensor{SensorID: deviceID, SensorType: "temperature", SensorValue: value})
sensors[index] = sensor{SensorID: deviceID, SensorType: "temperature", SensorValue: value}
index++
}
time.Sleep(60 * time.Second)
}
Expand Down

0 comments on commit ec1b1fa

Please sign in to comment.