-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
121 lines (87 loc) · 3.37 KB
/
README.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
109
110
111
112
113
114
115
116
117
118
119
120
121
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
```{r echo=FALSE, results="hide", message=FALSE}
library("badger")
```
# Rthingsboard
<!-- badges: start -->
`r badge_license(color = "orange")`
`r badge_lifecycle("maturing", color = "blue")`
`r badge_devel(color = "blue")`
[![R build status](https://github.com/DDorch/Rthingsboard/workflows/R-CMD-check/badge.svg)](https://github.com/DDorch/Rthingsboard/actions)
`r badge_code_size("DDorch/Rthingsboard")`
<!-- badges: end -->
The goal of 'Rthingsboard' is to provide interaction with the API of 'ThingsBoard' (https://thingsboard.io/), an open-source IoT platform for device management, data collection, processing and visualization.
## Installation
You can install the released version of 'Rthingsboard' from [CRAN](https://CRAN.R-project.org/package=Rthingsboard) with:
``` r
install.packages("Rthingsboard")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("DDorch/Rthingsboard")
```
## Example
This is a basic example which shows you how to extract data from the following public dashboard : http://scada.g-eau.fr/dashboard/4db16100-f3e9-11e8-9dbf-cbc1e37c11e3?publicId=299cedc0-f3e9-11e8-9dbf-cbc1e37c11e3
### Load library
```{r setup}
library(Rthingsboard)
```
### Define the configuration parameters
```{r parameters}
# Identifier of SupAgro Halle hydraulique SCADA
url = "http://scada.g-eau.fr"
publicId = "299cedc0-f3e9-11e8-9dbf-cbc1e37c11e3"
entityId = "18d56d50-f3e9-11e8-9dbf-cbc1e37c11e3"
startDate = as.POSIXct("2020-11-19 15:00:00", tz = "Europe/Paris")
endDate = as.POSIXct("2020-11-19 18:00:00", tz = "Europe/Paris")
# Set logger threshold to DEBUG to see extra messages for debug purpose
logger::log_threshold(logger::DEBUG)
```
### Connexion to the 'ThingsBoard' server
First, you need to create an object of class `ThingsboardApi` as follow:
``` {r connection}
# Connection to the API
tb_api = ThingsboardApi(url = url, publicId = publicId)
```
### Retrieve data from the 'ThingsBoard' server
You can get the available keys on the specified device defined by its `entityId`:
``` {r getKeys}
# Get list of keys
keys = tb_api$getKeys(entityId = entityId)
```
Knowing the name of the available keys, you can get the telemetry of this device for a given period defined by `startTS` and `endTS`.
Here below, we download the telemetry for all keys beginning by "Y":
```{r getTelemetry}
df <- tb_api$getTelemetry(entityId,
keys = keys[grep("^Y", keys)],
startTs = startDate,
endTs = endDate)
```
Here below the first records of the extracted telemetry:
```{r time zone}
knitr::kable(head(df))
```
You can then record this table into a file in the current directory:
```{r write_csv, eval=FALSE}
# getwd() # to get the path of the current directory
write.csv2(df, "myData.csv")
```
And also plot some time series:
```{r plot_telemetry}
library(ggplot2)
ggplot(df, aes(x = ts, y = value)) +
geom_line(aes(color = key), size = 1) +
scale_color_brewer(palette = "Set1")
```