-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOtherGPS.rmd
108 lines (97 loc) · 3.24 KB
/
OtherGPS.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Other GPS devices
## Lonestar
email // swfsc8901$adrift
key:
f22e32e6ba5953978f0875c86f07c5ffae24b2bc
This should get us what we need:
https://fleetone.lonestartracking.com/api/#method-route-List
use PAMmisc:::fmtPsx8601 to posxic->char
https://fleetone.lonestartracking.com/api/v1/unit.json?key=yourapikey
HTTP GET method - all parameters must be added to the url query string, for example:
https://fleetone.lonestartracking.com/api/v1/unit/list.json?key=yourapikey&unit_id[]=14700&unit_id[]=14701
Route list method is what we need
https://fleetone.lonestartracking.com/api/v1/route/list.json
from & till datetime string args for route
CAN ONLY do 31 DAYS AT A TIME
FROM ONLY DOESNT WORK
```{r}
key <- 'f22e32e6ba5953978f0875c86f07c5ffae24b2bc'
keyChar <- paste0('?key=', key)
routeURL <- 'https://fleetone.lonestartracking.com/api/v1/route/list.json'
fromPsx <- as.POSIXct('2021-10-01 00:00:00', tz='UTC')
tillPsx <- as.POSIXct('2021-10-30 00:00:00', tz='UTC')
fromChar <- paste0('&from=', PAMmisc:::fmtPsx8601(fromPsx))
tillChar <- paste0('&till=', PAMmisc:::fmtPsx8601(tillPsx))
fromTil <- GET(paste0(routeURL, keyChar, fromChar, tillChar))
ftJSON <- fromJSON(rawToChar(fromTil$content))
```
```{r}
lsUnitToDf <- function(x, start=TRUE) {
id <- x$unit_id
data <- dplyr::bind_rows(lapply(x$routes, function(r) {
if(isTRUE(start)) {
return(r$start[c('time', 'lat', 'lng')])
}
r$end[c('time', 'lat', 'lng')]
}))
data$time <- as.POSIXct(data$time, format='%Y-%m-%dT%H:%M:%SZ', tz='UTC')
data$id <- id
data
}
lsToDf <- function(x) {
dplyr::bind_rows(lapply(x$data$units, function(u) {
lsUnitToDf(u, start=FALSE)
}))
}
lsDf <- lsToDf(ftJSON)
```
## Rock7
my email // Shannon1234*
As of 2/4/2022 Still seems like only PUSH API is avialable, would need to set up via IT
Last time I tried the interface was not even working to
## BlueOcean
adrift // $JuzzeBB490
https://blueapi.boggroup.net/docs/
BuoyId 176 is our only one right now
Set up authorization by getting token using username/PW. This is passed as header
to future calls
```{r}
library(httr)
authURL <- 'https://blueapi.boggroup.net/api/v2/auth'
authBody <- list(type='login', username='adrift', password='$JuzzeBB490')
authPost <- POST(authURL, body=authBody, encode='json')
```
```{r}
library(rjson)
authJSON <- fromJSON(rawToChar(authPost$content))
if(isTRUE(authJSON$ok)) {
authHeader <- paste0('Bearer ', authJSON$token)
} else{
warning('Authentication failed')
authHeader <- FALSE
}
```
Get Incremental Messages for All Buoys Assigned to User
GET https://blueapi.boggroup.net/api/v2/updates?since=<since_cursor>
```{r}
allMsgURL <- 'https://blueapi.boggroup.net/api/v2/updates'
sinceCursor <- -1
if(sinceCursor > 0) {
since <- paste0('?since=', sinceCursor)
} else {
since <- ''
}
allMsg <- GET(paste0(allMsgURL, since), add_headers(Authorization=authHeader))
msgJSON <- fromJSON(rawToChar(allMsg$content))
sinceCursor <- msgJSON$since_cursor
boJSONtoDf <- function(x) {
dplyr::bind_rows(lapply(x$messages, function(m) {
if(!('position_latitude' %in% names(m))) {
return(NULL)
}
m$time <- as.POSIXct(m$time, format='%Y-%m-%dT%H:%M:%S', tz='UTC')
m
}))
}
boDf <- boJSONtoDf(msgJSON)
```