Skip to content

Commit

Permalink
Merge pull request #136 from TheCacophonyProject/fix-battery-readings
Browse files Browse the repository at this point in the history
Fix battery readings
  • Loading branch information
CameronRP authored Jun 25, 2024
2 parents 476b631 + 84bf082 commit f7bff0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 19 additions & 9 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,10 @@ func (api *ManagementAPI) GetServiceStatus(w http.ResponseWriter, r *http.Reques
}

type BatteryReading struct {
Time string `json:"time"`
MainBattery string `json:"mainBattery"`
RTCBattery string `json:"rtcBattery"`
Time string `json:"time"`
MainBattery string `json:"mainBattery"`
MainBatteryLow string `json:"mainBatteryLow"`
RTCBattery string `json:"rtcBattery"`
}

func getLastBatteryReading() (BatteryReading, error) {
Expand All @@ -785,24 +786,33 @@ func getLastBatteryReading() (BatteryReading, error) {
}

parts := strings.Split(lastLine, ",")
if len(parts) != 3 {
if len(parts) != 4 {
return BatteryReading{}, errors.New("unexpected format in battery-readings.csv")
}

return BatteryReading{
Time: parts[0],
MainBattery: parts[1],
RTCBattery: parts[2],
Time: parts[0],
MainBattery: parts[1],
MainBatteryLow: parts[2],
RTCBattery: parts[3],
}, nil
}

func (api *ManagementAPI) GetTestVideos(w http.ResponseWriter, r *http.Request) {
recordings, err := os.ReadDir("/var/spool/cptv/test-recordings")
recordingNames := []string{}
testRecordingsPath := "/var/spool/cptv/test-recordings"
_, err := os.Stat(testRecordingsPath)
if os.IsNotExist(err) {
http.Error(w, "Directory does not exist", http.StatusNotFound)
json.NewEncoder(w).Encode(recordingNames)
return
}
recordings, err := os.ReadDir(testRecordingsPath)
if err != nil {
serverError(&w, err)
return
}
recordingNames := []string{}

for _, recording := range recordings {
if strings.HasSuffix(recording.Name(), ".cptv") {
recordingNames = append(recordingNames, recording.Name())
Expand Down
2 changes: 1 addition & 1 deletion management-interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func DownloadTemperatureCSV(w http.ResponseWriter, r *http.Request) {
defer file.Close()

w.Header().Set("Content-Type", "text/csv")
w.Header().Set("Content-Disposition", "attachment; filename=battery-readings.csv")
w.Header().Set("Content-Disposition", "attachment; filename=temperature.csv")

_, err = io.Copy(w, file)
if err != nil {
Expand Down

0 comments on commit f7bff0f

Please sign in to comment.