Skip to content

Commit

Permalink
Log a warning with instructions when an AP is configured but the HTTP…
Browse files Browse the repository at this point in the history
… API can't be accessed.
  • Loading branch information
patfair committed Jun 3, 2024
1 parent 6a83399 commit a739e9b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions network/access_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ package network
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"strconv"
"syscall"
"time"

"github.com/Team254/cheesy-arena/model"
Expand Down Expand Up @@ -126,6 +128,7 @@ func (ap *AccessPoint) ConfigureTeamWifi(teams [6]*model.Team) error {
var httpClient http.Client
httpResponse, err := httpClient.Do(httpRequest)
if err != nil {
ap.checkAndLogApiError(err)
return err
}
defer httpResponse.Body.Close()
Expand Down Expand Up @@ -156,6 +159,7 @@ func (ap *AccessPoint) updateMonitoring() error {
var httpClient http.Client
httpResponse, err := httpClient.Do(httpRequest)
if err != nil {
ap.checkAndLogApiError(err)
ap.Status = "ERROR"
return fmt.Errorf("failed to fetch access point status: %v", err)
}
Expand Down Expand Up @@ -189,6 +193,18 @@ func (ap *AccessPoint) updateMonitoring() error {
return nil
}

func (ap *AccessPoint) checkAndLogApiError(err error) {
if errors.Is(err, syscall.ECONNREFUSED) {
log.Printf(
"\x1b[31mThe access point appears to be present at %s but is refusing API connection requests. Note that "+
"from 2024 onwards, you must manually install the API server on the Linksys API before it can be used "+
"with Cheesy Arena. See https://github.com/patfair/frc-radio-api for installation instructions."+
"\u001B[0m",
ap.apiUrl,
)
}
}

// Generates the configuration for the given team's station and adds it to the map. If the team is nil, no entry is
// added for the station.
func addStation(stationsConfigurations map[string]stationConfiguration, station string, team *model.Team) {
Expand Down

0 comments on commit a739e9b

Please sign in to comment.