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
jschenke488 committed Oct 29, 2024
1 parent 8168c55 commit 1393f3b
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/FRCTeam1987/crimson-arena/model"
Expand Down Expand Up @@ -129,6 +131,7 @@ func (ap *AccessPoint) ConfigureTeamWifi(teams [6]*model.Team) error {
url := ap.apiUrl + "/configuration"
httpRequest, err := http.NewRequest("POST", url, bytes.NewReader(jsonBody))
if err != nil {
ap.checkAndLogApiError(err)
return err
}
if ap.password != "" {
Expand Down Expand Up @@ -167,6 +170,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 @@ -217,6 +221,18 @@ func (ap *AccessPoint) statusMatchesLastConfiguration() bool {
return true
}

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 1393f3b

Please sign in to comment.