knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
library("badger")
r badge_license(color = "orange")
r badge_lifecycle("maturing", color = "blue")
r badge_devel(color = "blue")
r badge_code_size("DDorch/Rthingsboard")
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.
You can install the released version of 'Rthingsboard' from CRAN with:
install.packages("Rthingsboard")
And the development version from GitHub with:
# install.packages("devtools") devtools::install_github("DDorch/Rthingsboard")
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
library(Rthingsboard)
# 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)
First, you need to create an object of class ThingsboardApi
as follow:
``` {r connection}
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":
df <- tb_api$getTelemetry(entityId, keys = keys[grep("^Y", keys)], startTs = startDate, endTs = endDate)
Here below the first records of the extracted telemetry:
knitr::kable(head(df))
You can then record this table into a file in the current directory:
# getwd() # to get the path of the current directory write.csv2(df, "myData.csv")
And also plot some time series:
library(ggplot2) ggplot(df, aes(x = ts, y = value)) + geom_line(aes(color = key), size = 1) + scale_color_brewer(palette = "Set1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.