-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinflux.r
More file actions
47 lines (35 loc) · 1.12 KB
/
Copy pathinflux.r
File metadata and controls
47 lines (35 loc) · 1.12 KB
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
library(httr)
influx.read <- function(query, user, password){
# Purpose: Query data from the bee-observer sensor data base
#
# Parameters:
# query: A query string. Refer to: https://docs.influxdata.com/influxdb/v1.7/query_language/data_exploration/
# examples:
# "select * from sensors where time >= now() -1h"
# "select * from sensors where \"key\" = 'Q05rcH1lquY8YrYN' and time >= now() -1h"
# user: the user of the influx db
# password: influx db password
#
# Returns:
# the data as data frame
# Get raw data
result <- GET(
"http://134.102.219.159:8086/query?db=bee_data",
query=list(
q= query
),
authenticate(user, password),
verbose()
)
# parse raw data
content <- content(result, as="parsed")
# extract values
content.list <- content$results[[1]]$series[[1]]$values
# extract header
content.header <- content$results[[1]]$series[[1]]$columns
# convert to data frame
df <- do.call(rbind, content.list)
df <- as.data.frame(df)
names(df) <- unlist(content.header)
return(df)
}