Skip to content

Commit

Permalink
update deps and set user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcichra committed Oct 13, 2023
1 parent c79d86d commit e41e7eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gps_collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/gofrs/flock v0.8.1 // indirect
github.com/joncrlsn/dque v0.0.0-20211108142734-c2ef48c5192a
github.com/stratoberry/go-gpsd v1.2.0
golang.org/x/sys v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
)

require github.com/pkg/errors v0.9.1 // indirect
4 changes: 2 additions & 2 deletions gps_collector/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/stratoberry/go-gpsd v1.2.0 h1:Ia0TUd5eIUgLl7/MFFWnAa6e42ACrJt18MR7+HRNV9A=
github.com/stratoberry/go-gpsd v1.2.0/go.mod h1:nVf/vTgfYxOMxiQdy9BtJjojbFRtG8H3wNula++VgkU=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
18 changes: 12 additions & 6 deletions gps_collector/gps_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const database = "public"
const table = "gps"
const TPVInterval = 10

//gps record with hostname metadata
//jonathandbriggs: Added cputemp scraping for raspi.
// gps record with hostname metadata
// jonathandbriggs: Added cputemp scraping for raspi.
type dbRecord struct {
*gpsd.TPVReport
Hostname string `json:"hostname"`
Cputemp float64 `json:"cputemp"`
}

//gpsRecord - a basic GPS datapoint
// gpsRecord - a basic GPS datapoint
type gpsRecord struct {
Value gpsd.TPVReport
}
Expand Down Expand Up @@ -130,15 +130,21 @@ func queueToPost(q *dque.DQue, h *http.Client) {

log.Println("POSTING:", string(b))
// post
resp, err := h.Post(url+"/"+database+"/"+table, "application/json", bytes.NewBuffer(b))
req, err := http.NewRequest("POST", url+"/"+database+"/"+table, bytes.NewBuffer(b))
if err != nil {
log.Println(err)
continue
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "gps-collector")

resp, err := h.Do(req)
if err != nil {
log.Println(err)
continue
}

log.Println("response Status:", resp.Status)
// body, _ := ioutil.ReadAll(resp.Body)
// log.Println("response Body:", string(body))
if resp.StatusCode == 200 {
// Dequeue this variable now
_, err = q.Dequeue()
Expand Down

0 comments on commit e41e7eb

Please sign in to comment.